Implement anonymous fmap
This commit is contained in:
@@ -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]> {
|
||||
|
||||
Reference in New Issue
Block a user