rust/tests/ui/abi/segfault-no-out-of-stack.rs

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

47 lines
1.3 KiB
Rust
Raw Normal View History

//@ run-pass
//@ ignore-wasm32 can't run commands
2019-04-24 16:26:33 +00:00
//@ ignore-sgx no processes
//@ ignore-fuchsia must translate zircon signal to SIGSEGV/SIGBUS, FIXME (#58590)
2024-04-16 03:46:27 +00:00
#![feature(rustc_private)]
use std::env;
2024-04-16 03:46:27 +00:00
use std::ffi::c_char;
2020-09-01 21:12:52 +00:00
use std::process::{Command, ExitStatus};
2016-11-24 00:09:51 +00:00
#[link(name = "rust_test_helpers", kind = "static")]
2020-09-01 21:12:52 +00:00
extern "C" {
2024-04-16 03:46:27 +00:00
fn rust_get_null_ptr() -> *mut c_char;
}
#[cfg(unix)]
2024-04-16 03:46:27 +00:00
fn check_status(status: ExitStatus) {
extern crate libc;
use std::os::unix::process::ExitStatusExt;
2020-09-01 21:12:52 +00:00
assert!(status.signal() == Some(libc::SIGSEGV) || status.signal() == Some(libc::SIGBUS));
}
#[cfg(not(unix))]
2024-04-16 03:46:27 +00:00
fn check_status(status: ExitStatus) {
assert!(!status.success());
}
fn main() {
let args: Vec<String> = env::args().collect();
if args.len() > 1 && args[1] == "segfault" {
2020-09-01 21:12:52 +00:00
unsafe {
*rust_get_null_ptr() = 1;
}; // trigger a segfault
} else {
let segfault = Command::new(&args[0]).arg("segfault").output().unwrap();
let stderr = String::from_utf8_lossy(&segfault.stderr);
let stdout = String::from_utf8_lossy(&segfault.stdout);
println!("stdout: {}", stdout);
println!("stderr: {}", stderr);
println!("status: {}", segfault.status);
check_status(segfault.status);
assert!(!stderr.contains("has overflowed its stack"));
}
}