Skip to content

Commit

Permalink
Rollup merge of rust-lang#130132 - sunshowers:illumos-sigsegv, r=Nora…
Browse files Browse the repository at this point in the history
…trieb

[illumos] enable SIGSEGV handler to detect stack overflows

Use the same code as Solaris. I couldn't find any tests regarding this, but I did test a stage0 build against my stack-exhaust-test binary [1]. Before:

```
running with use_stacker = No, new_thread = false, make_large_local = false
zsh: segmentation fault (core dumped)  cargo run
```

After:

```
running with use_stacker = No, new_thread = false, make_large_local = false

thread 'main' has overflowed its stack
fatal runtime error: stack overflow
zsh: IOT instruction (core dumped)  cargo +stage0 run
```

Fixes rust-lang#128568.

[1] https://github.com/sunshowers/stack-exhaust-test/
  • Loading branch information
workingjubilee authored Sep 10, 2024
2 parents ec7fd8a + af9a77d commit 0bbb25d
Showing 1 changed file with 11 additions and 4 deletions.
15 changes: 11 additions & 4 deletions std/src/sys/pal/unix/stack_overflow.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,8 @@ impl Drop for Handler {
target_os = "macos",
target_os = "netbsd",
target_os = "openbsd",
target_os = "solaris"
target_os = "solaris",
target_os = "illumos",
))]
mod imp {
#[cfg(not(all(target_os = "linux", target_env = "gnu")))]
Expand Down Expand Up @@ -280,7 +281,7 @@ mod imp {
libc::SIGSTKSZ
}

#[cfg(target_os = "solaris")]
#[cfg(any(target_os = "solaris", target_os = "illumos"))]
unsafe fn get_stack_start() -> Option<*mut libc::c_void> {
let mut current_stack: libc::stack_t = crate::mem::zeroed();
assert_eq!(libc::stack_getbounds(&mut current_stack), 0);
Expand Down Expand Up @@ -486,7 +487,12 @@ mod imp {
Some(guardaddr..guardaddr + page_size)
}

#[cfg(any(target_os = "macos", target_os = "openbsd", target_os = "solaris"))]
#[cfg(any(
target_os = "macos",
target_os = "openbsd",
target_os = "solaris",
target_os = "illumos",
))]
// FIXME: I am probably not unsafe.
unsafe fn current_guard() -> Option<Range<usize>> {
let stackptr = get_stack_start()?;
Expand Down Expand Up @@ -569,7 +575,8 @@ mod imp {
target_os = "macos",
target_os = "netbsd",
target_os = "openbsd",
target_os = "solaris"
target_os = "solaris",
target_os = "illumos",
)))]
mod imp {
pub unsafe fn init() {}
Expand Down

0 comments on commit 0bbb25d

Please sign in to comment.