2019-07-26 21:54:25 +00:00
|
|
|
// run-pass
|
2017-06-21 19:08:18 +00:00
|
|
|
// ignore-arm
|
2017-07-21 08:21:42 +00:00
|
|
|
// ignore-aarch64
|
2018-03-09 10:05:05 +00:00
|
|
|
// ignore-mips
|
|
|
|
// ignore-mips64
|
2018-03-29 17:25:32 +00:00
|
|
|
// ignore-powerpc
|
|
|
|
// ignore-s390x
|
2018-06-04 11:27:32 +00:00
|
|
|
// ignore-sparc
|
|
|
|
// ignore-sparc64
|
2017-06-21 19:08:18 +00:00
|
|
|
// ignore-wasm
|
2017-10-18 01:45:42 +00:00
|
|
|
// ignore-emscripten no processes
|
2019-04-24 16:26:33 +00:00
|
|
|
// ignore-sgx no processes
|
2017-06-21 19:08:18 +00:00
|
|
|
|
2019-12-22 02:43:13 +00:00
|
|
|
use std::mem::MaybeUninit;
|
2017-06-21 19:08:18 +00:00
|
|
|
use std::process::Command;
|
|
|
|
use std::thread;
|
|
|
|
use std::env;
|
|
|
|
|
|
|
|
#[link(name = "rust_test_helpers", kind = "static")]
|
|
|
|
extern {
|
|
|
|
#[link_name = "rust_dbg_extern_identity_u64"]
|
|
|
|
fn black_box(u: u64);
|
|
|
|
}
|
|
|
|
|
|
|
|
fn main() {
|
|
|
|
let args = env::args().skip(1).collect::<Vec<_>>();
|
|
|
|
if args.len() > 0 {
|
|
|
|
match &args[0][..] {
|
2019-12-22 02:43:13 +00:00
|
|
|
"main-thread" => recurse(&MaybeUninit::uninit()),
|
|
|
|
"child-thread" => thread::spawn(|| recurse(&MaybeUninit::uninit())).join().unwrap(),
|
2017-06-21 19:08:18 +00:00
|
|
|
_ => panic!(),
|
|
|
|
}
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
let me = env::current_exe().unwrap();
|
|
|
|
|
|
|
|
// The linux kernel has some different behavior for the main thread because
|
|
|
|
// the main thread's stack can typically grow. We can't always guarantee
|
|
|
|
// that we report stack overflow on the main thread, see #43052 for some
|
|
|
|
// details
|
|
|
|
if cfg!(not(target_os = "linux")) {
|
|
|
|
assert_overflow(Command::new(&me).arg("main-thread"));
|
|
|
|
}
|
|
|
|
assert_overflow(Command::new(&me).arg("child-thread"));
|
|
|
|
}
|
|
|
|
|
|
|
|
#[allow(unconditional_recursion)]
|
2019-12-22 02:43:13 +00:00
|
|
|
fn recurse(array: &MaybeUninit<[u64; 1024]>) {
|
|
|
|
unsafe {
|
|
|
|
black_box(array.as_ptr() as u64);
|
|
|
|
}
|
|
|
|
let local: MaybeUninit<[u64; 1024]> = MaybeUninit::uninit();
|
2017-06-21 19:08:18 +00:00
|
|
|
recurse(&local);
|
|
|
|
}
|
|
|
|
|
|
|
|
fn assert_overflow(cmd: &mut Command) {
|
|
|
|
let output = cmd.output().unwrap();
|
|
|
|
assert!(!output.status.success());
|
|
|
|
let stdout = String::from_utf8_lossy(&output.stdout);
|
|
|
|
let stderr = String::from_utf8_lossy(&output.stderr);
|
|
|
|
println!("status: {}", output.status);
|
|
|
|
println!("stdout: {}", stdout);
|
|
|
|
println!("stderr: {}", stderr);
|
|
|
|
assert!(stdout.is_empty());
|
|
|
|
assert!(stderr.contains("has overflowed its stack\n"));
|
|
|
|
}
|