File tree Expand file tree Collapse file tree 2 files changed +45
-63
lines changed Expand file tree Collapse file tree 2 files changed +45
-63
lines changed Original file line number Diff line number Diff line change 1- .text
2-
3- #if defined(__APPLE__) || defined(_WIN32)
4- #define RECORD_SP_LIMIT _record_sp_limit
5- #define GET_SP_LIMIT _get_sp_limit
6- #define GET_SP _get_sp
7- #else
8- #define RECORD_SP_LIMIT record_sp_limit
9- #define GET_SP_LIMIT get_sp_limit
10- #define GET_SP get_sp
11- #endif
12-
13- .globl RECORD_SP_LIMIT
14- .globl GET_SP_LIMIT
15- .globl GET_SP
16-
17- #if defined(__linux__) || defined(__FreeBSD__)
18- RECORD_SP_LIMIT:
19- movl 4 (%esp ), %eax
20- movl %eax , %gs :48
21- ret
22- #endif
23-
24- #if defined(__APPLE__)
25- RECORD_SP_LIMIT:
26- movl $0x48 +90*4 , %eax
27- movl 4 (%esp ), %ecx
28- movl %ecx , %gs :(%eax )
29- ret
30- #endif
31-
32- #if defined(_WIN32)
33- RECORD_SP_LIMIT:
34- movl 4 (%esp ), %eax
35- movl %eax , %fs :0x14
36- ret
37- #endif
38-
39- #if defined(__linux__) || defined(__FreeBSD__)
40- GET_SP_LIMIT:
41- movl %gs :48 , %eax
42- ret
43- #endif
44-
45- #if defined(__APPLE__)
46- GET_SP_LIMIT:
47- movl $0x48 +90*4 , %ecx
48- movl %gs :(%ecx ), %eax
49- ret
50- #endif
51-
52- #if defined(_WIN32)
53- GET_SP_LIMIT:
54- movl %fs :0x14 , %eax
55- ret
56- #endif
57-
58- GET_SP:
59- movl %esp , %eax
60- ret
Original file line number Diff line number Diff line change 1616#include "../../rust_globals.h"
1717
1818// Gets a pointer to the vicinity of the current stack pointer
19- extern "C" uintptr_t get_sp ();
19+ extern "C" ALWAYS_INLINE uintptr_t get_sp () {
20+ uintptr_t sp ;
21+ asm volatile (
22+ "movl %%esp, %0"
23+ : "=m" (sp ));
24+ return sp ;
25+ }
2026
2127// Gets the pointer to the end of the Rust stack from a platform-
2228// specific location in the thread control block
23- extern "C" CDECL uintptr_t get_sp_limit ();
29+ extern "C" CDECL ALWAYS_INLINE uintptr_t get_sp_limit () {
30+ uintptr_t limit ;
31+
32+ #if defined(__linux__ ) || defined(__FreeBSD__ )
33+ asm volatile (
34+ "movl %%gs:48, %0"
35+ : "=r" (limit ));
36+ #elif defined(__APPLE__ )
37+ asm volatile (
38+ "movl $0x48+90*4, %%ecx\n\t"
39+ "movl %%gs:(%%ecx), %0"
40+ : "=r" (limit )
41+ :: "ecx" );
42+ #elif defined(_WIN32 )
43+ asm volatile (
44+ "movl %%fs:0x14, %0"
45+ : "=r" (limit ));
46+ #endif
47+
48+ return limit ;
49+ }
2450
2551// Records the pointer to the end of the Rust stack in a platform-
2652// specific location in the thread control block
27- extern "C" CDECL void record_sp_limit (void * limit );
53+ extern "C" CDECL ALWAYS_INLINE void record_sp_limit (void * limit ) {
54+ #if defined(__linux__ ) || defined(__FreeBSD__ )
55+ asm volatile (
56+ "movl %0, %%gs:48"
57+ :: "r" (limit ));
58+ #elif defined(__APPLE__ )
59+ asm volatile (
60+ "movl $0x48+90*4, %%eax\n\t"
61+ "movl %0, %%gs:(%%eax)"
62+ :: "r" (limit )
63+ : "eax" );
64+ #elif defined(_WIN32 )
65+ asm volatile (
66+ "movl %0, %%fs:0x14"
67+ :: "r" (limit ));
68+ #endif
69+ }
2870
2971#endif
You can’t perform that action at this time.
0 commit comments