Skip to content

Commit

Permalink
trying another approach
Browse files Browse the repository at this point in the history
  • Loading branch information
devnexen committed Feb 9, 2024
1 parent d7f047a commit f6868af
Showing 1 changed file with 10 additions and 19 deletions.
29 changes: 10 additions & 19 deletions library/std/src/sys/pal/unix/thread.rs
Original file line number Diff line number Diff line change
Expand Up @@ -854,32 +854,23 @@ pub mod guard {
let guard = guardaddr
..guardaddr
+ *LOCK.get_or_init(|| {
extern "C" {
pub fn sysctlbyname(
oid: *const libc::c_char,
ov: *mut libc::c_void,
osize: *mut libc::size_t,
nv: *const libc::c_void,
nsize: libc::size_t,
) -> libc::c_int;
}
use crate::sys::weak::dlsym;
dlsym!(fn sysctlbyname(*const libc::c_char, *mut libc::c_void, *mut libc::size_t, *const libc::c_void, libc::size_t) -> libc::c_int);
let mut guard: usize = 0;
let mut size = crate::mem::size_of_val(&guard);
let oid = crate::ffi::CStr::from_bytes_with_nul(
b"security.bsd.stack_guard_page\0",
)
.unwrap();
let res = sysctlbyname(
oid.as_ptr(),
&mut guard as *mut _ as *mut _,
&mut size as *mut _ as *mut _,
crate::ptr::null_mut(),
0,
);
if res == 0 {
return guard;
match sysctlbyname.get() {
Some(fcn) => {
if fcn(oid.as_ptr(), &mut guard as *mut _ as *mut _, &mut size as *mut _ as *mut _, crate::ptr::null_mut(), 0) == 0 {
return guard;
}
return 1;
},
_ => { return 1; }
}
1
}) * page_size;
Some(guard)
} else if cfg!(target_os = "openbsd") {
Expand Down

0 comments on commit f6868af

Please sign in to comment.