summaryrefslogtreecommitdiff
path: root/mail/thunderbird/files/patch-bug1445907
blob: 924ac0aa7cd7ef0d6d194d476a0ae690e7b690f6 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
commit 0c6dd4a750db
Author: Lars T Hansen <lhansen@mozilla.com>
Date:   Mon Mar 19 09:58:06 2018 +0100

    Bug 1445907 - Save x28 before clobbering it in the regex compiler. r=sstangl
---
 js/src/irregexp/NativeRegExpMacroAssembler.cpp | 25 ++++++++++++++++++++++++-
 js/src/jit-test/tests/regexp/bug1445907.js     | 15 +++++++++++++++
 2 files changed, 39 insertions(+), 1 deletion(-)

diff --git js/src/irregexp/NativeRegExpMacroAssembler.cpp js/src/irregexp/NativeRegExpMacroAssembler.cpp
index 28a4c35e75bfe..c08b005cf856b 100644
--- js/src/irregexp/NativeRegExpMacroAssembler.cpp
+++ js/src/irregexp/NativeRegExpMacroAssembler.cpp
@@ -123,7 +123,15 @@ NativeRegExpMacroAssembler::GenerateCode(JSContext* cx, bool match_only)
     masm.bind(&entry_label_);
 
 #ifdef JS_CODEGEN_ARM64
-    // ARM64 communicates stack address via sp, but uses a pseudo-sp for addressing.
+    // ARM64 communicates stack address via SP, but uses a pseudo-sp (PSP) for
+    // 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();
 #endif
 
@@ -421,7 +429,22 @@ NativeRegExpMacroAssembler::GenerateCode(JSContext* cx, bool match_only)
     for (GeneralRegisterBackwardIterator iter(savedNonVolatileRegisters); iter.more(); ++iter)
         masm.Pop(*iter);
 
+#ifdef JS_CODEGEN_ARM64
+    // Now restore the value that was in the PSP register on entry, and return.
+
+    // Obtain the correct SP from the PSP.
+    masm.Mov(sp, PseudoStackPointer64);
+
+    // Restore the saved value of the PSP register, this value is whatever the
+    // caller had saved in it, not any actual SP value, and it must not be
+    // overwritten subsequently.
+    masm.Ldr(PseudoStackPointer64, vixl::MemOperand(sp, 16, vixl::PostIndex));
+
+    // Perform a plain Ret(), as abiret() will move SP <- PSP and that is wrong.
+    masm.Ret(vixl::lr);
+#else
     masm.abiret();
+#endif
 
     // Backtrack code (branch target for conditional backtracks).
     if (backtrack_label_.used()) {
diff --git js/src/jit-test/tests/regexp/bug1445907.js js/src/jit-test/tests/regexp/bug1445907.js
new file mode 100644
index 0000000000000..75b23753eaf93
--- /dev/null
+++ js/src/jit-test/tests/regexp/bug1445907.js
@@ -0,0 +1,15 @@
+// On ARM64, we failed to save x28 properly when generating code for the regexp
+// matcher.
+//
+// There's wasm and Debugger code here because the combination forces the use of
+// x28 and exposes the bug when running on the simulator.
+
+if (!wasmIsSupported())
+    quit();
+
+var g = newGlobal('');
+var dbg = new Debugger(g);
+g.eval(`var m = new WebAssembly.Instance(new WebAssembly.Module(wasmTextToBinary('(module (func (export "test")))')))`);
+var re = /./;
+dbg.onEnterFrame = function(frame) { re.exec("x") };
+result = g.eval("m.exports.test()");