@@ -77,14 +77,27 @@ void mp_stack_set_bottom(void* stack_bottom) {
77
77
MP_STATE_THREAD (stack_bottom ) = stack_bottom ;
78
78
}
79
79
80
+ // Return the current frame pointer. This can be used as an
CDE9
81
+ // approximation for the stack pointer of the _calling_ function.
82
+ // This routine must not be inlined. This method is
83
+ // architecture-independent, as opposed to using asm("sp") or similar.
84
+ //
85
+ // The stack_dummy approach used elsewhere in this file is not safe in
86
+ // all cases. That value may be below the actual top of the stack.
87
+ static void * approx_stack_pointer (void ){
88
+ __asm volatile ("" );
89
+ return __builtin_frame_address (0 );
90
+ }
91
+
80
92
// Fill stack space down toward the stack limit with a known unusual value.
81
93
void mp_stack_fill_with_sentinel (void ) {
82
94
// Force routine to not be inlined. Better guarantee than MP_NOINLINE for -flto.
83
95
__asm volatile ("" );
84
- volatile char * volatile p ;
85
- // Start filling stack just below the last variable in the current stack frame, which is p.
86
- // Continue until we've hit the bottom of the stack (lowest address, logical "ceiling" of stack).
87
- p = (char * ) (& p - 1 );
96
+ // Start filling stack just below the current stack frame.
97
+ // Continue until we've hit the bottom of the stack (lowest address,
98
+ // logical "ceiling" of stack).
99
+ char * p = (char * ) approx_stack_pointer () - 1 ;
100
+
88
101
while (p >= MP_STATE_THREAD (stack_bottom )) {
89
102
* p -- = MP_MAX_STACK_USAGE_SENTINEL_BYTE ;
90
103
}
0 commit comments