Bug 1522298 - ARM64: Ensure that the emulated stack pointer is restored when returning from WASM. r=bbouvier,sstangl
authorNicolas B. Pierron <nicolas.b.pierron@nbp.name>
Mon, 11 Feb 2019 13:07:15 +0000
changeset 458477 d7989f40291e2d1551e4e86c611e9b5cde008da5
parent 458476 4f629b83e01b336169ae3279b37a06f95a174978
child 458478 100d9de169abb02adbdef29a056ea3ce45a74d95
push id35536
push userbtara@mozilla.com
push dateMon, 11 Feb 2019 21:54:04 +0000
treeherdermozilla-central@6d8e6f960446 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersbbouvier, sstangl
bugs1522298
milestone67.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1522298 - ARM64: Ensure that the emulated stack pointer is restored when returning from WASM. r=bbouvier,sstangl Differential Revision: https://phabricator.services.mozilla.com/D19185
js/src/irregexp/NativeRegExpMacroAssembler.cpp
js/src/jit/arm64/MacroAssembler-arm64.h
js/src/jit/arm64/Trampoline-arm64.cpp
js/src/vm/UnboxedObject.cpp
js/src/wasm/WasmStubs.cpp
--- a/js/src/irregexp/NativeRegExpMacroAssembler.cpp
+++ b/js/src/irregexp/NativeRegExpMacroAssembler.cpp
@@ -127,17 +127,17 @@ NativeRegExpMacroAssembler::GenerateCode
     // addressing.  The register we use for PSP may however also be used by
     // calling code, and it is nonvolatile, so save it.  Do this as a special
     // case first because the generic save/restore code needs the PSP to be
     // initialized already.
     MOZ_ASSERT(PseudoStackPointer64.Is(masm.GetStackPointer64()));
     masm.Str(PseudoStackPointer64, vixl::MemOperand(sp, -16, vixl::PreIndex));
 
     // Initialize the PSP from the SP.
-    masm.initStackPtr();
+    masm.initPseudoStackPtr();
 #endif
 
     // Push non-volatile registers which might be modified by jitcode.
     size_t pushedNonVolatileRegisters = 0;
     for (GeneralRegisterForwardIterator iter(savedNonVolatileRegisters); iter.more(); ++iter) {
         masm.Push(*iter);
         pushedNonVolatileRegisters++;
     }
--- a/js/src/jit/arm64/MacroAssembler-arm64.h
+++ b/js/src/jit/arm64/MacroAssembler-arm64.h
@@ -251,17 +251,17 @@ class MacroAssemblerCompat : public vixl
   }
 
   // Update sp with the value of the current active stack pointer, if necessary.
   void syncStackPtr() {
     if (!GetStackPointer64().Is(vixl::sp)) {
       Mov(vixl::sp, GetStackPointer64());
     }
   }
-  void initStackPtr() {
+  void initPseudoStackPtr() {
     if (!GetStackPointer64().Is(vixl::sp)) {
       Mov(GetStackPointer64(), vixl::sp);
     }
   }
   void storeValue(ValueOperand val, const Address& dest) {
     storePtr(val.valueReg(), dest);
   }
 
--- a/js/src/jit/arm64/Trampoline-arm64.cpp
+++ b/js/src/jit/arm64/Trampoline-arm64.cpp
@@ -644,19 +644,17 @@ bool JitRuntime::generateVMWrapper(JSCon
   masm.callWithABI(f.wrapped, MoveOp::GENERAL,
                    CheckUnsafeCallWithABI::DontCheckHasExitFrame);
 
   if (!generateTLExitVM(masm, f)) {
     return false;
   }
 
   // SP is used to transfer stack across call boundaries.
-  if (!masm.GetStackPointer64().Is(vixl::sp)) {
-    masm.Mov(masm.GetStackPointer64(), vixl::sp);
-  }
+  masm.initPseudoStackPtr();
 
   // Test for failure.
   switch (f.failType()) {
     case Type_Object:
       masm.branchTestPtr(Assembler::Zero, r0, r0, masm.failureLabel());
       break;
     case Type_Bool:
       masm.branchIfFalseBool(r0, masm.failureLabel());
--- a/js/src/vm/UnboxedObject.cpp
+++ b/js/src/vm/UnboxedObject.cpp
@@ -105,17 +105,17 @@ static const uintptr_t CLEAR_CONSTRUCTOR
   // addressing.  The register we use for PSP may however also be used by
   // calling code, and it is nonvolatile, so save it.  Do this as a special
   // case first because the generic save/restore code needs the PSP to be
   // initialized already.
   MOZ_ASSERT(PseudoStackPointer64.Is(masm.GetStackPointer64()));
   masm.Str(PseudoStackPointer64, vixl::MemOperand(sp, -16, vixl::PreIndex));
 
   // Initialize the PSP from the SP.
-  masm.initStackPtr();
+  masm.initPseudoStackPtr();
 #endif
 
   MOZ_ASSERT(propertiesReg.volatile_());
   MOZ_ASSERT(newKindReg.volatile_());
 
   AllocatableGeneralRegisterSet regs(GeneralRegisterSet::All());
   regs.take(propertiesReg);
   regs.take(newKindReg);
--- a/js/src/wasm/WasmStubs.cpp
+++ b/js/src/wasm/WasmStubs.cpp
@@ -1094,16 +1094,22 @@ void wasm::GenerateDirectCallFromJit(Mac
   const MetadataTier& metadata = codeTier.metadata();
   const CodeRange& codeRange = metadata.codeRange(fe);
   void* callee = codeTier.segment().base() + codeRange.funcNormalEntry();
 
   masm.assertStackAlignment(WasmStackAlignment);
   masm.callJit(ImmPtr(callee));
   masm.assertStackAlignment(WasmStackAlignment);
 
+#ifdef JS_CODEGEN_ARM64
+  // WASM does not use the emulated stack pointer, so reinitialize it as it
+  // might be clobbered either by WASM or by any C++ calls within.
+  masm.initPseudoStackPtr();
+#endif
+
   masm.branchPtr(Assembler::Equal, FramePointer, Imm32(wasm::FailFP),
                  masm.exceptionLabel());
 
   // Store the return value in the appropriate place.
   GenPrintf(DebugChannel::Function, masm, "wasm-function[%d]; returns ", fe.funcIndex());
   switch (fe.funcType().ret().code()) {
     case wasm::ExprType::Void:
       masm.moveValue(UndefinedValue(), JSReturnOperand);