@@ -44,6 +44,7 @@ mod imp {
4444 use crate :: ops:: Range ;
4545 use crate :: ptr;
4646 use crate :: sync:: atomic:: { AtomicBool , AtomicPtr , AtomicUsize , Ordering } ;
47+ use crate :: sync:: OnceLock ;
4748 use crate :: sys:: pal:: unix:: os;
4849 use crate :: thread;
4950
@@ -370,6 +371,7 @@ mod imp {
370371 None
371372 }
372373
374+ #[ forbid( unsafe_op_in_unsafe_fn) ]
373375 unsafe fn install_main_guard_freebsd ( page_size : usize ) -> Option < Range < usize > > {
374376 // FreeBSD's stack autogrows, and optionally includes a guard page
375377 // at the bottom. If we try to remap the bottom of the stack
@@ -381,25 +383,22 @@ mod imp {
381383 // by the security.bsd.stack_guard_page sysctl.
382384 // By default it is 1, checking once is enough since it is
383385 // a boot time config value.
384- static PAGES : crate :: sync :: OnceLock < usize > = crate :: sync :: OnceLock :: new ( ) ;
386+ static PAGES : OnceLock < usize > = OnceLock :: new ( ) ;
385387
386388 let pages = PAGES . get_or_init ( || {
387389 use crate :: sys:: weak:: dlsym;
388390 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) ;
389391 let mut guard: usize = 0 ;
390- let mut size = crate :: mem:: size_of_val ( & guard) ;
391- let oid = crate :: ffi:: CStr :: from_bytes_with_nul (
392- b"security.bsd.stack_guard_page\0 " ,
393- )
394- . unwrap ( ) ;
392+ let mut size = mem:: size_of_val ( & guard) ;
393+ let oid = c"security.bsd.stack_guard_page" ;
395394 match sysctlbyname. get ( ) {
396- Some ( fcn) => {
397- 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 {
398- guard
399- } else {
400- 1
401- }
402- } ,
395+ Some ( fcn) if unsafe {
396+ fcn ( oid. as_ptr ( ) ,
397+ ptr :: addr_of_mut! ( guard) . cast ( ) ,
398+ ptr :: addr_of_mut! ( size ) ,
399+ ptr :: null_mut ( ) ,
400+ 0 ) == 0
401+ } => guard ,
403402 _ => 1 ,
404403 }
405404 } ) ;
0 commit comments