summaryrefslogtreecommitdiff
path: root/src/mem.rs
diff options
context:
space:
mode:
authorNathan Lee <me@nwlee.tech>2026-06-10 22:27:34 -0500
committerNathan Lee <me@nwlee.tech>2026-06-10 22:27:34 -0500
commit0f4993d181bb4dd09a8f2613dd82f267b355fe7e (patch)
treeb213a68dd99c73360133e7c3d8ded4b87ed3a6b0 /src/mem.rs
parentf94c087120bf2a241dda51d6311c565dd03b96be (diff)
chore: lint
Diffstat (limited to 'src/mem.rs')
-rw-r--r--src/mem.rs36
1 files changed, 26 insertions, 10 deletions
diff --git a/src/mem.rs b/src/mem.rs
index 297c54c..8d0e9dc 100644
--- a/src/mem.rs
+++ b/src/mem.rs
@@ -19,7 +19,7 @@ impl Memory {
virtual_addr: usize::MAX,
real_addr: i * PAGE_SIZE,
permission: 0,
- allocated: 0
+ allocated: 0,
}
}
Memory {
@@ -43,7 +43,10 @@ impl Memory {
pub fn lookup_page(&mut self, virtual_addr: usize, permission: usize) -> Option<usize> {
for (i, page) in self.pages.iter().enumerate() {
- if page.virtual_addr == virtual_addr && permission >= page.permission && page.allocated == 1 {
+ if page.virtual_addr == virtual_addr
+ && permission >= page.permission
+ && page.allocated == 1
+ {
return Some(i);
}
}
@@ -52,7 +55,10 @@ impl Memory {
pub fn ro_lookup(&self, virtual_addr: usize, permission: usize) -> Option<usize> {
for (i, page) in self.pages.iter().enumerate() {
- if page.virtual_addr == virtual_addr && page.permission == permission && page.allocated == 1 {
+ if page.virtual_addr == virtual_addr
+ && page.permission == permission
+ && page.allocated == 1
+ {
return Some(i);
}
}
@@ -81,10 +87,15 @@ impl Memory {
Err(())
}
}
-
- pub fn read_multiple_bytes(&self, address: usize, size: usize, permission: usize) -> Result<Box<[u8]>, ()> {
+
+ pub fn read_multiple_bytes(
+ &self,
+ address: usize,
+ size: usize,
+ permission: usize,
+ ) -> Result<Box<[u8]>, ()> {
let mut ret = [];
- for addr in address..address+size {
+ for addr in address..address + size {
if let Ok(byte) = self.read(addr, permission) {
ret[addr - address] = byte;
} else {
@@ -93,13 +104,18 @@ impl Memory {
}
Ok(Box::new(ret))
}
-
- pub fn write_multiple_bytes(&mut self, address: usize, bytes: &[u8], permission: usize) -> Result<(), ()> {
+
+ pub fn write_multiple_bytes(
+ &mut self,
+ address: usize,
+ bytes: &[u8],
+ permission: usize,
+ ) -> Result<(), ()> {
for addr in address..address + bytes.len() {
if let Err(_) = self.write(addr, permission, bytes[addr - address]) {
return Err(());
- }
+ }
}
Ok(())
}
-} \ No newline at end of file
+}