Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

std::threads: revisit stack address calculation on netbsd. #122002

Merged
merged 2 commits into from
Mar 11, 2024
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 21 additions & 2 deletions library/std/src/sys/pal/unix/thread.rs
Original file line number Diff line number Diff line change
Expand Up @@ -803,12 +803,30 @@ pub mod guard {
Some(stack_ptr.with_addr(stackaddr))
}

#[cfg(target_os = "netbsd")]
unsafe fn get_stack_start() -> Option<*mut libc::c_void> {
let mut ret = None;
let mut attr: libc::pthread_attr_t = crate::mem::zeroed();
workingjubilee marked this conversation as resolved.
Show resolved Hide resolved
let e = libc::pthread_getattr_np(libc::pthread_self(), &mut attr);
workingjubilee marked this conversation as resolved.
Show resolved Hide resolved
if e == 0 {
let mut stackaddr = crate::ptr::null_mut();
let mut stacksize = 0;
let mut guardsize = 0;
assert_eq!(libc::pthread_attr_getstack(&attr, &mut stackaddr, &mut stacksize), 0);
// on netbsd, we need to take in account the guard size to push up
// the stack's address from the bottom.
assert_eq!(libc::pthread_attr_getguardsize(&attr, &mut guardsize), 0);
stackaddr = stackaddr.add(guardsize);
workingjubilee marked this conversation as resolved.
Show resolved Hide resolved
ret = Some(stackaddr);
}
ret
}

#[cfg(any(
target_os = "android",
target_os = "freebsd",
target_os = "hurd",
target_os = "linux",
target_os = "netbsd",
target_os = "l4re"
))]
unsafe fn get_stack_start() -> Option<*mut libc::c_void> {
Expand Down Expand Up @@ -911,9 +929,10 @@ pub mod guard {
}
}) * page_size;
Some(guard)
} else if cfg!(target_os = "openbsd") {
} else if cfg!(any(target_os = "openbsd", target_os = "netbsd")) {
Copy link
Member

@workingjubilee workingjubilee Mar 11, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah, I was being a bit dense earlier, it seems!

// OpenBSD stack already includes a guard page, and stack is
// immutable.
// NetBSD stack includes the guard page.
//
// We'll just note where we expect rlimit to start
// faulting, so our handler can report "stack overflow", and
Expand Down
Loading