@@ -512,19 +512,19 @@ rust_task::new_stack(size_t requested_sz) {
512
512
size_t rust_stk_sz = get_next_stack_size (min_sz,
513
513
current_sz, requested_sz);
514
514
515
- if (total_stack_sz + rust_stk_sz > kernel->env ->max_stack_size ) {
515
+ size_t max_stack = kernel->env ->max_stack_size ;
516
+ size_t used_stack = total_stack_sz + rust_stk_sz;
517
+
518
+ // Don't allow stacks to grow forever. During unwinding we have to allow
519
+ // for more stack than normal in order to allow destructors room to run,
520
+ // arbitrarily selected as 2x the maximum stack size.
521
+ if (!unwinding && used_stack > max_stack) {
516
522
LOG_ERR (this , task, " task %" PRIxPTR " ran out of stack" , this );
517
- if (!unwinding) {
518
- fail ();
519
- } else {
520
- // FIXME: Because we have landing pads that may need more
521
- // stack than normally allowed we have to go allow the stack
522
- // to grow unbounded during unwinding. Would be nice to
523
- // have a different solution - maybe just double the limit.
524
- LOG_ERR (this , task, " task %" PRIxPTR " has blown its stack "
525
- " budget but we are unwinding so growing the stack "
526
- " anyway" );
527
- }
523
+ fail ();
524
+ } else if (unwinding && used_stack > max_stack) {
525
+ LOG_ERR (this , task,
526
+ " task %" PRIxPTR " ran out of stack during unwinding" , this );
527
+ fail ();
528
528
}
529
529
530
530
size_t sz = rust_stk_sz + RED_ZONE_SIZE;
0 commit comments