// Generate a stackmap for a function's stack-overflow-at-entry trap, with // the structure: // // <reg dump area> // | ++ <space reserved before trap, if any> // | ++ <space for Frame> // | ++ <inbound arg area> // | | // Lowest Addr Highest Addr // // The caller owns the resulting stackmap. This assumes a grow-down stack. // // For non-debug builds, if the stackmap would contain no pointers, no // stackmap is created, and nullptr is returned. For a debug build, a // stackmap is always created and returned. // // The "space reserved before trap" is the space reserved by // MacroAssembler::wasmReserveStackChecked, in the case where the frame is // "small", as determined by that function. bool wasm::CreateStackMapForFunctionEntryTrap( const wasm::ArgTypeVector& argTypes, const RegisterOffsets& trapExitLayout,
size_t trapExitLayoutWords, size_t nBytesReservedBeforeTrap,
size_t nInboundStackArgBytes, wasm::StackMaps& stackMaps,
wasm::StackMap** result) { // Ensure this is defined on all return paths.
*result = nullptr;
// The size of the wasm::Frame itself. const size_t nFrameBytes = sizeof(wasm::Frame);
// The size of the register dump (trap) area. const size_t trapExitLayoutBytes = trapExitLayoutWords * sizeof(void*);
// The stack map owns any alignment padding for incoming stack args.
MOZ_ASSERT(nInboundStackArgBytes % sizeof(void*) == 0); const size_t nInboundStackArgBytesAligned =
AlignStackArgAreaSize(nInboundStackArgBytes); const size_t numStackArgWords = nInboundStackArgBytesAligned / sizeof(void*);
// This is the total number of bytes covered by the map. const size_t nTotalBytes = trapExitLayoutBytes + nBytesReservedBeforeTrap +
nFrameBytes + nInboundStackArgBytesAligned;
#ifdef JS_JITSPEW void StackMap::show(uint32_t codeOffset) const {
uint32_t nWords = numMappedWords();
uint32_t nTotal = nWords + 64; char* str = (char*)js_malloc(nTotal); if (!str) { return;
}
memset(str, 0, nTotal);
snprintf(str, nTotal, "%u words: LO{ ", nWords);
uint32_t offs = strlen(str); for (uint32_t i = 0; i < nWords; i++) { char c = '.'; switch (get(i)) { case StackMap::Kind::POD: break; case StackMap::Kind::AnyRef:
c = 'R'; break; case StackMap::Kind::StructDataPointer:
c = 'S'; break; case StackMap::Kind::ArrayDataPointer:
c = 'A'; break; case StackMap::Kind::Limit: default:
MOZ_CRASH();
}
MOZ_RELEASE_ASSERT(offs < nTotal);
str[offs++] = c;
}
snprintf(&str[offs], nTotal - offs, " }HI");
MOZ_RELEASE_ASSERT(str[nTotal - 1] == 0);
JitSpew(jit::JitSpew_Codegen, "%06x # <-- @ w::StackMap: %s", codeOffset,
str);
js_free(str);
}
constchar* wasm::NameOfTrap(Trap t) { switch (t) { case Trap::Unreachable: return"Unreachable"; case Trap::IntegerOverflow: return"IntegerOverflow"; case Trap::InvalidConversionToInteger: return"InvalidConversionToInteger"; case Trap::IntegerDivideByZero: return"IntegerDivideByZero"; case Trap::OutOfBounds: return"OutOfBounds"; case Trap::UnalignedAccess: return"UnalignedAccess"; case Trap::IndirectCallToNull: return"IndirectCallToNull"; case Trap::IndirectCallBadSig: return"IndirectCallBadSig"; case Trap::NullPointerDereference: return"NullPointerDereference"; case Trap::BadCast: return"BadCast"; case Trap::StackOverflow: return"StackOverflow"; case Trap::CheckInterrupt: return"CheckInterrupt"; case Trap::ThrowReported: return"ThrowReported"; case Trap::Limit: return"Limit"; default:
MOZ_CRASH();
}
} #endif
// If this doesn't hold, the associated register wasn't saved by // the trap exit stub. Better to crash now than much later, in // some obscure place, and possibly with security consequences.
MOZ_RELEASE_ASSERT(offsetFromTop < trapExitLayoutNumWords);
// offsetFromTop is an offset in words down from the highest // address in the exit stub save area. Switch it around to be an // offset up from the bottom of the (integer register) save area.
size_t offsetFromBottom = trapExitLayoutNumWords - 1 - offsetFromTop;
(*extras)[offsetFromBottom] = true;
}
returntrue;
}
template <class Addr> void wasm::EmitWasmPreBarrierGuard(MacroAssembler& masm, Register instance, Register scratch, Addr addr,
Label* skipBarrier,
MaybeTrapSiteDesc trapSiteDesc) { // If no incremental GC has started, we don't need the barrier.
masm.loadPtr(
Address(instance, Instance::offsetOfAddressOfNeedsMarkingBarrier()),
scratch);
masm.branchTest32(Assembler::Zero, Address(scratch, 0), Imm32(0x1),
skipBarrier);
// If the previous value is not a GC thing, we don't need the barrier.
FaultingCodeOffset fco = masm.loadPtr(addr, scratch);
masm.branchWasmAnyRefIsGCThing(false, scratch, skipBarrier);
// Emit metadata for a potential null access when reading the previous value. if (trapSiteDesc) {
masm.append(wasm::Trap::NullPointerDereference,
TrapMachineInsnForLoadWord(), fco.get(), *trapSiteDesc);
}
}
// Add the offset to the PreBarrierReg, if any. if (valueOffset != 0) {
masm.addPtr(Imm32(valueOffset), valueAddr);
}
#ifdefined(DEBUG) && defined(JS_CODEGEN_ARM64) // The prebarrier assumes that x20 == sp.
Label ok;
masm.Cmp(sp, vixl::Operand(x20));
masm.B(&ok, Assembler::Equal);
masm.breakpoint();
masm.bind(&ok); #endif
// Load and call the pre-write barrier code. It will preserve all volatile // registers.
masm.loadPtr(Address(instance, Instance::offsetOfPreBarrierCode()), scratch);
masm.call(scratch);
// Remove the offset we folded into PreBarrierReg, if any. if (valueOffset != 0) {
masm.subPtr(Imm32(valueOffset), valueAddr);
}
}
// Save the original base so we can restore it later.
masm.movePtr(AsRegister(addr.base), scratch2);
// Compute the final address into PrebarrierReg, as the barrier expects it // there.
masm.computeEffectiveAddress(addr, PreBarrierReg);
#ifdefined(DEBUG) && defined(JS_CODEGEN_ARM64) // The prebarrier assumes that x20 == sp.
Label ok;
masm.Cmp(sp, vixl::Operand(x20));
masm.B(&ok, Assembler::Equal);
masm.breakpoint();
masm.bind(&ok); #endif
// Load and call the pre-write barrier code. It will preserve all volatile // registers.
masm.loadPtr(Address(instance, Instance::offsetOfPreBarrierCode()), scratch1);
masm.call(scratch1);
// Restore the original base
masm.movePtr(scratch2, AsRegister(addr.base));
}
#ifdef ENABLE_WASM_JSPI void wasm::EmitWasmResumeBarrierGuard(MacroAssembler& masm, Register instance, Register scratch, Label* enterBarrier) { // If an incremental GC has started, we need the barrier.
masm.loadPtr(
Address(instance, Instance::offsetOfAddressOfNeedsMarkingBarrier()),
scratch);
masm.branchTest32(Assembler::NonZero, Address(scratch, 0), Imm32(0x1),
enterBarrier);
}
void wasm::EmitWasmResumeBarrier(MacroAssembler& masm, Register instance, Register cont) { // The builtin thunk will assume that instance is in InstanceReg.
MOZ_ASSERT(instance == InstanceReg);
// Reserve stack space for the call. unsigned argDecrement;
{
ABIArgGenerator abi(ABIKind::Wasm);
ABIArg arg;
arg = abi.next(MIRType::Pointer);
argDecrement = StackDecrementForCall(
WasmStackAlignment, sizeof(wasm::Frame) + masm.framePushed(),
abi.stackBytesConsumedSoFar());
}
masm.reserveStack(argDecrement);
masm.assertStackAlignment(WasmStackAlignment);
void wasm::EmitWasmPostBarrierGuard(MacroAssembler& masm, const mozilla::Maybe<Register>& object, Register otherScratch, Register setValue,
Label* skipBarrier) { // If the pointer being stored is to a tenured object, no barrier.
masm.branchWasmAnyRefIsNurseryCell(false, setValue, otherScratch,
skipBarrier);
// If there is a containing object and it is in the nursery, no barrier. if (object) {
masm.branchPtrInNurseryChunk(Assembler::Equal, *object, otherScratch,
skipBarrier);
}
}
# elif defined(JS_CODEGEN_MIPS64) // TODO (bug 1699696): Implement this. As for the platforms above, we need to // enumerate all code sequences that can precede the stackmap location. returntrue; # elif defined(JS_CODEGEN_LOONG64) // TODO(loong64): Implement IsValidStackMapKey. returntrue; # elif defined(JS_CODEGEN_RISCV64) const uint32_t* insn = reinterpret_cast<const uint32_t*>(nextPC); return (((uintptr_t(insn) & 3) == 0) &&
((insn[-1] == 0x00006037 && insn[-2] == 0x00100073) || // break;
((insn[-1] & kBaseOpcodeMask) == JALR) || // jalr
((insn[-1] & kBaseOpcodeMask) == JAL) || // jal
((insn[-2] & kBaseOpcodeMask) == JAL &&
insn[-1] == 0x00000013 /* addi zero, zero, 0 */) || // jal; nop
(insn[-1] == 0x00100073 &&
(insn[-2] & kITypeMask) == RO_CSRRWI))); // wasm trap # else
MOZ_CRASH("IsValidStackMapKey: requires implementation on this platform"); # endif
} #endif
void StackMaps::checkInvariants(const uint8_t* base) const { #ifdef DEBUG // Chech that each entry points from the stackmap structure points // to a plausible instruction. for (auto iter = codeOffsetToStackMap_.iter(); !iter.done(); iter.next()) {
MOZ_ASSERT(IsPlausibleStackMapKey(base + iter.get().key()), "wasm stackmap does not reference a valid insn");
} #endif
}
Messung V0.5 in Prozent
¤ Dauer der Verarbeitung: 0.13 Sekunden
(vorverarbeitet am 2026-09-30)
¤
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.