]> git.lizzy.rs Git - rust.git/commitdiff
rt: Insert stack alignment checks into upcalls
authorBrian Anderson <banderson@mozilla.com>
Thu, 15 Dec 2011 08:24:35 +0000 (00:24 -0800)
committerBrian Anderson <banderson@mozilla.com>
Sat, 17 Dec 2011 02:18:43 +0000 (18:18 -0800)
src/rt/arch/i386/record_sp.S
src/rt/arch/x86_64/record_sp.S
src/rt/rust_upcall.cpp

index 0c9f078284679505d90a940025abc8029377137f..b9c42a650d844d88d44b5041ece86cffcc81ca04 100644 (file)
@@ -3,13 +3,16 @@
 #if defined(__APPLE__) || defined(_WIN32)
 #define RECORD_SP          _record_sp
 #define GET_SP             _get_sp
+#define CHECK_STACK        _check_stack_alignment
 #else
 #define RECORD_SP          record_sp
 #define GET_SP             get_sp
+#define CHECK_STACK        check_stack_alignment
 #endif
 
 .globl RECORD_SP
 .globl GET_SP
+.globl CHECK_STACK
 
 #if defined(__linux__)
 RECORD_SP:
@@ -35,4 +38,11 @@ RECORD_SP:
 
 GET_SP:
        movl %esp, %eax
-       ret
\ No newline at end of file
+       ret
+
+// This will segfault if not called on a 16-byte boundary
+CHECK_STACK:
+       subl $28, %esp
+       movaps %xmm0, (%esp)
+       addl $28, %esp
+       ret
index 415f6685655c944ffd8e9587a59e6ffdb780cbe6..af217d0f37faa277a1ea1c3ac884810edf8e1ef7 100644 (file)
@@ -3,13 +3,16 @@
 #if defined(__APPLE__) || defined(_WIN32)
 #define RECORD_SP          _record_sp
 #define GET_SP             _get_sp
+#define CHECK_STACK        _check_stack_alignment
 #else
 #define RECORD_SP          record_sp
 #define GET_SP             get_sp
+#define CHECK_STACK        check_stack_alignment
 #endif
 
 .globl RECORD_SP
 .globl GET_SP
+.globl CHECK_STACK
 
 #if defined(__linux__)
 RECORD_SP:
@@ -30,3 +33,10 @@ RECORD_SP:
 GET_SP:
        movq %rsp, %rax
        ret
+
+// This will segfault if not called on a 16-byte boundary
+CHECK_STACK:
+       subq $24, %rsp
+       movaps %xmm0, (%rsp)
+       addq $24, %rsp
+       ret
index 97e1321c02d933d0d79f4bec6cf97e161a974292..dd7e275cd045084408fe71e645222537774dfdef 100644 (file)
 #include "rust_upcall.h"
 #include <stdint.h>
 
+
+// This is called to ensure we've set up our rust stacks
+// correctly. Strategically placed at entry to upcalls because they begin on
+// the rust stack and happen frequently enough to catch most stack changes,
+// including at the beginning of all landing pads.
+extern "C" void
+check_stack_alignment() __attribute__ ((aligned (16)));
+
 #define SWITCH_STACK(A, F) upcall_call_shim_on_c_stack((void*)A, (void*)F)
 
 extern "C" void record_sp(void *limit);
@@ -26,6 +34,7 @@ extern "C" void record_sp(void *limit);
  */
 extern "C" CDECL void
 upcall_call_shim_on_c_stack(void *args, void *fn_ptr) {
+    check_stack_alignment();
     rust_task *task = rust_scheduler::get_task();
 
     // FIXME (1226) - The shim functions generated by rustc contain the
@@ -594,6 +603,7 @@ upcall_del_stack() {
 // needs to acquire the value of the stack pointer
 extern "C" CDECL void
 upcall_reset_stack_limit() {
+    check_stack_alignment();
     rust_task *task = rust_scheduler::get_task();
     task->reset_stack_limit();
 }