Files
rust/tests/ui/abi/stack-probes.rs
Jorge Aparicio 49769afe4b QNX SDP 8 fixes.
1) setsid/setpgrp: check child's group process ID

Linux [1], FreeBSD [2] and the Open Group [3] manuals for both setsid and
setpgrp state that the calling process will be assigned a process group ID that
matches its process ID so check that's the case in the test by calling
getpgid on the child process ID.

on QNX8 (as of GA8.0.2) libc::kill(pgid) appears unable to terminate the
child process so skip that check on that target as it's behavior that
libstd provides no API for

[1]: https://man7.org/linux/man-pages/man2/setsid.2.html
[2]: https://man.freebsd.org/cgi/man.cgi?query=setsid&sektion=2
[3]: https://pubs.opengroup.org/onlinepubs/000095399/functions/setsid.html

2) fix handling of sockaddr_un.len on QNX

also extend the existing tests to exercise the getsockname(2) and
getpeername(2) paths with both named and unnamed Unix sockets

3) Additional fixes library/std after earlier PR renamed some targets

4) Replace more instances of "QNX Neutrino / QNX OS" with "QNX SDP" and fix up some documentation URLs

5) Tests ignored on target_os = "nto" should also be ignored on target_os = "qnx".

6) Simplify nto-qnx.md documentation

cc-rs now knows about QNX so the environment isn't required
2026-07-07 17:31:05 +01:00

89 lines
2.9 KiB
Rust

//@ revisions: aarch64 x32 x64
//@ run-pass
//@[aarch64] only-aarch64
//@[x32] only-x86
//@[x64] only-x86_64
//@ needs-subprocess
//@ ignore-fuchsia no exception handler registered for segfault
//@ ignore-nto Crash analysis impossible at SIGSEGV in QNX SDP 7.x
//@ ignore-qnx Crash analysis impossible at SIGSEGV in QNX SDP 8.0+
//@ ignore-ios Stack probes are enabled, but the SIGSEGV handler isn't
//@ ignore-tvos Stack probes are enabled, but the SIGSEGV handler isn't
//@ ignore-watchos Stack probes are enabled, but the SIGSEGV handler isn't
//@ ignore-visionos Stack probes are enabled, but the SIGSEGV handler isn't
//@ ignore-backends: gcc
use std::env;
use std::mem::MaybeUninit;
use std::process::Command;
use std::thread;
#[link(name = "rust_test_helpers", kind = "static")]
extern "C" {
#[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][..] {
"main-recurse" => overflow_recurse(),
"child-recurse" => thread::spawn(overflow_recurse).join().unwrap(),
"child-frame" => overflow_frame(),
_ => 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-recurse"));
}
assert_overflow(Command::new(&me).arg("child-recurse"));
assert_overflow(Command::new(&me).arg("child-frame"));
}
#[allow(unconditional_recursion)]
fn recurse(array: &MaybeUninit<[u64; 1024]>) {
unsafe {
black_box(array.as_ptr() as u64);
}
let local: MaybeUninit<[u64; 1024]> = MaybeUninit::uninit();
recurse(&local);
}
#[inline(never)]
fn overflow_recurse() {
recurse(&MaybeUninit::uninit());
}
fn overflow_frame() {
// By using a 1MiB stack frame with only 512KiB stack, we'll jump over any
// guard page, even with 64K pages -- but stack probes should catch it.
const STACK_SIZE: usize = 512 * 1024;
thread::Builder::new().stack_size(STACK_SIZE).spawn(|| {
let local: MaybeUninit<[u8; 2 * STACK_SIZE]> = MaybeUninit::uninit();
unsafe {
black_box(local.as_ptr() as u64);
}
}).unwrap().join().unwrap();
}
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"));
}