Skip to content

Commit d6e6d62

Browse files
committed
last ever fix
Signed-off-by: Simon Davies <simongdavies@users.noreply.github.com>
1 parent 0d0829d commit d6e6d62

File tree

1 file changed

+6
-7
lines changed
  • src/hyperlight_host/src/mem

1 file changed

+6
-7
lines changed

src/hyperlight_host/src/mem/mgr.rs

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -90,18 +90,17 @@ impl vmem::TableOps for GuestPageTableBuffer {
9090
unsafe fn read_entry(&self, addr: (usize, usize)) -> PageTableEntry {
9191
let b = self.buffer.borrow();
9292
let byte_offset = addr.0 * PAGE_TABLE_SIZE + addr.1 * 8;
93-
unsafe {
94-
let ptr = b.as_ptr().add(byte_offset) as *const PageTableEntry;
95-
ptr.read_unaligned()
96-
}
93+
b.get(byte_offset..byte_offset + 8)
94+
.and_then(|s| <[u8; 8]>::try_from(s).ok())
95+
.map(u64::from_ne_bytes)
96+
.unwrap_or(0)
9797
}
9898

9999
unsafe fn write_entry(&self, addr: (usize, usize), x: PageTableEntry) {
100100
let mut b = self.buffer.borrow_mut();
101101
let byte_offset = addr.0 * PAGE_TABLE_SIZE + addr.1 * 8;
102-
unsafe {
103-
let ptr = b.as_mut_ptr().add(byte_offset) as *mut PageTableEntry;
104-
ptr.write_unaligned(x);
102+
if let Some(slice) = b.get_mut(byte_offset..byte_offset + 8) {
103+
slice.copy_from_slice(&x.to_ne_bytes());
105104
}
106105
}
107106

0 commit comments

Comments
 (0)