File tree Expand file tree Collapse file tree 3 files changed +31
-1
lines changed Expand file tree Collapse file tree 3 files changed +31
-1
lines changed Original file line number Diff line number Diff line change 3
3
#if defined(__APPLE__) || defined(_WIN32)
4
4
#define RECORD_SP _record_sp
5
5
#define GET_SP _get_sp
6
+ #define CHECK_STACK _check_stack_alignment
6
7
#else
7
8
#define RECORD_SP record_sp
8
9
#define GET_SP get_sp
10
+ #define CHECK_STACK check_stack_alignment
9
11
#endif
10
12
11
13
.globl RECORD_SP
12
14
.globl GET_SP
15
+ .globl CHECK_STACK
13
16
14
17
#if defined(__linux__)
15
18
RECORD_SP:
@@ -35,4 +38,11 @@ RECORD_SP:
35
38
36
39
GET_SP:
37
40
movl %esp , %eax
38
- ret
41
+ ret
42
+
43
+ // This will segfault if not called on a 16-byte boundary
44
+ CHECK_STACK:
45
+ subl $28 , %esp
46
+ movaps %xmm0 , (%esp )
47
+ addl $28 , %esp
48
+ ret
Original file line number Diff line number Diff line change 3
3
#if defined(__APPLE__) || defined(_WIN32)
4
4
#define RECORD_SP _record_sp
5
5
#define GET_SP _get_sp
6
+ #define CHECK_STACK _check_stack_alignment
6
7
#else
7
8
#define RECORD_SP record_sp
8
9
#define GET_SP get_sp
10
+ #define CHECK_STACK check_stack_alignment
9
11
#endif
10
12
11
13
.globl RECORD_SP
12
14
.globl GET_SP
15
+ .globl CHECK_STACK
13
16
14
17
#if defined(__linux__)
15
18
RECORD_SP:
@@ -30,3 +33,10 @@ RECORD_SP:
30
33
GET_SP:
31
34
movq %rsp , %rax
32
35
ret
36
+
37
+ // This will segfault if not called on a 16-byte boundary
38
+ CHECK_STACK:
39
+ subq $24 , %rsp
40
+ movaps %xmm0 , (%rsp )
41
+ addq $24 , %rsp
42
+ ret
Original file line number Diff line number Diff line change 14
14
#include " rust_upcall.h"
15
15
#include < stdint.h>
16
16
17
+
18
+ // This is called to ensure we've set up our rust stacks
19
+ // correctly. Strategically placed at entry to upcalls because they begin on
20
+ // the rust stack and happen frequently enough to catch most stack changes,
21
+ // including at the beginning of all landing pads.
22
+ extern " C" void
23
+ check_stack_alignment () __attribute__ ((aligned (16 )));
24
+
17
25
#define SWITCH_STACK (A, F ) upcall_call_shim_on_c_stack((void *)A, (void *)F)
18
26
19
27
extern " C" void record_sp (void *limit);
@@ -26,6 +34,7 @@ extern "C" void record_sp(void *limit);
26
34
*/
27
35
extern " C" CDECL void
28
36
upcall_call_shim_on_c_stack (void *args, void *fn_ptr) {
37
+ check_stack_alignment ();
29
38
rust_task *task = rust_scheduler::get_task ();
30
39
31
40
// FIXME (1226) - The shim functions generated by rustc contain the
@@ -594,6 +603,7 @@ upcall_del_stack() {
594
603
// needs to acquire the value of the stack pointer
595
604
extern " C" CDECL void
596
605
upcall_reset_stack_limit () {
606
+ check_stack_alignment ();
597
607
rust_task *task = rust_scheduler::get_task ();
598
608
task->reset_stack_limit ();
599
609
}
You can’t perform that action at this time.
0 commit comments