Bug 1366322 - Baldr: remove dependency of TlsData on specific JSContext (r=bbouvier)

MozReview-Commit-ID: 2Z77q3YJsyO
This commit is contained in:
Luke Wagner 2017-05-24 10:24:17 -05:00
parent 00312ec84c
commit d94140b08e
13 changed files with 47 additions and 46 deletions

View File

@ -9571,12 +9571,8 @@ CodeGenerator::generateWasm(wasm::SigIdDesc sigId, wasm::BytecodeOffset trapOffs
// functions with small framePushed). Perform overflow-checking after
// pushing framePushed to catch cases with really large frames.
Label onOverflow;
if (!omitOverRecursedCheck()) {
masm.branchPtr(Assembler::AboveOrEqual,
Address(WasmTlsReg, offsetof(wasm::TlsData, stackLimit)),
masm.getStackPointer(),
&onOverflow);
}
if (!omitOverRecursedCheck())
masm.wasmEmitStackCheck(masm.getStackPointer(), ABINonArgReg0, &onOverflow);
if (!generateBody())
return false;

View File

@ -3090,6 +3090,17 @@ MacroAssembler::wasmAssertNonExitInvariants(Register activation)
#endif
}
void
MacroAssembler::wasmEmitStackCheck(Register sp, Register scratch, Label* onOverflow)
{
loadPtr(Address(WasmTlsReg, offsetof(wasm::TlsData, addressOfContext)), scratch);
loadPtr(Address(scratch, 0), scratch);
branchPtr(Assembler::AboveOrEqual,
Address(scratch, offsetof(JSContext, jitStackLimitNoInterrupt)),
sp,
onOverflow);
}
//}}} check_macroassembler_style
void

View File

@ -1479,6 +1479,9 @@ class MacroAssembler : public MacroAssemblerSpecific
// Assert invariants that should be true within any non-exit-stub wasm code.
void wasmAssertNonExitInvariants(Register activation);
// Perform a stack-overflow test, branching to the given Label on overflow.
void wasmEmitStackCheck(Register sp, Register scratch, Label* onOverflow);
public:
// ========================================================================
// Clamping functions.

View File

@ -8057,7 +8057,8 @@ DebuggerFrame::setOnStepHandler(JSContext* cx, HandleDebuggerFrame frame, OnStep
return false;
} else if (!handler && prior) {
// Single stepping toggled on->off.
if (!instance->debug().decrementStepModeCount(cx, wasmFrame->funcIndex()))
FreeOp* fop = cx->runtime()->defaultFreeOp();
if (!instance->debug().decrementStepModeCount(fop, wasmFrame->funcIndex()))
return false;
}
} else {
@ -8391,8 +8392,7 @@ DebuggerFrame_maybeDecrementFrameScriptStepModeCount(FreeOp* fop, AbstractFrameP
return;
if (frame.isWasmDebugFrame()) {
wasm::Instance* instance = frame.wasmInstance();
instance->debug().decrementStepModeCount(instance->cx(),
frame.asWasmDebugFrame()->funcIndex());
instance->debug().decrementStepModeCount(fop, frame.asWasmDebugFrame()->funcIndex());
} else {
frame.script()->decrementStepModeCount(fop);
}

View File

@ -1684,9 +1684,7 @@ WasmActivation::startInterrupt(void* pc, uint8_t* fp)
cx_->runtime()->setWasmResumePC(pc);
exitFP_ = reinterpret_cast<wasm::Frame*>(fp);
MOZ_ASSERT(cx() == exitFP_->tls->cx);
MOZ_ASSERT(compartment() == exitFP_->tls->instance->compartment());
MOZ_ASSERT(interrupted());
}

View File

@ -2225,14 +2225,11 @@ class BaseCompiler
// be (we may need arbitrary spill slots and outgoing param slots) so
// emit a patchable add that is patched in endFunction().
//
// ScratchReg may be used by branchPtr(), so use ABINonArgReg0 for the
// effective address.
// ScratchReg may be used by branchPtr(), so use ABINonArgReg0/1 for
// temporaries.
stackAddOffset_ = masm.add32ToPtrWithPatch(StackPointer, ABINonArgReg0);
masm.branchPtr(Assembler::AboveOrEqual,
Address(WasmTlsReg, offsetof(TlsData, stackLimit)),
ABINonArgReg0,
&stackOverflowLabel_);
masm.wasmEmitStackCheck(ABINonArgReg0, ABINonArgReg1, &stackOverflowLabel_);
// Copy arguments from registers to stack.

View File

@ -345,7 +345,7 @@ DebugState::incrementStepModeCount(JSContext* cx, uint32_t funcIndex)
}
bool
DebugState::decrementStepModeCount(JSContext* cx, uint32_t funcIndex)
DebugState::decrementStepModeCount(FreeOp* fop, uint32_t funcIndex)
{
MOZ_ASSERT(debugEnabled());
const CodeRange& codeRange = codeRanges(Tier::Debug)[debugFuncToCodeRangeIndex(funcIndex)];
@ -359,7 +359,7 @@ DebugState::decrementStepModeCount(JSContext* cx, uint32_t funcIndex)
stepModeCounters_.remove(p);
AutoWritableJitCode awjc(cx->runtime(), code_->segment(Tier::Debug).base() + codeRange.begin(),
AutoWritableJitCode awjc(fop->runtime(), code_->segment(Tier::Debug).base() + codeRange.begin(),
codeRange.end() - codeRange.begin());
AutoFlushICache afc("Code::decrementStepModeCount");

View File

@ -137,7 +137,7 @@ class DebugState
bool stepModeEnabled(uint32_t funcIndex) const;
bool incrementStepModeCount(JSContext* cx, uint32_t funcIndex);
bool decrementStepModeCount(JSContext* cx, uint32_t funcIndex);
bool decrementStepModeCount(FreeOp* fop, uint32_t funcIndex);
// Stack inspection helpers.

View File

@ -309,7 +309,8 @@ LoadActivation(MacroAssembler& masm, Register dest)
{
// WasmCall pushes a WasmActivation and an inactive JitActivation. The
// JitActivation only becomes active when calling into JS from wasm.
masm.loadPtr(Address(WasmTlsReg, offsetof(wasm::TlsData, cx)), dest);
masm.loadPtr(Address(WasmTlsReg, offsetof(wasm::TlsData, addressOfContext)), dest);
masm.loadPtr(Address(dest, 0), dest);
masm.loadPtr(Address(dest, JSContext::offsetOfActivation()), dest);
masm.loadPtr(Address(dest, Activation::offsetOfPrev()), dest);
}

View File

@ -256,7 +256,7 @@ Instance::callImport(JSContext* cx, uint32_t funcImportIndex, unsigned argc, con
/* static */ int32_t
Instance::callImport_void(Instance* instance, int32_t funcImportIndex, int32_t argc, uint64_t* argv)
{
JSContext* cx = instance->cx();
JSContext* cx = TlsContext.get();
RootedValue rval(cx);
return instance->callImport(cx, funcImportIndex, argc, argv, &rval);
}
@ -264,7 +264,7 @@ Instance::callImport_void(Instance* instance, int32_t funcImportIndex, int32_t a
/* static */ int32_t
Instance::callImport_i32(Instance* instance, int32_t funcImportIndex, int32_t argc, uint64_t* argv)
{
JSContext* cx = instance->cx();
JSContext* cx = TlsContext.get();
RootedValue rval(cx);
if (!instance->callImport(cx, funcImportIndex, argc, argv, &rval))
return false;
@ -275,7 +275,7 @@ Instance::callImport_i32(Instance* instance, int32_t funcImportIndex, int32_t ar
/* static */ int32_t
Instance::callImport_i64(Instance* instance, int32_t funcImportIndex, int32_t argc, uint64_t* argv)
{
JSContext* cx = instance->cx();
JSContext* cx = TlsContext.get();
RootedValue rval(cx);
if (!instance->callImport(cx, funcImportIndex, argc, argv, &rval))
return false;
@ -286,7 +286,7 @@ Instance::callImport_i64(Instance* instance, int32_t funcImportIndex, int32_t ar
/* static */ int32_t
Instance::callImport_f64(Instance* instance, int32_t funcImportIndex, int32_t argc, uint64_t* argv)
{
JSContext* cx = instance->cx();
JSContext* cx = TlsContext.get();
RootedValue rval(cx);
if (!instance->callImport(cx, funcImportIndex, argc, argv, &rval))
return false;
@ -299,7 +299,7 @@ Instance::growMemory_i32(Instance* instance, uint32_t delta)
{
MOZ_ASSERT(!instance->isAsmJS());
JSContext* cx = instance->cx();
JSContext* cx = TlsContext.get();
RootedWasmMemoryObject memory(cx, instance->memory_);
uint32_t ret = WasmMemoryObject::grow(memory, delta, cx);
@ -343,14 +343,13 @@ Instance::Instance(JSContext* cx,
#endif
MOZ_ASSERT(tables_.length() == metadata().tables.length());
tlsData()->cx = cx;
tlsData()->instance = this;
tlsData()->globalData = globals_->globalData();
tlsData()->memoryBase = memory ? memory->buffer().dataPointerEither().unwrap() : nullptr;
#ifndef WASM_HUGE_MEMORY
tlsData()->boundsCheckLimit = memory ? memory->buffer().wasmBoundsCheckLimit() : 0;
#endif
tlsData()->stackLimit = *(void**)cx->stackLimitAddressForJitCode(JS::StackForUntrustedScript);
tlsData()->globalData = globals_->globalData();
tlsData()->instance = this;
tlsData()->addressOfContext = (JSContext**)object->zone()->group()->addressOfOwnerContext();
Tier callerTier = Tier::TBD;
Tier calleeTier = Tier::TBD;

View File

@ -104,7 +104,6 @@ class Instance
bool init(JSContext* cx);
void trace(JSTracer* trc);
JSContext* cx() const { return tlsData()->cx; }
JSCompartment* compartment() const { return compartment_; }
const Code& code() const { return *code_; }
DebugState& debug() { return *debug_; }

View File

@ -736,7 +736,8 @@ wasm::GenerateImportJitExit(MacroAssembler& masm, const FuncImport& fi, Label* t
Register act = WasmIonExitRegE1;
// JitActivation* act = cx->activation();
masm.loadPtr(Address(WasmTlsReg, offsetof(TlsData, cx)), cx);
masm.loadPtr(Address(WasmTlsReg, offsetof(TlsData, addressOfContext)), cx);
masm.loadPtr(Address(cx, 0), cx);
masm.loadPtr(Address(cx, JSContext::offsetOfActivation()), act);
// act.active_ = true;
@ -772,7 +773,8 @@ wasm::GenerateImportJitExit(MacroAssembler& masm, const FuncImport& fi, Label* t
Register tmp = WasmIonExitRegD2;
// JitActivation* act = cx->activation();
masm.loadPtr(Address(WasmTlsReg, offsetof(TlsData, cx)), cx);
masm.loadPtr(Address(WasmTlsReg, offsetof(TlsData, addressOfContext)), cx);
masm.loadPtr(Address(cx, 0), cx);
masm.loadPtr(Address(cx, JSContext::offsetOfActivation()), act);
// cx->jitTop = act->prevJitTop_;

View File

@ -1287,15 +1287,6 @@ struct ExportArg
struct TlsData
{
// Pointer to the JSContext that contains this TLS data.
JSContext* cx;
// Pointer to the Instance that contains this TLS data.
Instance* instance;
// Pointer to the global data for this Instance.
uint8_t* globalData;
// Pointer to the base of the default memory (or null if there is none).
uint8_t* memoryBase;
@ -1304,10 +1295,14 @@ struct TlsData
uint32_t boundsCheckLimit;
#endif
// Stack limit for the current thread. This limit is checked against the
// stack pointer in the prologue of functions that allocate stack space. See
// `CodeGenerator::generateWasm`.
void* stackLimit;
// Pointer to the global data for this Instance.
uint8_t* globalData;
// Pointer to the Instance that contains this TLS data.
Instance* instance;
// Shortcut to instance->zone->group->addressOfOwnerContext
JSContext** addressOfContext;
// The globalArea must be the last field. Globals for the module start here
// and are inline in this structure. 16-byte alignment is required for SIMD