tor-browser

The Tor Browser
git clone https://git.dasho.dev/tor-browser.git
Log | Files | Refs | README | LICENSE

Assembler-shared.cpp (3058B)


      1 /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*-
      2 * vim: set ts=8 sts=2 et sw=2 tw=80:
      3 * This Source Code Form is subject to the terms of the Mozilla Public
      4 * License, v. 2.0. If a copy of the MPL was not distributed with this
      5 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
      6 
      7 #include "jit/shared/Assembler-shared.h"
      8 
      9 #include "jit/JitSpewer.h"
     10 #include "vm/NativeObject.h"
     11 #include "wasm/WasmFrame.h"
     12 #include "wasm/WasmMemory.h"
     13 
     14 namespace js {
     15 
     16 namespace wasm {
     17 
     18 #ifdef DEBUG
     19 void MemoryAccessDesc::assertOffsetInGuardPages() const {
     20  MOZ_ASSERT(offset_ < (uint64_t)GetMaxOffsetGuardLimit(
     21                           hugeMemory_, wasm::PageSize::Standard));
     22 }
     23 #endif
     24 
     25 }  // namespace wasm
     26 
     27 namespace jit {
     28 
     29 void BaseObjectElementIndex::staticAssertions() {
     30  NativeObject::elementsSizeMustNotOverflow();
     31 }
     32 
     33 void BaseObjectSlotIndex::staticAssertions() {
     34  NativeObject::slotsSizeMustNotOverflow();
     35 }
     36 
     37 AssemblerShared::~AssemblerShared() {
     38 #ifdef DEBUG
     39  while (hasCreator()) {
     40    popCreator();
     41  }
     42 #endif
     43 }
     44 
     45 #ifdef DEBUG
     46 void AssemblerShared::pushCreator(const char* who) {
     47  (void)creators_.append(who);
     48  JitSpewStart(JitSpew_Codegen, "# BEGIN creators: ");
     49  bool first = true;
     50  for (const char* str : creators_) {
     51    JitSpewCont(JitSpew_Codegen, "%s%s", first ? "" : "/", str);
     52    first = false;
     53  }
     54  JitSpewCont(JitSpew_Codegen, "\n");
     55 }
     56 
     57 void AssemblerShared::popCreator() {
     58  JitSpewStart(JitSpew_Codegen, "# END   creators: ");
     59  bool first = true;
     60  for (const char* str : creators_) {
     61    JitSpewCont(JitSpew_Codegen, "%s%s", first ? "" : "/", str);
     62    first = false;
     63  }
     64  JitSpewCont(JitSpew_Codegen, "\n");
     65  if (creators_.empty()) {
     66    JitSpew(JitSpew_Codegen, " ");
     67  }
     68  MOZ_ASSERT(!creators_.empty());
     69  creators_.popBack();
     70 }
     71 
     72 bool AssemblerShared::hasCreator() const {
     73  // If you get failures of assertions of the form `MOZ_ASSERT(hasCreator())`,
     74  // what this means is that a `MacroAssembler` (or, really, anything that
     75  // inherits from `js::jit::AssemblerShared`) has emitted code or data from a
     76  // place, in the SM C++ hierarchy, that is not nested within an
     77  // `AutoCreatedBy` RAII scope.  Consequently the emitted instructions/data
     78  // won't have any owner that is identifiable in the `IONFLAGS=codegen`
     79  // output.
     80  //
     81  // Fixing this is easy: work back up the crash stack and decide on a place
     82  // to put an `AutoCreatedBy` call.  A bit of grepping for `AutoCreatedBy`
     83  // should make it obvious what to do.  If in doubt, add `AutoCreatedBy`
     84  // calls liberally; "extra" ones are harmless.
     85  return !creators_.empty();
     86 }
     87 #endif
     88 
     89 static uint32_t ABIArgGeneratorStartOffset(ABIKind kind) {
     90  switch (kind) {
     91    case ABIKind::System:
     92      return 0;
     93    case ABIKind::Wasm:
     94      return wasm::FrameWithInstances::sizeOfInstanceFields();
     95    default:
     96      MOZ_CRASH("Invalid ABI kind");
     97  }
     98 }
     99 
    100 ABIArgGeneratorShared::ABIArgGeneratorShared(ABIKind kind)
    101    : kind_(kind), stackOffset_(ABIArgGeneratorStartOffset(kind)) {}
    102 
    103 }  // namespace jit
    104 
    105 }  // namespace js