diff --git a/xous-rs/src/arch/hosted.rs b/xous-rs/src/arch/hosted.rs index b202794a0..f5ac45ff2 100644 --- a/xous-rs/src/arch/hosted.rs +++ b/xous-rs/src/arch/hosted.rs @@ -9,6 +9,9 @@ use std::thread_local; use crate::{Result, PID, TID}; +mod mem; +pub use mem::*; + #[derive(Copy, Clone, Debug, PartialEq)] pub struct ProcessKey([u8; 16]); impl ProcessKey { diff --git a/xous-rs/src/carton.rs b/xous-rs/src/carton.rs index c83ff6e17..d24b187eb 100644 --- a/xous-rs/src/carton.rs +++ b/xous-rs/src/carton.rs @@ -1,7 +1,5 @@ //! A Carton is an object that wraps another object for shipping across the kernel //! boundary. Structs that are stored in Cartons can be sent as messages. -// extern crate alloc; -// use alloc::alloc::{alloc, dealloc, Layout}; use crate::{Error, MemoryMessage, MemoryRange, Message, CID}; @@ -15,7 +13,6 @@ impl<'a> Carton<'a> { pub fn from_bytes(bytes: &[u8]) -> Self { let src_mem = bytes.as_ptr(); let size = bytes.len(); - // let layout = Layout::from_size_align(size, 4096).unwrap(); let new_mem = crate::map_memory( None, None, @@ -23,11 +20,9 @@ impl<'a> Carton<'a> { crate::MemoryFlags::R | crate::MemoryFlags::W, ) .unwrap(); - // unsafe { - // let new_mem = alloc(layout); - // core::ptr::copy(src_mem, new_mem, size); - // new_mem - // }; + unsafe { + core::ptr::copy(src_mem, new_mem.as_mut_ptr(), new_mem.len()); + }; Carton { range: new_mem, slice: unsafe { core::slice::from_raw_parts_mut(new_mem.as_mut_ptr(), new_mem.len()) }, @@ -81,8 +76,6 @@ impl<'a> AsRef<[u8]> for Carton<'a> { impl<'a> Drop for Carton<'a> { fn drop(&mut self) { - // let layout = Layout::from_size_align(self.range.len(), 4096).unwrap(); - // let ptr = self.range.as_mut_ptr(); - // unsafe { dealloc(ptr, layout) }; + crate::unmap_memory(self.range).unwrap(); } } diff --git a/xous-rs/src/syscall.rs b/xous-rs/src/syscall.rs index 5608e031a..0efa5d5ab 100644 --- a/xous-rs/src/syscall.rs +++ b/xous-rs/src/syscall.rs @@ -701,6 +701,7 @@ pub fn map_memory( size: usize, flags: MemoryFlags, ) -> core::result::Result { + crate::arch::map_memory_pre(&phys, &virt, size, flags)?; let result = rsyscall(SysCall::MapMemory( phys, virt, @@ -708,7 +709,7 @@ pub fn map_memory( flags, ))?; if let Result::MemoryRange(range) = result { - Ok(range) + Ok(crate::arch::map_memory_post(phys, virt, size, flags, range)?) } else if let Result::Error(e) = result { Err(e) } else { @@ -719,8 +720,10 @@ pub fn map_memory( /// Map the given physical address to the given virtual address. /// The `size` field must be page-aligned. pub fn unmap_memory(range: MemoryRange) -> core::result::Result<(), Error> { + crate::arch::unmap_memory_pre(&range)?; let result = rsyscall(SysCall::UnmapMemory(range))?; if let Result::Ok = result { + crate::arch::unmap_memory_post(range)?; Ok(()) } else if let Result::Error(e) = result { Err(e)