write_minibsod for apple (#1425)

This commit is contained in:
David CARLIER 2023-08-15 19:16:07 +01:00 committed by GitHub
parent 5c05b3d32d
commit b5774b2275
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -732,14 +732,58 @@ fn write_minibsod<W: Write>(writer: &mut BufWriter<W>) -> Result<(), std::io::Er
Ok(()) Ok(())
} }
#[cfg(target_env = "apple")]
fn write_minibsod<W: Write>(writer: &mut BufWriter<W>) -> Result<(), std::io::Error> {
let ptask = std::mem::MaybeUninit::<libc::mach_task_t>::uninit();
// We start by the lowest virtual address from the userland' standpoint
let mut addr = libc::mach_vm_address_t = libc::MACH_VM_MIN_ADDRESS;
let mut cnt: libc::mach_msg_type_number_t = 0;
let mut sz: libc::mach_vm_size_t = 0;
let mut reg: libc::natural_t = 1;
let mut r =
unsafe { libc::task_for_pid(libc::mach_task_self(), libc::getpid(), ptask.as_mut_ptr()) };
if r != libc::KERN_SUCCESS {
return Err(std::io::Error::last_os_error());
}
let task = ptask.assume_init();
loop {
let pvminfo = std::mem::MaybeUninit::<libc::vm_regions_submap_info_64>::uninit();
cnt = libc::VM_REGION_SUBMAP_INFO_COUNT_64;
r = libc::mach_vm_region_recurse(
task,
&mut addr,
&mut sz,
&mut reg,
pvminfo.as_mut_ptr() as *mut libc::vm_region_recurse_info_t,
&cnt,
);
if r != libc::KERN_SUCCESS {
break;
}
let vminfo = pvminfo.assume_init();
// We are only interested by the first level of the maps
if !vminfo.is_submap {
let i = format!("{}-{}\n", addr, addr + sz);
writer.write(&i.into_bytes())?;
}
addr = addr + sz;
}
Ok(())
}
#[cfg(not(any( #[cfg(not(any(
target_os = "freebsd", target_os = "freebsd",
target_os = "openbsd", target_os = "openbsd",
target_env = "apple",
any(target_os = "linux", target_os = "android"), any(target_os = "linux", target_os = "android"),
)))] )))]
fn write_minibsod<W: Write>(writer: &mut BufWriter<W>) -> Result<(), std::io::Error> { fn write_minibsod<W: Write>(writer: &mut BufWriter<W>) -> Result<(), std::io::Error> {
// TODO for other platforms // TODO for other platforms
// Note that for apple, types might not be entirely mapped in libc due to mach crate.
writeln!(writer, "{:━^100}", " / ")?; writeln!(writer, "{:━^100}", " / ")?;
Ok(()) Ok(())
} }