Skip to content

Commit

Permalink
fix feature guard
Browse files Browse the repository at this point in the history
  • Loading branch information
lenawanel committed Sep 8, 2023
1 parent 3acb5de commit dce1178
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 11 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
/target
Cargo.lock
.lapce
18 changes: 7 additions & 11 deletions src/mmu.rs
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ impl MMU {

/// write a buffer to a virtual adress, checking if we have the given permissions
pub fn write_from_perms(&mut self, addr: Virtaddr, buf: &[u8], exp_perm: Perm) -> Result<()> {
#[cfg(raw_tracking)]
#[cfg(feature = "raw_tracking")]
let mut has_raw = false;

// check if we're not writing past the memory buffer
Expand All @@ -114,25 +114,21 @@ impl MMU {
// dbg!("checking permissions");
// check if we have the permission, paying extra attention to if we have RAW
// memory, to update the permissions later
#[cfg(raw_tracking)]
#[cfg(feature = "raw_tracking")]
if !self.permissions[addr.0..addr.0 + buf.len()]
.iter()
.all(|&x| {
has_raw |= (x & PERM_RAW).0 != 0;
(x & exp_perm).0 != 0
})
{
println!("expected permission: {:#b}", exp_perm.0);
println!("perm check failed");
return Err(AccessError::PermErr(addr, self.permissions[addr.0]));
}
#[cfg(not(raw_tracking))]
#[cfg(not(feature = "raw_tracking"))]
if !self.permissions[addr.0..addr.0 + buf.len()]
.iter()
.all(|&x| (x & exp_perm).0 != 0)
{
println!("expected permission: {:#b}", exp_perm.0);
println!("perm check failed");
return Err(AccessError::PermErr(addr, self.permissions[addr.0]));
}
// dbg!("after checking permissions");
Expand All @@ -141,7 +137,7 @@ impl MMU {
// dbg!("after writing memory");

// if the read after write flag is up, update the Permission of the memory
#[cfg(raw_tracking)]
#[cfg(feature = "raw_tracking")]
if has_raw {
self.permissions.iter_mut().for_each(|x| {
if (*x & PERM_RAW).0 != 0 {
Expand Down Expand Up @@ -252,14 +248,14 @@ impl MMU {
}

// Mark the memory as un-initialized and writable
#[cfg(raw_tracking)]
#[cfg(feature = "raw_tracking")]
if self
.set_permissions(base, align_size, PERM_RAW | PERM_WRITE)
.is_err()
{
return None;
}
#[cfg(not(raw_tracking))]
#[cfg(not(feature = "raw_tracking"))]
if self
.set_permissions(base, align_size, PERM_WRITE | PERM_READ)
.is_err()
Expand Down Expand Up @@ -480,7 +476,7 @@ pub const PERM_READ: Perm = Perm(1 << 2);
pub const PERM_WRITE: Perm = Perm(1 << 1);
/// permission to read a byte in memory after writing to it
/// this can be useful for detecting unintialized reads
#[cfg(raw_tracking)]
#[cfg(feature = "raw_tracking")]
pub const PERM_RAW: Perm = Perm(1 << 3);
/// permission to execute a byte in memory
pub const PERM_EXEC: Perm = Perm(1 << 0);
Expand Down

0 comments on commit dce1178

Please sign in to comment.