Implement anonymous fmap

This commit is contained in:
Jeremy Soller
2021-09-22 21:04:04 -06:00
parent 17309754d6
commit 64f1533d6f
3 changed files with 40 additions and 21 deletions
+10
View File
@@ -31,6 +31,16 @@ fn validate(address: usize, size: usize, writable: bool) -> Result<()> {
Ok(())
}
/// Convert a pointer and length to reference, if valid
pub unsafe fn validate_ref<T>(ptr: *const T, size: usize) -> Result<&'static T> {
if size == mem::size_of::<T>() {
validate(ptr as usize, mem::size_of::<T>(), false)?;
Ok(unsafe { &*ptr })
} else {
Err(Error::new(EINVAL))
}
}
/// Convert a pointer and length to slice, if valid
//TODO: Mark unsafe
pub fn validate_slice<T>(ptr: *const T, len: usize) -> Result<&'static [T]> {