Skip to content

Commit 91b7118

Browse files
committed
auto merge of #8217 : brson/rust/reset_stack_limit, r=pcwalton
In some scenarios upcall_rust_stack_limit fails to record the stack limit, leaving it 0, and allowing subsequent Rust code to run into the red zone.
2 parents fbeeeeb + 044fa35 commit 91b7118

File tree

2 files changed

+13
-1
lines changed

2 files changed

+13
-1
lines changed

src/rt/rust_task.cpp

+11
Original file line numberDiff line numberDiff line change
@@ -609,10 +609,21 @@ when unwinding through __morestack).
609609
void
610610
rust_task::reset_stack_limit() {
611611
uintptr_t sp = get_sp();
612+
bool reseted = false;
612613
while (!sp_in_stk_seg(sp, stk)) {
614+
reseted = true;
613615
prev_stack();
614616
assert(stk != NULL && "Failed to find the current stack");
615617
}
618+
619+
// Each call to prev_stack will record the stack limit. If we *didn't*
620+
// call prev_stack then we still need to record it now to catch a corner case:
621+
// the throw to initiate unwinding starts on the C stack while sp limit is 0.
622+
// If we don't set the limit here then the rust code run subsequently will
623+
// will veer into the red zone. Lame!
624+
if (!reseted) {
625+
record_stack_limit();
626+
}
616627
}
617628

618629
void

src/test/run-pass/unwind-resource.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,8 @@
88
// option. This file may not be copied, modified, or distributed
99
// except according to those terms.
1010

11-
// xfail-test
11+
// xfail-fast
12+
1213
extern mod extra;
1314

1415
use std::comm::*;

0 commit comments

Comments
 (0)