/// A simple wrapper struct to call munmap on `Drop`. struct Mapped<'a>(&'a [u8]);
impl<'a> Mapped<'_> { /// # Safety /// - `ptr` must be memory mmap-ed in this process and be readable for `sz` bytes while this struct is live. /// - It must be sound to unmap this memory when this struct is dropped. unsafefn new(ptr: *const c_void, sz: usize) -> Self { Self(unsafe { core::slice::from_raw_parts(ptr.cast(), sz) })
}
}
impl Drop for Mapped<'_> { fn drop(&mutself) { // SAFETY: This struct exists specifically to call munmap on mmap-ed memory. new is marked // unsafe to discourage improper construction of this struct and details that ptr must be // mapped in this process with the corresponding size. let res = unsafe { libc::munmap(self.0.as_ptr() as *mut _, self.0.len()) }; if res != 0 {
log::error!("munmap failed!");
}
}
}
pubfn get_vmm_obj(name: &CStr) -> Result<Vec<u8>, GetVmmObjFailure> { letmut ptr: *const c_void = std::ptr::null(); letmut sz: usize = 0; // SAFETY: // - `name.as_ptr()` points to as a valid, readable nul-terminated string as promised by CStr // - ptr and sz have been initialized to valid values // - references to name, ptr, and sz are not retained. let rc = unsafe { crate::sys::vmm_obj_map_ro(name.as_ptr().cast(), &mut ptr, &mut sz) }; if rc < 0 || ptr.is_null() { return Err(GetVmmObjFailure::NotFound);
} // SAFETY: On success, vmm_obj_map_ro sets ptr to point to static immutable memory readable for // sz bytes. let buffer = unsafe { Mapped::new(ptr, sz) }; let start = u32::from_ne_bytes(
buffer
.0
.get(..4)
.ok_or(GetVmmObjFailure::BadStart)?
.try_into()
.map_err(|_| GetVmmObjFailure::BadStart)?,
) as usize; let sz = u32::from_ne_bytes(
buffer
.0
.get(4..8)
.ok_or(GetVmmObjFailure::BadSize)?
.try_into()
.map_err(|_| GetVmmObjFailure::BadSize)?,
) as usize;
Ok(buffer.0.get(start..start + sz).ok_or(GetVmmObjFailure::BadSize)?.to_vec())
}
Messung V0.5 in Prozent
¤ Dauer der Verarbeitung: 0.10 Sekunden
(vorverarbeitet am 2026-06-27)
¤
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.