2011-12-05 19:20:59 -06:00
|
|
|
// This test attempts to force the dynamic linker to resolve
|
|
|
|
// external symbols as close to the red zone as possible.
|
|
|
|
|
2012-07-03 18:11:00 -05:00
|
|
|
extern mod rustrt {
|
2011-12-05 19:20:59 -06:00
|
|
|
fn debug_get_stk_seg() -> *u8;
|
|
|
|
|
2012-07-17 20:48:15 -05:00
|
|
|
fn rust_get_sched_id() -> libc::intptr_t;
|
2012-07-14 00:57:48 -05:00
|
|
|
fn last_os_error() -> ~str;
|
|
|
|
fn rust_getcwd() -> ~str;
|
2012-07-17 21:10:52 -05:00
|
|
|
fn get_task_id() -> libc::intptr_t;
|
2012-09-14 08:01:17 -05:00
|
|
|
fn rust_max_sched_threads();
|
2011-12-05 19:20:59 -06:00
|
|
|
fn rust_get_task();
|
|
|
|
}
|
|
|
|
|
2012-07-17 20:18:45 -05:00
|
|
|
fn calllink01() { rustrt::rust_get_sched_id(); }
|
2011-12-05 19:20:59 -06:00
|
|
|
fn calllink02() { rustrt::last_os_error(); }
|
|
|
|
fn calllink03() { rustrt::rust_getcwd(); }
|
|
|
|
fn calllink08() { rustrt::get_task_id(); }
|
2012-09-14 08:01:17 -05:00
|
|
|
fn calllink09() { rustrt::rust_max_sched_threads(); }
|
2011-12-05 19:20:59 -06:00
|
|
|
fn calllink10() { rustrt::rust_get_task(); }
|
|
|
|
|
2012-01-11 11:58:05 -06:00
|
|
|
fn runtest(f: fn~(), frame_backoff: u32) {
|
2011-12-05 19:20:59 -06:00
|
|
|
runtest2(f, frame_backoff, 0 as *u8);
|
|
|
|
}
|
|
|
|
|
2012-01-11 11:58:05 -06:00
|
|
|
fn runtest2(f: fn~(), frame_backoff: u32, last_stk: *u8) -> u32 {
|
2011-12-05 19:20:59 -06:00
|
|
|
let curr_stk = rustrt::debug_get_stk_seg();
|
|
|
|
if (last_stk != curr_stk && last_stk != 0 as *u8) {
|
|
|
|
// We switched stacks, go back and try to hit the dynamic linker
|
|
|
|
frame_backoff
|
|
|
|
} else {
|
|
|
|
let frame_backoff = runtest2(f, frame_backoff, curr_stk);
|
|
|
|
if frame_backoff > 1u32 {
|
|
|
|
frame_backoff - 1u32
|
|
|
|
} else if frame_backoff == 1u32 {
|
|
|
|
f();
|
|
|
|
0u32
|
|
|
|
} else {
|
|
|
|
0u32
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
fn main() {
|
2012-06-29 18:26:56 -05:00
|
|
|
let fns = ~[
|
2011-12-05 19:20:59 -06:00
|
|
|
calllink01,
|
|
|
|
calllink02,
|
|
|
|
calllink03,
|
|
|
|
calllink08,
|
|
|
|
calllink09,
|
|
|
|
calllink10
|
2012-06-29 18:26:56 -05:00
|
|
|
];
|
2012-08-27 16:22:25 -05:00
|
|
|
let rng = rand::Rng();
|
2012-06-30 18:19:07 -05:00
|
|
|
for fns.each |f| {
|
2011-12-05 19:20:59 -06:00
|
|
|
let sz = rng.next() % 256u32 + 256u32;
|
|
|
|
let frame_backoff = rng.next() % 10u32 + 1u32;
|
2012-06-30 18:19:07 -05:00
|
|
|
task::try(|| runtest(f, frame_backoff) );
|
2011-12-05 19:20:59 -06:00
|
|
|
}
|
2012-06-28 13:40:31 -05:00
|
|
|
}
|