@@ -31,8 +31,6 @@ extern crate libc;
31
31
use std:: cell:: Cell ;
32
32
33
33
extern {
34
- fn __stacker_morestack_stack_limit ( ) -> usize ;
35
- fn __stacker_set_morestack_stack_limit ( limit : usize ) ;
36
34
fn __stacker_stack_pointer ( ) -> usize ;
37
35
fn __stacker_switch_stacks ( new_stack : usize ,
38
36
fnptr : * const u8 ,
@@ -41,7 +39,7 @@ extern {
41
39
42
40
thread_local ! {
43
41
static STACK_LIMIT : Cell <usize > = Cell :: new( unsafe {
44
- guess_os_morestack_stack_limit ( )
42
+ guess_os_stack_limit ( )
45
43
} )
46
44
}
47
45
@@ -79,7 +77,6 @@ unsafe fn grow_the_stack<R, F: FnOnce() -> R>(stack_size: usize, f: F) -> R {
79
77
struct Context < F : FnOnce ( ) -> R , R > {
80
78
thunk : Option < F > ,
81
79
ret : Option < R > ,
82
- new_limit : usize ,
83
80
}
84
81
85
82
// Align to 16-bytes (see below for why)
@@ -90,19 +87,15 @@ unsafe fn grow_the_stack<R, F: FnOnce() -> R>(stack_size: usize, f: F) -> R {
90
87
let new_limit = stack. as_ptr ( ) as usize + 32 * 1024 ;
91
88
92
89
// Save off the old stack limits
93
- let old_morestack_limit = __stacker_morestack_stack_limit ( ) ;
94
90
let old_limit = get_stack_limit ( ) ;
95
91
96
- // Prepare stack limits for the stack switch, note that the morestack stack
97
- // limit will be set to a real value once we've switched threads.
98
- __stacker_set_morestack_stack_limit ( 0 ) ;
92
+ // Prepare stack limits for the stack switch
99
93
set_stack_limit ( new_limit) ;
100
94
101
95
// Set up the arguments and do the actual stack switch.
102
96
let mut cx: Context < F , R > = Context {
103
97
thunk : Some ( f) ,
104
98
ret : None ,
105
- new_limit : new_limit,
106
99
} ;
107
100
108
101
// Make sure the stack is 16-byte aligned which should be enough for all
@@ -121,14 +114,11 @@ unsafe fn grow_the_stack<R, F: FnOnce() -> R>(stack_size: usize, f: F) -> R {
121
114
122
115
// Once we've returned reset bothe stack limits and then return value same
123
116
// value the closure returned.
124
- __stacker_set_morestack_stack_limit ( old_morestack_limit) ;
125
117
set_stack_limit ( old_limit) ;
126
118
return cx. ret . unwrap ( ) ;
127
119
128
120
unsafe extern fn doit < R , F : FnOnce ( ) -> R > ( cx : & mut Context < F , R > ) {
129
- __stacker_set_morestack_stack_limit ( cx. new_limit ) ;
130
121
cx. ret = Some ( cx. thunk . take ( ) . unwrap ( ) ( ) ) ;
131
- __stacker_set_morestack_stack_limit ( 0 ) ;
132
122
}
133
123
}
134
124
@@ -138,7 +128,7 @@ cfg_if! {
138
128
//
139
129
// https://github.com/adobe/webkit/blob/0441266/Source/WTF/wtf
140
130
// /StackBounds.cpp
141
- unsafe fn guess_os_morestack_stack_limit ( ) -> usize {
131
+ unsafe fn guess_os_stack_limit ( ) -> usize {
142
132
#[ cfg( target_pointer_width = "32" ) ]
143
133
extern {
144
134
#[ link_name = "__stacker_get_tib_32" ]
@@ -159,7 +149,7 @@ cfg_if! {
159
149
} else if #[ cfg( target_os = "linux" ) ] {
160
150
use std:: mem;
161
151
162
- unsafe fn guess_os_morestack_stack_limit ( ) -> usize {
152
+ unsafe fn guess_os_stack_limit ( ) -> usize {
163
153
let mut attr: libc:: pthread_attr_t = mem:: zeroed( ) ;
164
154
assert_eq!( libc:: pthread_attr_init( & mut attr) , 0 ) ;
165
155
assert_eq!( libc:: pthread_getattr_np( libc:: pthread_self( ) ,
@@ -174,12 +164,12 @@ cfg_if! {
174
164
} else if #[ cfg( target_os = "macos" ) ] {
175
165
use libc:: { c_void, pthread_t, size_t} ;
176
166
177
- unsafe fn guess_os_morestack_stack_limit ( ) -> usize {
167
+ unsafe fn guess_os_stack_limit ( ) -> usize {
178
168
libc:: pthread_get_stackaddr_np( libc:: pthread_self( ) ) as usize -
179
169
libc:: pthread_get_stacksize_np( libc:: pthread_self( ) ) as usize
180
170
}
181
171
} else {
182
- unsafe fn guess_os_morestack_stack_limit ( ) -> usize {
172
+ unsafe fn guess_os_stack_limit ( ) -> usize {
183
173
panic!( "cannot guess the stack limit on this platform" ) ;
184
174
}
185
175
}
0 commit comments