faster path for borrow-checking GuestPtr::{read, write}
This commit is contained in:
@@ -22,6 +22,9 @@ impl BorrowChecker {
|
||||
pub fn unborrow(&self, h: BorrowHandle) {
|
||||
self.bc.borrow_mut().unborrow(h)
|
||||
}
|
||||
pub fn is_borrowed(&self, r: Region) -> bool {
|
||||
self.bc.borrow().is_borrowed(r)
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Debug)]
|
||||
|
||||
@@ -81,13 +81,14 @@ macro_rules! primitives {
|
||||
Self::guest_align(),
|
||||
size,
|
||||
)?;
|
||||
let borrow_handle = ptr.borrow_checker().borrow( Region {
|
||||
let region = Region {
|
||||
start: offset,
|
||||
len: size,
|
||||
})?;
|
||||
let v = unsafe { *host_ptr.cast::<Self>() };
|
||||
ptr.borrow_checker().unborrow(borrow_handle);
|
||||
Ok(v)
|
||||
};
|
||||
if ptr.borrow_checker().is_borrowed(region) {
|
||||
return Err(GuestError::PtrBorrowed(region));
|
||||
}
|
||||
Ok(unsafe { *host_ptr.cast::<Self>() })
|
||||
}
|
||||
|
||||
#[inline]
|
||||
@@ -99,14 +100,16 @@ macro_rules! primitives {
|
||||
Self::guest_align(),
|
||||
size,
|
||||
)?;
|
||||
let borrow_handle = ptr.borrow_checker().borrow( Region {
|
||||
let region = Region {
|
||||
start: offset,
|
||||
len: size,
|
||||
})?;
|
||||
};
|
||||
if ptr.borrow_checker().is_borrowed(region) {
|
||||
return Err(GuestError::PtrBorrowed(region));
|
||||
}
|
||||
unsafe {
|
||||
*host_ptr.cast::<Self>() = val;
|
||||
}
|
||||
ptr.borrow_checker().unborrow(borrow_handle);
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user