faster path for borrow-checking GuestPtr::{read, write}

This commit is contained in:
Pat Hickey
2020-05-18 19:12:55 -07:00
parent be1df80c1b
commit d221a3a346
2 changed files with 14 additions and 8 deletions

View File

@@ -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)]

View File

@@ -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(())
}
}