mem: get tests working again on hosted

This fixes all tests so they now work (and pass!) when running in a
hosted environment.

Signed-off-by: Sean Cross <sean@xobs.io>
This commit is contained in:
Sean Cross 2020-08-03 18:15:56 +08:00
parent 6ab4133165
commit 285b92401e
3 changed files with 38 additions and 16 deletions

View file

@ -19,7 +19,7 @@ impl MemoryMapping {
/// Get the currently active memory mapping. Note that the actual root pages
/// may be found at virtual address `PAGE_TABLE_ROOT_OFFSET`.
pub fn current() -> MemoryMapping {
unimplemented!()
MemoryMapping { pid: 0 }
}
/// Get the "PID" (actually, ASID) from the current mapping
@ -32,7 +32,7 @@ impl MemoryMapping {
/// kernel, which should be mapped into every possible address space.
/// As such, this will only have an observable effect once code returns
/// to userspace.
pub fn activate(self) -> Result<(), xous::Error>{
pub fn activate(self) -> Result<(), xous::Error> {
// This is a no-op on hosted environments
Ok(())
}
@ -43,13 +43,13 @@ impl MemoryMapping {
_addr: usize,
_flags: MemoryFlags,
) -> Result<(), Error> {
unimplemented!()
Ok(())
}
}
/// Determine whether a virtual address has been mapped
pub fn address_available(_virt: usize) -> bool {
unimplemented!()
true
}
pub fn map_page_inner(
@ -97,14 +97,14 @@ pub fn return_page_inner(
unimplemented!()
}
pub fn unmap_page_inner(_mm: &mut MemoryManager, _virt: usize) -> Result<usize, Error> {
unimplemented!()
pub fn unmap_page_inner(_mm: &mut MemoryManager, virt: usize) -> Result<usize, Error> {
Ok(virt)
}
pub fn hand_page_to_user(_virt: *mut usize) -> Result<(), Error> {
unimplemented!()
}
pub fn virt_to_phys(_virt: usize) -> Result<usize, Error> {
unimplemented!()
pub fn virt_to_phys(virt: usize) -> Result<usize, Error> {
Ok(virt)
}

View file

@ -84,6 +84,7 @@ impl<'a> MemoryManagerHandle<'a> {
MM_HANDLE_COUNT - 1
};
if count != 0 {
::debug_here::debug_here!();
panic!("Multiple users of MemoryManagerHandle!");
}
MemoryManagerHandle {
@ -529,6 +530,17 @@ impl MemoryManager {
/// Claim the given memory for the given process, or release the memory
/// back to the free pool.
#[cfg(not(baremetal))]
fn claim_or_release(
&mut self,
_addr: *mut usize,
_pid: PID,
_action: ClaimOrRelease,
) -> Result<(), xous::Error> {
Ok(())
}
#[cfg(baremetal)]
fn claim_or_release(
&mut self,
addr: *mut usize,

View file

@ -1,18 +1,23 @@
//! 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.
use crate::{Error, MemoryMessage, MemoryRange, Message, CID};
use crate::{Error, MemoryMessage, MemoryRange, MemorySize, Message, CID};
#[derive(Debug)]
pub struct Carton<'a> {
range: MemoryRange,
valid: MemoryRange,
slice: &'a [u8],
}
impl<'a> Carton<'a> {
pub fn from_bytes(bytes: &[u8]) -> Self {
let src_mem = bytes.as_ptr();
let size = bytes.len();
// Ensure our byte size is a multiple of 4096
let remainder = bytes.len() & 4095;
let size = bytes.len() + (4096 - remainder);
let new_mem = crate::map_memory(
None,
None,
@ -20,19 +25,24 @@ impl<'a> Carton<'a> {
crate::MemoryFlags::R | crate::MemoryFlags::W,
)
.unwrap();
// NOTE: Remaining bytes are not zeroed. We assume the kernel has done this for us.
unsafe {
core::ptr::copy(src_mem, new_mem.as_mut_ptr(), new_mem.len());
core::ptr::copy(src_mem, new_mem.as_mut_ptr(), bytes.len());
};
let mut valid = new_mem;
valid.size = MemorySize::new(bytes.len()).unwrap();
Carton {
range: new_mem,
slice: unsafe { core::slice::from_raw_parts_mut(new_mem.as_mut_ptr(), new_mem.len()) },
slice: unsafe { core::slice::from_raw_parts_mut(new_mem.as_mut_ptr(), bytes.len()) },
valid,
}
}
pub fn into_message(self, id: usize) -> MemoryMessage {
MemoryMessage {
id,
buf: self.range,
buf: self.valid,
offset: None,
valid: None,
}
@ -43,7 +53,7 @@ impl<'a> Carton<'a> {
pub fn lend(&self, connection: CID, id: usize) -> Result<(), Error> {
let msg = MemoryMessage {
id,
buf: self.range,
buf: self.valid,
offset: None,
valid: None,
};
@ -54,7 +64,7 @@ impl<'a> Carton<'a> {
pub fn lend_mut(&mut self, connection: CID, id: usize) -> Result<(), Error> {
let msg = MemoryMessage {
id,
buf: self.range,
buf: self.valid,
offset: None,
valid: None,
};
@ -64,7 +74,7 @@ impl<'a> Carton<'a> {
impl<'a> AsRef<MemoryRange> for Carton<'a> {
fn as_ref(&self) -> &MemoryRange {
&self.range
&self.valid
}
}