Skip to content

Commit f6868af

Browse files
committed
trying another approach
1 parent d7f047a commit f6868af

File tree

1 file changed

+10
-19
lines changed

1 file changed

+10
-19
lines changed

Diff for: library/std/src/sys/pal/unix/thread.rs

+10-19
Original file line numberDiff line numberDiff line change
@@ -854,32 +854,23 @@ pub mod guard {
854854
let guard = guardaddr
855855
..guardaddr
856856
+ *LOCK.get_or_init(|| {
857-
extern "C" {
858-
pub fn sysctlbyname(
859-
oid: *const libc::c_char,
860-
ov: *mut libc::c_void,
861-
osize: *mut libc::size_t,
862-
nv: *const libc::c_void,
863-
nsize: libc::size_t,
864-
) -> libc::c_int;
865-
}
857+
use crate::sys::weak::dlsym;
858+
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);
866859
let mut guard: usize = 0;
867860
let mut size = crate::mem::size_of_val(&guard);
868861
let oid = crate::ffi::CStr::from_bytes_with_nul(
869862
b"security.bsd.stack_guard_page\0",
870863
)
871864
.unwrap();
872-
let res = sysctlbyname(
873-
oid.as_ptr(),
874-
&mut guard as *mut _ as *mut _,
875-
&mut size as *mut _ as *mut _,
876-
crate::ptr::null_mut(),
877-
0,
878-
);
879-
if res == 0 {
880-
return guard;
865+
match sysctlbyname.get() {
866+
Some(fcn) => {
867+
if fcn(oid.as_ptr(), &mut guard as *mut _ as *mut _, &mut size as *mut _ as *mut _, crate::ptr::null_mut(), 0) == 0 {
868+
return guard;
869+
}
870+
return 1;
871+
},
872+
_ => { return 1; }
881873
}
882-
1
883874
}) * page_size;
884875
Some(guard)
885876
} else if cfg!(target_os = "openbsd") {

0 commit comments

Comments
 (0)