Skip to content

rt: Fix a corner-case in unwinding that leads to stack overflow #8217

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions src/rt/rust_task.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -609,10 +609,21 @@ when unwinding through __morestack).
void
rust_task::reset_stack_limit() {
uintptr_t sp = get_sp();
bool reseted = false;
while (!sp_in_stk_seg(sp, stk)) {
reseted = true;
prev_stack();
assert(stk != NULL && "Failed to find the current stack");
}

// Each call to prev_stack will record the stack limit. If we *didn't*
// call prev_stack then we still need to record it now to catch a corner case:
// the throw to initiate unwinding starts on the C stack while sp limit is 0.
// If we don't set the limit here then the rust code run subsequently will
// will veer into the red zone. Lame!
if (!reseted) {
record_stack_limit();
}
}

void
Expand Down
3 changes: 2 additions & 1 deletion src/test/run-pass/unwind-resource.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@
// option. This file may not be copied, modified, or distributed
// except according to those terms.

// xfail-test
// xfail-fast

extern mod extra;

use std::comm::*;
Expand Down