tor-browser

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

SharedICHelpers-x86.h (2327B)


      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 #ifndef jit_x86_SharedICHelpers_x86_h
      8 #define jit_x86_SharedICHelpers_x86_h
      9 
     10 #include "jit/BaselineIC.h"
     11 #include "jit/JitFrames.h"
     12 #include "jit/MacroAssembler.h"
     13 #include "jit/SharedICRegisters.h"
     14 
     15 namespace js {
     16 namespace jit {
     17 
     18 // Distance from stack top to the top Value inside an IC stub (this is the
     19 // return address).
     20 static const size_t ICStackValueOffset = sizeof(void*);
     21 
     22 inline void EmitRestoreTailCallReg(MacroAssembler& masm) {
     23  masm.Pop(ICTailCallReg);
     24 }
     25 
     26 inline void EmitRepushTailCallReg(MacroAssembler& masm) {
     27  masm.Push(ICTailCallReg);
     28 }
     29 
     30 inline void EmitCallIC(MacroAssembler& masm, CodeOffset* callOffset) {
     31  // The stub pointer must already be in ICStubReg.
     32  // Call the stubcode.
     33  masm.call(Address(ICStubReg, ICStub::offsetOfStubCode()));
     34  *callOffset = CodeOffset(masm.currentOffset());
     35 }
     36 
     37 inline void EmitReturnFromIC(MacroAssembler& masm) { masm.ret(); }
     38 
     39 inline void EmitBaselineLeaveStubFrame(MacroAssembler& masm) {
     40  Address stubAddr(FramePointer, BaselineStubFrameLayout::ICStubOffsetFromFP);
     41  masm.loadPtr(stubAddr, ICStubReg);
     42 
     43  masm.mov(FramePointer, StackPointer);
     44  masm.Pop(FramePointer);
     45 
     46  // The return address is on top of the stack, followed by the frame
     47  // descriptor. Use a pop instruction to overwrite the frame descriptor
     48  // with the return address. Note that pop increments the stack pointer
     49  // before computing the address.
     50  masm.Pop(Operand(StackPointer, 0));
     51 }
     52 
     53 template <typename AddrType>
     54 inline void EmitPreBarrier(MacroAssembler& masm, const AddrType& addr,
     55                           MIRType type) {
     56  masm.guardedCallPreBarrier(addr, type);
     57 }
     58 
     59 inline void EmitStubGuardFailure(MacroAssembler& masm) {
     60  // Load next stub into ICStubReg
     61  masm.loadPtr(Address(ICStubReg, ICCacheIRStub::offsetOfNext()), ICStubReg);
     62 
     63  // Return address is already loaded, just jump to the next stubcode.
     64  masm.jmp(Operand(ICStubReg, ICStub::offsetOfStubCode()));
     65 }
     66 
     67 }  // namespace jit
     68 }  // namespace js
     69 
     70 #endif /* jit_x86_SharedICHelpers_x86_h */