(ptr: *mut u8)
| 315 | } |
| 316 | |
| 317 | unsafe fn assert_faults(ptr: *mut u8) { |
| 318 | use std::io::Error; |
| 319 | #[cfg(unix)] |
| 320 | unsafe { |
| 321 | // There's probably a faster way to do this here, but, uh, when in rome? |
| 322 | match libc::fork() { |
| 323 | 0 => { |
| 324 | *ptr = 4; |
| 325 | |
| 326 | std::process::exit(0); |
| 327 | } |
| 328 | -1 => panic!("failed to fork: {}", Error::last_os_error()), |
| 329 | n => { |
| 330 | let mut status = 0; |
| 331 | assert!( |
| 332 | libc::waitpid(n, &mut status, 0) == n, |
| 333 | "failed to wait: {}", |
| 334 | Error::last_os_error() |
| 335 | ); |
| 336 | assert!(libc::WIFSIGNALED(status)); |
| 337 | } |
| 338 | } |
| 339 | } |
| 340 | #[cfg(windows)] |
| 341 | unsafe { |
| 342 | use windows_sys::Win32::System::Memory::*; |
| 343 | |
| 344 | let mut info = std::mem::MaybeUninit::uninit(); |
| 345 | let r = VirtualQuery( |
| 346 | ptr as *const _, |
| 347 | info.as_mut_ptr(), |
| 348 | std::mem::size_of_val(&info), |
| 349 | ); |
| 350 | if r == 0 { |
| 351 | panic!("failed to VirtualAlloc: {}", Error::last_os_error()); |
| 352 | } |
| 353 | let info = info.assume_init(); |
| 354 | assert_eq!(info.AllocationProtect, PAGE_NOACCESS); |
| 355 | } |
| 356 | } |
| 357 | |
| 358 | // Disable test on s390x because the large allocation may actually succeed; |
| 359 | // the whole 64-bit address space is available on this platform. |
no test coverage detected