diff --git a/src/lib.rs b/src/lib.rs index 4c51fac..f4bbb65 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -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") @@ -372,8 +385,8 @@ cfg_if! { } else if #[cfg(target_os = "openbsd")] { unsafe fn guess_os_stack_limit() -> Option { let mut stackinfo = std::mem::MaybeUninit::::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 {