mirror of
https://github.com/saymrwulf/xous-core.git
synced 2026-11-19 09:00:54 +00:00
kernel: implement move test
We can now `Move` memory from one "process" to another. Signed-off-by: Sean Cross <sean@xobs.io>
This commit is contained in:
parent
40ed6365e2
commit
05ccba9450
7 changed files with 39 additions and 36 deletions
|
|
@ -77,10 +77,10 @@ pub fn move_page_inner(
|
||||||
pub fn lend_page_inner(
|
pub fn lend_page_inner(
|
||||||
_mm: &mut MemoryManager,
|
_mm: &mut MemoryManager,
|
||||||
_src_space: &MemoryMapping,
|
_src_space: &MemoryMapping,
|
||||||
_src_addr: *mut usize,
|
_src_addr: *mut u8,
|
||||||
_dest_pid: PID,
|
_dest_pid: PID,
|
||||||
_dest_space: &MemoryMapping,
|
_dest_space: &MemoryMapping,
|
||||||
_dest_addr: *mut usize,
|
_dest_addr: *mut u8,
|
||||||
_mutable: bool,
|
_mutable: bool,
|
||||||
) -> Result<usize, Error> {
|
) -> Result<usize, Error> {
|
||||||
unimplemented!()
|
unimplemented!()
|
||||||
|
|
|
||||||
|
|
@ -91,14 +91,15 @@ fn handle_connection(mut conn: TcpStream, pid: PID, chn: Sender<ThreadMessage>)
|
||||||
})
|
})
|
||||||
.unwrap();
|
.unwrap();
|
||||||
// Update the address pointer. This will get turned back into a
|
// Update the address pointer. This will get turned back into a
|
||||||
// usable pointer by casting it back into a Box<[T]> on the other
|
// usable pointer by casting it back into a &[T] on the other
|
||||||
// side. This is a pointer to &[T], which itself contains len()
|
// side. This is just a pointer to the start of data
|
||||||
// as well as the index into the data it points at. The lengths
|
// as well as the index into the data it points at. The lengths
|
||||||
// should still be equal once we reconstitute the data in the
|
// should still be equal once we reconstitute the data in the
|
||||||
// other process.
|
// other process.
|
||||||
|
// ::debug_here::debug_here!();
|
||||||
let sliced_data = tmp_data.into_boxed_slice();
|
let sliced_data = tmp_data.into_boxed_slice();
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
(*sliced_data).len(),
|
sliced_data.len(),
|
||||||
msg.buf.len(),
|
msg.buf.len(),
|
||||||
"deconstructed data {} != message buf length {}",
|
"deconstructed data {} != message buf length {}",
|
||||||
sliced_data.len(),
|
sliced_data.len(),
|
||||||
|
|
|
||||||
|
|
@ -241,10 +241,10 @@ impl MemoryManager {
|
||||||
/// to fit `size` bytes.
|
/// to fit `size` bytes.
|
||||||
pub fn find_virtual_address(
|
pub fn find_virtual_address(
|
||||||
&mut self,
|
&mut self,
|
||||||
virt_ptr: *mut usize,
|
virt_ptr: *mut u8,
|
||||||
size: usize,
|
size: usize,
|
||||||
kind: xous::MemoryType,
|
kind: xous::MemoryType,
|
||||||
) -> Result<*mut usize, xous::Error> {
|
) -> Result<*mut u8, xous::Error> {
|
||||||
// If we were supplied a perfectly good address, return that.
|
// If we were supplied a perfectly good address, return that.
|
||||||
if virt_ptr as usize != 0 {
|
if virt_ptr as usize != 0 {
|
||||||
return Ok(virt_ptr);
|
return Ok(virt_ptr);
|
||||||
|
|
@ -260,7 +260,7 @@ impl MemoryManager {
|
||||||
if new_virt + size > process_inner.mem_heap_base + process_inner.mem_heap_max {
|
if new_virt + size > process_inner.mem_heap_base + process_inner.mem_heap_max {
|
||||||
return Err(xous::Error::OutOfMemory);
|
return Err(xous::Error::OutOfMemory);
|
||||||
}
|
}
|
||||||
return Ok(new_virt as *mut usize);
|
return Ok(new_virt as *mut u8);
|
||||||
}
|
}
|
||||||
xous::MemoryType::Default => (
|
xous::MemoryType::Default => (
|
||||||
process_inner.mem_default_base,
|
process_inner.mem_default_base,
|
||||||
|
|
@ -290,7 +290,7 @@ impl MemoryManager {
|
||||||
xous::MemoryType::Messages => process_inner.mem_message_last = potential_start,
|
xous::MemoryType::Messages => process_inner.mem_message_last = potential_start,
|
||||||
other => panic!("invalid kind: {:?}", other),
|
other => panic!("invalid kind: {:?}", other),
|
||||||
}
|
}
|
||||||
return Ok(potential_start as *mut usize);
|
return Ok(potential_start as *mut u8);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -309,7 +309,7 @@ impl MemoryManager {
|
||||||
xous::MemoryType::Messages => process_inner.mem_message_last = potential_start,
|
xous::MemoryType::Messages => process_inner.mem_message_last = potential_start,
|
||||||
other => panic!("invalid kind: {:?}", other),
|
other => panic!("invalid kind: {:?}", other),
|
||||||
}
|
}
|
||||||
return Ok(potential_start as *mut usize);
|
return Ok(potential_start as *mut u8);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Err(xous::Error::BadAddress)
|
Err(xous::Error::BadAddress)
|
||||||
|
|
@ -321,7 +321,7 @@ impl MemoryManager {
|
||||||
/// needing to actually have pages to back it.
|
/// needing to actually have pages to back it.
|
||||||
pub fn reserve_range(
|
pub fn reserve_range(
|
||||||
&mut self,
|
&mut self,
|
||||||
virt_ptr: *mut usize,
|
virt_ptr: *mut u8,
|
||||||
size: usize,
|
size: usize,
|
||||||
flags: MemoryFlags,
|
flags: MemoryFlags,
|
||||||
) -> Result<xous::MemoryRange, xous::Error> {
|
) -> Result<xous::MemoryRange, xous::Error> {
|
||||||
|
|
@ -350,7 +350,7 @@ impl MemoryManager {
|
||||||
#[allow(dead_code)]
|
#[allow(dead_code)]
|
||||||
pub fn map_zeroed_page(&mut self, pid: PID, is_user: bool) -> Result<*mut usize, xous::Error> {
|
pub fn map_zeroed_page(&mut self, pid: PID, is_user: bool) -> Result<*mut usize, xous::Error> {
|
||||||
let virt =
|
let virt =
|
||||||
self.find_virtual_address(0 as *mut usize, PAGE_SIZE, xous::MemoryType::Default)?
|
self.find_virtual_address(core::ptr::null_mut(), PAGE_SIZE, xous::MemoryType::Default)?
|
||||||
as usize;
|
as usize;
|
||||||
|
|
||||||
// Grab the next available page. This claims it for this process.
|
// Grab the next available page. This claims it for this process.
|
||||||
|
|
@ -383,7 +383,7 @@ impl MemoryManager {
|
||||||
Ok(virt)
|
Ok(virt)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn is_main_memory(&self, phys: *mut usize) -> bool {
|
pub fn is_main_memory(&self, phys: *mut u8) -> bool {
|
||||||
(phys as usize) >= self.ram_start && (phys as usize) < self.ram_start + self.ram_size
|
(phys as usize) >= self.ram_start && (phys as usize) < self.ram_start + self.ram_size
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -395,8 +395,8 @@ impl MemoryManager {
|
||||||
/// * MemoryInUse - The specified page is already mapped
|
/// * MemoryInUse - The specified page is already mapped
|
||||||
pub fn map_range(
|
pub fn map_range(
|
||||||
&mut self,
|
&mut self,
|
||||||
phys_ptr: *mut usize,
|
phys_ptr: *mut u8,
|
||||||
virt_ptr: *mut usize,
|
virt_ptr: *mut u8,
|
||||||
size: usize,
|
size: usize,
|
||||||
pid: PID,
|
pid: PID,
|
||||||
flags: MemoryFlags,
|
flags: MemoryFlags,
|
||||||
|
|
@ -482,10 +482,10 @@ impl MemoryManager {
|
||||||
pub fn lend_page(
|
pub fn lend_page(
|
||||||
&mut self,
|
&mut self,
|
||||||
src_mapping: &MemoryMapping,
|
src_mapping: &MemoryMapping,
|
||||||
src_addr: *mut usize,
|
src_addr: *mut u8,
|
||||||
dest_pid: PID,
|
dest_pid: PID,
|
||||||
dest_mapping: &MemoryMapping,
|
dest_mapping: &MemoryMapping,
|
||||||
dest_addr: *mut usize,
|
dest_addr: *mut u8,
|
||||||
mutable: bool,
|
mutable: bool,
|
||||||
) -> Result<usize, xous::Error> {
|
) -> Result<usize, xous::Error> {
|
||||||
// If this page is to be writable, detach it from this process.
|
// If this page is to be writable, detach it from this process.
|
||||||
|
|
|
||||||
|
|
@ -888,9 +888,9 @@ impl SystemServices {
|
||||||
#[cfg(baremetal)]
|
#[cfg(baremetal)]
|
||||||
pub fn send_memory(
|
pub fn send_memory(
|
||||||
&mut self,
|
&mut self,
|
||||||
src_virt: *mut usize,
|
src_virt: *mut u8,
|
||||||
dest_pid: PID,
|
dest_pid: PID,
|
||||||
dest_virt: *mut usize,
|
dest_virt: *mut u8,
|
||||||
len: usize,
|
len: usize,
|
||||||
) -> Result<*mut usize, xous::Error> {
|
) -> Result<*mut usize, xous::Error> {
|
||||||
if len == 0 {
|
if len == 0 {
|
||||||
|
|
@ -944,11 +944,11 @@ impl SystemServices {
|
||||||
#[cfg(not(baremetal))]
|
#[cfg(not(baremetal))]
|
||||||
pub fn send_memory(
|
pub fn send_memory(
|
||||||
&mut self,
|
&mut self,
|
||||||
src_virt: *mut usize,
|
src_virt: *mut u8,
|
||||||
_dest_pid: PID,
|
_dest_pid: PID,
|
||||||
_dest_virt: *mut usize,
|
_dest_virt: *mut u8,
|
||||||
_len: usize,
|
_len: usize,
|
||||||
) -> Result<*mut usize, xous::Error> {
|
) -> Result<*mut u8, xous::Error> {
|
||||||
Ok(src_virt)
|
Ok(src_virt)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -979,12 +979,12 @@ impl SystemServices {
|
||||||
/// * **BadAlignment**: The provided address or length was not page-aligned
|
/// * **BadAlignment**: The provided address or length was not page-aligned
|
||||||
pub fn lend_memory(
|
pub fn lend_memory(
|
||||||
&mut self,
|
&mut self,
|
||||||
src_virt: *mut usize,
|
src_virt: *mut u8,
|
||||||
dest_pid: PID,
|
dest_pid: PID,
|
||||||
dest_virt: *mut usize,
|
dest_virt: *mut u8,
|
||||||
len: usize,
|
len: usize,
|
||||||
mutable: bool,
|
mutable: bool,
|
||||||
) -> Result<*mut usize, xous::Error> {
|
) -> Result<*mut u8, xous::Error> {
|
||||||
if len == 0 {
|
if len == 0 {
|
||||||
return Err(xous::Error::BadAddress);
|
return Err(xous::Error::BadAddress);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -18,11 +18,11 @@ pub fn handle(pid: PID, call: SysCall) -> core::result::Result<xous::Result, xou
|
||||||
SysCall::MapMemory(phys, virt, size, req_flags) => {
|
SysCall::MapMemory(phys, virt, size, req_flags) => {
|
||||||
let mut mm = MemoryManagerHandle::get();
|
let mut mm = MemoryManagerHandle::get();
|
||||||
let phys_ptr = phys
|
let phys_ptr = phys
|
||||||
.map(|x| x.get() as *mut usize)
|
.map(|x| x.get() as *mut u8)
|
||||||
.unwrap_or(core::ptr::null_mut::<usize>());
|
.unwrap_or(core::ptr::null_mut());
|
||||||
let virt_ptr = virt
|
let virt_ptr = virt
|
||||||
.map(|x| x.get() as *mut usize)
|
.map(|x| x.get() as *mut u8)
|
||||||
.unwrap_or(core::ptr::null_mut::<usize>());
|
.unwrap_or(core::ptr::null_mut());
|
||||||
|
|
||||||
// Don't let the address exceed the user area (unless it's PID 1)
|
// Don't let the address exceed the user area (unless it's PID 1)
|
||||||
if pid.get() != 1
|
if pid.get() != 1
|
||||||
|
|
@ -107,7 +107,7 @@ pub fn handle(pid: PID, call: SysCall) -> core::result::Result<xous::Result, xou
|
||||||
|
|
||||||
let start = process_inner.mem_heap_base + process_inner.mem_heap_size;
|
let start = process_inner.mem_heap_base + process_inner.mem_heap_size;
|
||||||
process_inner.mem_heap_size += delta;
|
process_inner.mem_heap_size += delta;
|
||||||
Ok(start as *mut usize)
|
Ok(start as *mut u8)
|
||||||
})?
|
})?
|
||||||
};
|
};
|
||||||
let mut mm = MemoryManagerHandle::get();
|
let mut mm = MemoryManagerHandle::get();
|
||||||
|
|
@ -350,7 +350,7 @@ pub fn handle(pid: PID, call: SysCall) -> core::result::Result<xous::Result, xou
|
||||||
let new_virt = ss.send_memory(
|
let new_virt = ss.send_memory(
|
||||||
msg.buf.as_mut_ptr(),
|
msg.buf.as_mut_ptr(),
|
||||||
server_pid,
|
server_pid,
|
||||||
core::ptr::null_mut::<usize>(),
|
core::ptr::null_mut(),
|
||||||
msg.buf.len(),
|
msg.buf.len(),
|
||||||
)?;
|
)?;
|
||||||
(
|
(
|
||||||
|
|
@ -367,7 +367,7 @@ pub fn handle(pid: PID, call: SysCall) -> core::result::Result<xous::Result, xou
|
||||||
let new_virt = ss.lend_memory(
|
let new_virt = ss.lend_memory(
|
||||||
msg.buf.as_mut_ptr(),
|
msg.buf.as_mut_ptr(),
|
||||||
server_pid,
|
server_pid,
|
||||||
core::ptr::null_mut::<usize>(),
|
core::ptr::null_mut(),
|
||||||
msg.buf.len(),
|
msg.buf.len(),
|
||||||
true,
|
true,
|
||||||
)?;
|
)?;
|
||||||
|
|
@ -385,7 +385,7 @@ pub fn handle(pid: PID, call: SysCall) -> core::result::Result<xous::Result, xou
|
||||||
let new_virt = ss.lend_memory(
|
let new_virt = ss.lend_memory(
|
||||||
msg.buf.as_mut_ptr(),
|
msg.buf.as_mut_ptr(),
|
||||||
server_pid,
|
server_pid,
|
||||||
core::ptr::null_mut::<usize>(),
|
core::ptr::null_mut(),
|
||||||
msg.buf.len(),
|
msg.buf.len(),
|
||||||
false,
|
false,
|
||||||
)?;
|
)?;
|
||||||
|
|
|
||||||
|
|
@ -154,7 +154,9 @@ fn send_move_message() {
|
||||||
let message = envelope.message;
|
let message = envelope.message;
|
||||||
if let xous::Message::Move(m) = message {
|
if let xous::Message::Move(m) = message {
|
||||||
let buf = m.buf;
|
let buf = m.buf;
|
||||||
let bt = unsafe { core::slice::from_raw_parts(buf.as_ptr(), buf.len())};
|
// let bt = unsafe { Box::from_raw(buf.as_mut_ptr() as *mut [u8]) };
|
||||||
|
// let bt = unsafe { core::slice::from_raw_parts(buf.as_ptr(), buf.len())};
|
||||||
|
let bt = unsafe { Box::from_raw(core::slice::from_raw_parts_mut(buf.as_mut_ptr(), buf.len())) };
|
||||||
let s = String::from_utf8_lossy(&bt);
|
let s = String::from_utf8_lossy(&bt);
|
||||||
println!("Got message: {:?} -> \"{}\"", bt, s);
|
println!("Got message: {:?} -> \"{}\"", bt, s);
|
||||||
} else {
|
} else {
|
||||||
|
|
|
||||||
|
|
@ -316,8 +316,8 @@ impl MemoryRange {
|
||||||
self.addr.get() as *const u8
|
self.addr.get() as *const u8
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn as_mut_ptr(&self) -> *mut usize {
|
pub fn as_mut_ptr(&self) -> *mut u8 {
|
||||||
self.addr.get() as *mut usize
|
self.addr.get() as *mut u8
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue