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

few corrections for guess_os_stack_limit() on OpenBSD #34

Closed
wants to merge 2 commits into from
Closed
Changes from all commits
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
17 changes: 15 additions & 2 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -177,11 +177,24 @@ psm_stack_manipulation! {
old_stack_limit: get_stack_limit(),
};
let above_guard_page = new_stack.add(page_size);
#[cfg(not(target_os = "openbsd"))]
let result = libc::mprotect(
above_guard_page,
stack_bytes - page_size,
libc::PROT_READ | libc::PROT_WRITE
);
#[cfg(target_os = "openbsd")]
let result = if libc::mmap(
above_guard_page,
stack_bytes - page_size,
libc::PROT_READ | libc::PROT_WRITE,
libc::MAP_FIXED | libc::MAP_PRIVATE | libc::MAP_ANON | libc::MAP_STACK,
-1,
0) == above_guard_page {
0
} else {
-1
};
if result == -1 {
drop(guard);
panic!("unable to set stack permissions")
Expand Down Expand Up @@ -372,8 +385,8 @@ cfg_if! {
} else if #[cfg(target_os = "openbsd")] {
unsafe fn guess_os_stack_limit() -> Option<usize> {
let mut stackinfo = std::mem::MaybeUninit::<libc::stack_t>::uninit();
assert_eq!(libc::pthread_stackseg_np(libc::pthread_self(), stackinfo.as_mut_ptr()));
Some(stackinfo.assume_init().ss_sp)
assert_eq!(libc::pthread_stackseg_np(libc::pthread_self(), stackinfo.as_mut_ptr()), 0);
Some(stackinfo.assume_init().ss_sp as usize - stackinfo.assume_init().ss_size)
}
} else if #[cfg(target_os = "macos")] {
unsafe fn guess_os_stack_limit() -> Option<usize> {
Expand Down