Skip to content
Permalink
Browse files
[JSC] Set up wasm stack |this| first
https://bugs.webkit.org/show_bug.cgi?id=241907
rdar://problem/94397072

Reviewed by Mark Lam.

We should set up the stack's |thisValue| first.

* Source/JavaScriptCore/wasm/WasmAirIRGenerator.cpp:
(JSC::Wasm::AirIRGenerator::AirIRGenerator):

Canonical link: https://commits.webkit.org/251775@main
git-svn-id: https://svn.webkit.org/repository/webkit/trunk@295770 268f45cc-cd09-0410-ab3c-d52691b4dbfc
  • Loading branch information
Constellation committed Jun 23, 2022
1 parent 5fe6b71 commit e49129f82a16a9b5ef9c951c1743a33057d07d12
Showing 1 changed file with 10 additions and 12 deletions.
@@ -1014,14 +1014,20 @@ AirIRGenerator::AirIRGenerator(const ModuleInformation& info, B3::Procedure& pro
bool needUnderflowCheck = static_cast<unsigned>(checkSize) > Options::reservedZoneSize();
bool needsOverflowCheck = m_makesCalls || wasmFrameSize >= static_cast<int32_t>(minimumParentCheckSize) || needUnderflowCheck;

if ((needsOverflowCheck || m_usesInstanceValue) && Context::useFastTLS())
jit.loadWasmContextInstance(m_prologueWasmContextGPR);

// We need to setup JSWebAssemblyInstance in |this| slot first.
if (m_catchEntrypoints.size()) {
GPRReg scratch = wasmCallingConvention().prologueScratchGPRs[0];
jit.loadPtr(CCallHelpers::Address(m_prologueWasmContextGPR, Instance::offsetOfOwner()), scratch);
jit.store64(scratch, CCallHelpers::Address(GPRInfo::callFrameRegister, CallFrameSlot::thisArgument * sizeof(Register)));
}

// This allows leaf functions to not do stack checks if their frame size is within
// certain limits since their caller would have already done the check.
if (needsOverflowCheck) {
GPRReg scratch = wasmCallingConvention().prologueScratchGPRs[0];

if (Context::useFastTLS())
jit.loadWasmContextInstance(m_prologueWasmContextGPR);

jit.addPtr(CCallHelpers::TrustedImm32(-checkSize), GPRInfo::callFrameRegister, scratch);
MacroAssembler::JumpList overflow;
if (UNLIKELY(needUnderflowCheck))
@@ -1030,16 +1036,8 @@ AirIRGenerator::AirIRGenerator(const ModuleInformation& info, B3::Procedure& pro
jit.addLinkTask([overflow] (LinkBuffer& linkBuffer) {
linkBuffer.link(overflow, CodeLocationLabel<JITThunkPtrTag>(Thunks::singleton().stub(throwStackOverflowFromWasmThunkGenerator).code()));
});
} else if (m_usesInstanceValue && Context::useFastTLS()) {
// No overflow check is needed, but the instance values still needs to be correct.
jit.loadWasmContextInstance(m_prologueWasmContextGPR);
}

if (m_catchEntrypoints.size()) {
GPRReg scratch = wasmCallingConvention().prologueScratchGPRs[0];
jit.loadPtr(CCallHelpers::Address(m_prologueWasmContextGPR, Instance::offsetOfOwner()), scratch);
jit.store64(scratch, CCallHelpers::Address(GPRInfo::callFrameRegister, CallFrameSlot::thisArgument * sizeof(Register)));
}
}
});

0 comments on commit e49129f

Please sign in to comment.