bstinson / rpms / mozjs60

Forked from rpms/mozjs60 5 years ago
Clone

Blame SOURCES/Save-x28-before-clobbering-it-in-the-regex-compiler.patch

e43f4b
# HG changeset patch
e43f4b
# User Lars T Hansen <lhansen@mozilla.com>
e43f4b
# Date 1521449886 -3600
e43f4b
# Node ID 903a79a1efff18fc7cc50db09a3fe5d768adc9a8
e43f4b
# Parent  4d2955a9ca7e30ca4c3af9c214ccc77fb2fe7fb8
e43f4b
Bug 1445907 - Save x28 before clobbering it in the regex compiler. r=sstangl
e43f4b
e43f4b
Origin: upstream
e43f4b
Applied-upstream: 61, commit: https://hg.mozilla.org/mozilla-central/rev/903a79a1efff
e43f4b
---
e43f4b
diff --git a/js/src/irregexp/NativeRegExpMacroAssembler.cpp b/js/src/irregexp/NativeRegExpMacroAssembler.cpp
e43f4b
--- a/js/src/irregexp/NativeRegExpMacroAssembler.cpp
e43f4b
+++ b/js/src/irregexp/NativeRegExpMacroAssembler.cpp
e43f4b
@@ -118,17 +118,25 @@ NativeRegExpMacroAssembler::GenerateCode
e43f4b
e43f4b
     Label return_temp0;
e43f4b
e43f4b
     // Finalize code - write the entry point code now we know how many
e43f4b
     // registers we need.
e43f4b
     masm.bind(&entry_label_);
e43f4b
e43f4b
 #ifdef JS_CODEGEN_ARM64
e43f4b
-    // ARM64 communicates stack address via sp, but uses a pseudo-sp for addressing.
e43f4b
+    // ARM64 communicates stack address via SP, but uses a pseudo-sp (PSP) for
e43f4b
+    // addressing.  The register we use for PSP may however also be used by
e43f4b
+    // calling code, and it is nonvolatile, so save it.  Do this as a special
e43f4b
+    // case first because the generic save/restore code needs the PSP to be
e43f4b
+    // initialized already.
e43f4b
+    MOZ_ASSERT(PseudoStackPointer64.Is(masm.GetStackPointer64()));
e43f4b
+    masm.Str(PseudoStackPointer64, vixl::MemOperand(sp, -16, vixl::PreIndex));
e43f4b
+
e43f4b
+    // Initialize the PSP from the SP.
e43f4b
     masm.initStackPtr();
e43f4b
 #endif
e43f4b
e43f4b
     // Push non-volatile registers which might be modified by jitcode.
e43f4b
     size_t pushedNonVolatileRegisters = 0;
e43f4b
     for (GeneralRegisterForwardIterator iter(savedNonVolatileRegisters); iter.more(); ++iter) {
e43f4b
         masm.Push(*iter);
e43f4b
         pushedNonVolatileRegisters++;
e43f4b
@@ -416,17 +424,32 @@ NativeRegExpMacroAssembler::GenerateCode
e43f4b
     masm.pop(temp0);
e43f4b
     masm.movePtr(temp0, StackPointer);
e43f4b
 #endif
e43f4b
e43f4b
     // Restore non-volatile registers which were saved on entry.
e43f4b
     for (GeneralRegisterBackwardIterator iter(savedNonVolatileRegisters); iter.more(); ++iter)
e43f4b
         masm.Pop(*iter);
e43f4b
e43f4b
+#ifdef JS_CODEGEN_ARM64
e43f4b
+    // Now restore the value that was in the PSP register on entry, and return.
e43f4b
+
e43f4b
+    // Obtain the correct SP from the PSP.
e43f4b
+    masm.Mov(sp, PseudoStackPointer64);
e43f4b
+
e43f4b
+    // Restore the saved value of the PSP register, this value is whatever the
e43f4b
+    // caller had saved in it, not any actual SP value, and it must not be
e43f4b
+    // overwritten subsequently.
e43f4b
+    masm.Ldr(PseudoStackPointer64, vixl::MemOperand(sp, 16, vixl::PostIndex));
e43f4b
+
e43f4b
+    // Perform a plain Ret(), as abiret() will move SP <- PSP and that is wrong.
e43f4b
+    masm.Ret(vixl::lr);
e43f4b
+#else
e43f4b
     masm.abiret();
e43f4b
+#endif
e43f4b
e43f4b
     // Backtrack code (branch target for conditional backtracks).
e43f4b
     if (backtrack_label_.used()) {
e43f4b
         masm.bind(&backtrack_label_);
e43f4b
         Backtrack();
e43f4b
     }
e43f4b
e43f4b
     // Backtrack stack overflow code.
e43f4b
diff --git a/js/src/jit-test/tests/regexp/bug1445907.js b/js/src/jit-test/tests/regexp/bug1445907.js
e43f4b
new file mode 100644
e43f4b
--- /dev/null
e43f4b
+++ b/js/src/jit-test/tests/regexp/bug1445907.js
e43f4b
@@ -0,0 +1,15 @@
e43f4b
+// On ARM64, we failed to save x28 properly when generating code for the regexp
e43f4b
+// matcher.
e43f4b
+//
e43f4b
+// There's wasm and Debugger code here because the combination forces the use of
e43f4b
+// x28 and exposes the bug when running on the simulator.
e43f4b
+
e43f4b
+if (!wasmIsSupported())
e43f4b
+    quit();
e43f4b
+
e43f4b
+var g = newGlobal('');
e43f4b
+var dbg = new Debugger(g);
e43f4b
+g.eval(`var m = new WebAssembly.Instance(new WebAssembly.Module(wasmTextToBinary('(module (func (export "test")))')))`);
e43f4b
+var re = /./;
e43f4b
+dbg.onEnterFrame = function(frame) { re.exec("x") };
e43f4b
+result = g.eval("m.exports.test()");
e43f4b
e43f4b
--
e43f4b
2.21.0
e43f4b