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

dc9548
# HG changeset patch
dc9548
# User Lars T Hansen <lhansen@mozilla.com>
dc9548
# Date 1519822672 -3600
dc9548
# Node ID 800abe66894d6b07b24bccecbf6a65e2261076f6
dc9548
# Parent  223c97459e96183eb616aed39147207bdb953ba8
dc9548
Bug 1375074 - Save and restore non-volatile x28 on ARM64 for generated unboxed object constructor.  r=sstangl
dc9548
dc9548
Origin: upstream
dc9548
Applied-upstream: 61, commit: https://hg.mozilla.org/mozilla-central/rev/800abe66894d
dc9548
---
dc9548
 js/src/vm/UnboxedObject.cpp | 30 ++++++++++++++++++++++++++----
dc9548
 1 file changed, 26 insertions(+), 4 deletions(-)
dc9548
dc9548
diff --git a/js/src/vm/UnboxedObject.cpp b/js/src/vm/UnboxedObject.cpp
dc9548
index 35ca20d7405f..1c20a1093d13 100644
dc9548
--- a/js/src/vm/UnboxedObject.cpp
dc9548
+++ b/js/src/vm/UnboxedObject.cpp
dc9548
@@ -86,9 +86,16 @@ static const uintptr_t CLEAR_CONSTRUCTOR_CODE_TOKEN = 0x1;
dc9548
 #endif
dc9548
dc9548
 #ifdef JS_CODEGEN_ARM64
dc9548
-  // ARM64 communicates stack address via sp, but uses a pseudo-sp for
dc9548
-  // addressing.
dc9548
-  masm.initStackPtr();
dc9548
+    // ARM64 communicates stack address via sp, but uses a pseudo-sp (PSP) for
dc9548
+    // addressing.  The register we use for PSP may however also be used by
dc9548
+    // calling code, and it is nonvolatile, so save it.  Do this as a special
dc9548
+    // case first because the generic save/restore code needs the PSP to be
dc9548
+    // initialized already.
dc9548
+    MOZ_ASSERT(PseudoStackPointer64.Is(masm.GetStackPointer64()));
dc9548
+    masm.Str(PseudoStackPointer64, vixl::MemOperand(sp, -16, vixl::PreIndex));
dc9548
+
dc9548
+    // Initialize the PSP from the SP.
dc9548
+    masm.initStackPtr();
dc9548
 #endif
dc9548
dc9548
   MOZ_ASSERT(propertiesReg.volatile_());
dc9548
@@ -239,7 +246,22 @@ static const uintptr_t CLEAR_CONSTRUCTOR_CODE_TOKEN = 0x1;
dc9548
   if (ScratchDoubleReg.volatile_()) masm.pop(ScratchDoubleReg);
dc9548
   masm.PopRegsInMask(savedNonVolatileRegisters);
dc9548
dc9548
-  masm.abiret();
dc9548
+#ifdef JS_CODEGEN_ARM64
dc9548
+    // Now restore the value that was in the PSP register on entry, and return.
dc9548
+
dc9548
+    // Obtain the correct SP from the PSP.
dc9548
+    masm.Mov(sp, PseudoStackPointer64);
dc9548
+
dc9548
+    // Restore the saved value of the PSP register, this value is whatever the
dc9548
+    // caller had saved in it, not any actual SP value, and it must not be
dc9548
+    // overwritten subsequently.
dc9548
+    masm.Ldr(PseudoStackPointer64, vixl::MemOperand(sp, 16, vixl::PostIndex));
dc9548
+
dc9548
+    // Perform a plain Ret(), as abiret() will move SP <- PSP and that is wrong.
dc9548
+    masm.Ret(vixl::lr);
dc9548
+#else
dc9548
+    masm.abiret();
dc9548
+#endif
dc9548
dc9548
   masm.bind(&failureStoreOther);
dc9548
dc9548
--
dc9548
2.21.0
dc9548