bstinson / rpms / mozjs60

Forked from rpms/mozjs60 5 years ago
Clone

Blame SOURCES/Save-and-restore-non-volatile-x28-on-ARM64-for-generated-unboxed-object-constructor.patch

e43f4b
# HG changeset patch
e43f4b
# User Lars T Hansen <lhansen@mozilla.com>
e43f4b
# Date 1519822672 -3600
e43f4b
# Node ID 800abe66894d6b07b24bccecbf6a65e2261076f6
e43f4b
# Parent  223c97459e96183eb616aed39147207bdb953ba8
e43f4b
Bug 1375074 - Save and restore non-volatile x28 on ARM64 for generated unboxed object constructor.  r=sstangl
e43f4b
e43f4b
Origin: upstream
e43f4b
Applied-upstream: 61, commit: https://hg.mozilla.org/mozilla-central/rev/800abe66894d
e43f4b
---
e43f4b
 js/src/vm/UnboxedObject.cpp | 30 ++++++++++++++++++++++++++----
e43f4b
 1 file changed, 26 insertions(+), 4 deletions(-)
e43f4b
e43f4b
diff --git a/js/src/vm/UnboxedObject.cpp b/js/src/vm/UnboxedObject.cpp
e43f4b
index 35ca20d7405f..1c20a1093d13 100644
e43f4b
--- a/js/src/vm/UnboxedObject.cpp
e43f4b
+++ b/js/src/vm/UnboxedObject.cpp
e43f4b
@@ -86,9 +86,16 @@ static const uintptr_t CLEAR_CONSTRUCTOR_CODE_TOKEN = 0x1;
e43f4b
 #endif
e43f4b
e43f4b
 #ifdef JS_CODEGEN_ARM64
e43f4b
-  // ARM64 communicates stack address via sp, but uses a pseudo-sp for
e43f4b
-  // addressing.
e43f4b
-  masm.initStackPtr();
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
   MOZ_ASSERT(propertiesReg.volatile_());
e43f4b
@@ -239,7 +246,22 @@ static const uintptr_t CLEAR_CONSTRUCTOR_CODE_TOKEN = 0x1;
e43f4b
   if (ScratchDoubleReg.volatile_()) masm.pop(ScratchDoubleReg);
e43f4b
   masm.PopRegsInMask(savedNonVolatileRegisters);
e43f4b
e43f4b
-  masm.abiret();
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
   masm.bind(&failureStoreOther);
e43f4b
e43f4b
--
e43f4b
2.21.0
e43f4b