about summary refs log tree commit diff
path: root/library/std/src/sys
diff options
context:
space:
mode:
authorJubilee Young <workingjubilee@gmail.com>2024-07-17 00:06:00 -0700
committerJubilee Young <workingjubilee@gmail.com>2024-07-17 00:06:27 -0700
commit6ed563d49144f38b1066716833baf505646b274c (patch)
tree9d5d29de066b9646feb887c7f4b5abded46b2fee /library/std/src/sys
parente285c95cee3b5aaa01d731df8a7096e028460eb9 (diff)
unix: clean up install_main_guard_freebsd
This just was a mess.
Diffstat (limited to 'library/std/src/sys')
-rw-r--r--library/std/src/sys/pal/unix/stack_overflow.rs25
1 files changed, 12 insertions, 13 deletions
diff --git a/library/std/src/sys/pal/unix/stack_overflow.rs b/library/std/src/sys/pal/unix/stack_overflow.rs
index 5916be54fe8..0e15049be9a 100644
--- a/library/std/src/sys/pal/unix/stack_overflow.rs
+++ b/library/std/src/sys/pal/unix/stack_overflow.rs
@@ -44,6 +44,7 @@ mod imp {
     use crate::ops::Range;
     use crate::ptr;
     use crate::sync::atomic::{AtomicBool, AtomicPtr, AtomicUsize, Ordering};
+    use crate::sync::OnceLock;
     use crate::sys::pal::unix::os;
     use crate::thread;
 
@@ -370,6 +371,7 @@ mod imp {
         None
     }
 
+    #[forbid(unsafe_op_in_unsafe_fn)]
     unsafe fn install_main_guard_freebsd(page_size: usize) -> Option<Range<usize>> {
         // FreeBSD's stack autogrows, and optionally includes a guard page
         // at the bottom. If we try to remap the bottom of the stack
@@ -381,25 +383,22 @@ mod imp {
         // by the security.bsd.stack_guard_page sysctl.
         // By default it is 1, checking once is enough since it is
         // a boot time config value.
-        static PAGES: crate::sync::OnceLock<usize> = crate::sync::OnceLock::new();
+        static PAGES: OnceLock<usize> = OnceLock::new();
 
         let pages = PAGES.get_or_init(|| {
             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 mut size = mem::size_of_val(&guard);
+            let oid = c"security.bsd.stack_guard_page";
             match sysctlbyname.get() {
-                Some(fcn) => {
-                    if fcn(oid.as_ptr(), core::ptr::addr_of_mut!(guard) as *mut _, core::ptr::addr_of_mut!(size) as *mut _, crate::ptr::null_mut(), 0) == 0 {
-                        guard
-                    } else {
-                        1
-                    }
-                },
+                Some(fcn) if unsafe {
+                    fcn(oid.as_ptr(),
+                        ptr::addr_of_mut!(guard).cast(),
+                        ptr::addr_of_mut!(size),
+                        ptr::null_mut(),
+                        0) == 0
+                } => guard,
                 _ => 1,
             }
         });