@@ -31,25 +31,35 @@ extern unsigned char __global_base;
3131extern weak unsigned char __stack_high ;
3232extern weak unsigned char __stack_low ;
3333
34- static inline void setup_default_stack_size ()
34+ struct stack_bounds {
35+ void * base ;
36+ size_t size ;
37+ };
38+
39+ static inline struct stack_bounds get_stack_bounds ()
3540{
36- ptrdiff_t stack_size ;
41+ struct stack_bounds bounds ;
3742
38- if (& __stack_high )
39- stack_size = & __stack_high - & __stack_low ;
40- else {
43+ if (& __stack_high ) {
44+ bounds .base = & __stack_high ;
45+ bounds .size = & __stack_high - & __stack_low ;
46+ } else {
4147 unsigned char * sp ;
4248 __asm__(
4349 ".globaltype __stack_pointer, i32\n"
4450 "global.get __stack_pointer\n"
4551 "local.set %0\n"
4652 : "=r" (sp ));
47- stack_size = sp > & __global_base ? & __heap_base - & __data_end : (ptrdiff_t )& __global_base ;
53+ if (sp > & __global_base ) {
54+ bounds .base = & __heap_base ;
55+ bounds .size = & __heap_base - & __data_end ;
56+ } else {
57+ bounds .base = & __global_base ;
58+ bounds .size = (size_t )& __global_base ;
59+ }
4860 }
4961
50- __default_stacksize =
51- stack_size < DEFAULT_STACK_MAX ?
52- stack_size : DEFAULT_STACK_MAX ;
62+ return bounds ;
5363}
5464
5565void __wasi_init_tp () {
@@ -68,8 +78,14 @@ int __init_tp(void *p)
6878 td -> detach_state = DT_JOINABLE ;
6979 td -> tid = __syscall (SYS_set_tid_address , & __thread_list_lock );
7080#else
71- setup_default_stack_size ();
81+ struct stack_bounds bounds = get_stack_bounds ();
82+ __default_stacksize =
83+ bounds .size < DEFAULT_STACK_MAX ?
84+ bounds .size : DEFAULT_STACK_MAX ;
7285 td -> detach_state = DT_JOINABLE ;
86+ td -> stack = bounds .base ;
87+ td -> stack_size = bounds .size ;
88+ td -> guard_size = 0 ;
7389 /*
7490 * Initialize the TID to a value which doesn't conflict with
7591 * host-allocated TIDs, so that TID-based locks can work.
0 commit comments