@@ -239,6 +239,9 @@ cfg_if! {
239
239
if info. parent_fiber == 0i32 as _ {
240
240
panic!( "unable to convert thread to fiber" ) ;
241
241
}
242
+ // remember the old stack limit
243
+ let old_stack_limit = get_stack_limit( ) ;
244
+ // bump the know stack size in the thread local
242
245
set_stack_limit( stack_size) ;
243
246
let fiber = kernel32:: CreateFiber ( stack_size as _, Some ( fiber_proc) , & mut info as * mut FiberInfo as * mut _) ;
244
247
if fiber == 0i32 as _ {
@@ -249,6 +252,11 @@ cfg_if! {
249
252
// fiber execution finished, we can safely delete it now
250
253
kernel32:: DeleteFiber ( fiber) ;
251
254
255
+ // restore the old stack limit
256
+ if let Some ( old) = old_stack_limit {
257
+ set_stack_limit( old) ;
258
+ }
259
+
252
260
if !was_fiber {
253
261
kernel32:: ConvertFiberToThread ( ) ;
254
262
}
@@ -262,6 +270,7 @@ cfg_if! {
262
270
cfg_if! {
263
271
if #[ cfg( any( target_arch = "x86_64" , target_arch = "x86" ) ) ] {
264
272
#[ inline( always) ]
273
+ // We cannot know the initial stack size on x86
265
274
unsafe fn guess_os_stack_limit( ) -> Option <usize > {
266
275
None
267
276
}
@@ -309,6 +318,9 @@ cfg_if! {
309
318
libc:: pthread_get_stacksize_np( libc:: pthread_self( ) ) as usize )
310
319
}
311
320
} else {
321
+ // fallback for other platforms is to always increase the stack if we're on
322
+ // the root stack. After we increased the stack once, we know the new stack
323
+ // size and don't need this pessimization anymore
312
324
unsafe fn guess_os_stack_limit( ) -> Option <usize > {
313
325
None
314
326
}
0 commit comments