unix: clean up install_main_guard_freebsd · model-checking/verify-rust-std@4db3aa1 (original) (raw)

`@@ -44,6 +44,7 @@ mod imp {

`

44

44

`use crate::ops::Range;

`

45

45

`use crate::ptr;

`

46

46

`use crate::sync::atomic::{AtomicBool, AtomicPtr, AtomicUsize, Ordering};

`

``

47

`+

use crate::sync::OnceLock;

`

47

48

`use crate::sys::pal::unix::os;

`

48

49

`use crate::thread;

`

49

50

``

`@@ -370,6 +371,7 @@ mod imp {

`

370

371

`None

`

371

372

`}

`

372

373

``

``

374

`+

#[forbid(unsafe_op_in_unsafe_fn)]

`

373

375

`unsafe fn install_main_guard_freebsd(page_size: usize) -> Option<Range> {

`

374

376

`// FreeBSD's stack autogrows, and optionally includes a guard page

`

375

377

`// at the bottom. If we try to remap the bottom of the stack

`

`@@ -381,25 +383,22 @@ mod imp {

`

381

383

`// by the security.bsd.stack_guard_page sysctl.

`

382

384

`// By default it is 1, checking once is enough since it is

`

383

385

`// a boot time config value.

`

384

``

`-

static PAGES: crate::sync::OnceLock = crate::sync::OnceLock::new();

`

``

386

`+

static PAGES: OnceLock = OnceLock::new();

`

385

387

``

386

388

`let pages = PAGES.get_or_init(|| {

`

387

389

`use crate::sys::weak::dlsym;

`

388

390

`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);

`

389

391

`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";

`

395

394

`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

`+

  1. == 0

`

``

401

`+

} => guard,

`

403

402

` _ => 1,

`

404

403

`}

`

405

404

`});

`