Skip to content

Commit a731f16

Browse files
committed
test: Test hitting the dynamic linker in the red zone
1 parent 3b8bfaf commit a731f16

File tree

4 files changed

+91
-3
lines changed

4 files changed

+91
-3
lines changed

src/rt/rust_builtin.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -273,6 +273,12 @@ debug_ptrcast(type_desc *from_ty,
273273
return ptr;
274274
}
275275

276+
extern "C" CDECL void *
277+
debug_get_stk_seg() {
278+
rust_task *task = rust_scheduler::get_task();
279+
return task->stk;
280+
}
281+
276282
extern "C" CDECL rust_vec*
277283
rust_list_files(rust_str *path) {
278284
rust_task *task = rust_scheduler::get_task();

src/rt/rust_upcall.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -222,7 +222,7 @@ upcall_call_shim_on_c_stack(void *args, void *fn_ptr) {
222222
// FIXME (1226) - The shim functions generated by rustc contain the
223223
// morestack prologue, so we need to let them know they have enough
224224
// stack.
225-
//record_sp(0);
225+
record_sp(0);
226226

227227
rust_scheduler *sched = task->sched;
228228
try {
@@ -232,8 +232,8 @@ upcall_call_shim_on_c_stack(void *args, void *fn_ptr) {
232232
//task->record_stack_limit();
233233
throw;
234234
}
235-
//task = rust_scheduler::get_task();
236-
//task->record_stack_limit();
235+
task = rust_scheduler::get_task();
236+
task->record_stack_limit();
237237
}
238238

239239
struct rust_new_stack2_args {

src/rt/rustrt.def.in

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ del_port
88
debug_ptrcast
99
debug_tag
1010
debug_tydesc
11+
debug_get_stk_seg
1112
do_gc
1213
drop_task
1314
get_port_id

src/test/run-pass/morestack6.rs

Lines changed: 81 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,81 @@
1+
// xfail-test
2+
// compile-flags:--stack-growth
3+
4+
// This test attempts to force the dynamic linker to resolve
5+
// external symbols as close to the red zone as possible.
6+
7+
use std;
8+
import std::task;
9+
import std::rand;
10+
11+
native mod rustrt {
12+
fn set_min_stack(size: uint);
13+
fn debug_get_stk_seg() -> *u8;
14+
15+
fn unsupervise();
16+
fn last_os_error() -> str;
17+
fn rust_getcwd() -> str;
18+
fn refcount(box: @int);
19+
fn do_gc();
20+
fn pin_task();
21+
fn unpin_task();
22+
fn get_task_id();
23+
fn sched_threads();
24+
fn rust_get_task();
25+
}
26+
27+
fn calllink01() { rustrt::unsupervise(); }
28+
fn calllink02() { rustrt::last_os_error(); }
29+
fn calllink03() { rustrt::rust_getcwd(); }
30+
fn calllink04() { rustrt::refcount(@0); }
31+
fn calllink05() { rustrt::do_gc(); }
32+
fn calllink06() { rustrt::pin_task(); }
33+
fn calllink07() { rustrt::unpin_task(); }
34+
fn calllink08() { rustrt::get_task_id(); }
35+
fn calllink09() { rustrt::sched_threads(); }
36+
fn calllink10() { rustrt::rust_get_task(); }
37+
38+
fn runtest(&&args:(fn(), u32)) {
39+
let (f, frame_backoff) = args;
40+
runtest2(f, frame_backoff, 0 as *u8);
41+
}
42+
43+
fn runtest2(f: fn(), frame_backoff: u32, last_stk: *u8) -> u32 {
44+
let curr_stk = rustrt::debug_get_stk_seg();
45+
if (last_stk != curr_stk && last_stk != 0 as *u8) {
46+
// We switched stacks, go back and try to hit the dynamic linker
47+
frame_backoff
48+
} else {
49+
let frame_backoff = runtest2(f, frame_backoff, curr_stk);
50+
if frame_backoff > 1u32 {
51+
frame_backoff - 1u32
52+
} else if frame_backoff == 1u32 {
53+
f();
54+
0u32
55+
} else {
56+
0u32
57+
}
58+
}
59+
}
60+
61+
fn main() {
62+
let fns = [
63+
calllink01,
64+
calllink02,
65+
calllink03,
66+
calllink04,
67+
calllink05,
68+
calllink06,
69+
calllink07,
70+
calllink08,
71+
calllink09,
72+
calllink10
73+
];
74+
let rng = rand::mk_rng();
75+
for f in fns {
76+
let sz = rng.next() % 256u32 + 256u32;
77+
let frame_backoff = rng.next() % 10u32 + 1u32;
78+
rustrt::set_min_stack(sz as uint);
79+
task::join(task::spawn_joinable((f, frame_backoff), runtest));
80+
}
81+
}

0 commit comments

Comments
 (0)