mirror of
https://github.com/saymrwulf/xous-core.git
synced 2026-11-18 08:52:45 +00:00
mem: start implementing find_virtual_address()
Right now it just returns the address, which is exactly what we had before. Signed-off-by: Sean Cross <sean@xobs.io>
This commit is contained in:
parent
c1b575507d
commit
87676c0fc5
1 changed files with 18 additions and 3 deletions
|
|
@ -232,6 +232,18 @@ impl MemoryManager {
|
||||||
Err(xous::Error::OutOfMemory)
|
Err(xous::Error::OutOfMemory)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Find a virtual address in the current process that is big enough
|
||||||
|
// to fit `size` bytes.
|
||||||
|
fn find_virtual_address(&mut self, virt_ptr: *mut usize, size: usize) -> Result<usize, xous::Error> {
|
||||||
|
// If we were supplied a perfectly good address, return that.
|
||||||
|
if virt_ptr as usize != 0 {
|
||||||
|
return Ok(virt_ptr as usize);
|
||||||
|
}
|
||||||
|
|
||||||
|
// let mm = SystemServicesHandle::get().current_process();
|
||||||
|
Err(xous::Error::BadAddress)
|
||||||
|
}
|
||||||
|
|
||||||
/// Reserve the given range without actually allocating memory.
|
/// Reserve the given range without actually allocating memory.
|
||||||
/// That way we can overpromise on stack size and heap size without
|
/// That way we can overpromise on stack size and heap size without
|
||||||
/// needing to actually have pages to back it.
|
/// needing to actually have pages to back it.
|
||||||
|
|
@ -241,7 +253,10 @@ impl MemoryManager {
|
||||||
size: usize,
|
size: usize,
|
||||||
flags: MemoryFlags,
|
flags: MemoryFlags,
|
||||||
) -> Result<xous::Result, xous::Error> {
|
) -> Result<xous::Result, xous::Error> {
|
||||||
let virt = virt_ptr as usize;
|
|
||||||
|
// If no address was specified, pick the next address that fits
|
||||||
|
// in the "default" range
|
||||||
|
let virt = self.find_virtual_address(virt_ptr, size)?;
|
||||||
|
|
||||||
if virt & 0xfff != 0 {
|
if virt & 0xfff != 0 {
|
||||||
return Err(xous::Error::BadAlignment);
|
return Err(xous::Error::BadAlignment);
|
||||||
|
|
@ -275,11 +290,11 @@ impl MemoryManager {
|
||||||
let ss = SystemServicesHandle::get();
|
let ss = SystemServicesHandle::get();
|
||||||
let pid = ss.current_pid();
|
let pid = ss.current_pid();
|
||||||
let phys = phys_ptr as usize;
|
let phys = phys_ptr as usize;
|
||||||
let virt = virt_ptr as usize;
|
let virt = self.find_virtual_address(virt_ptr, size)?;
|
||||||
|
|
||||||
// If no physical address is specified, give the user the next available pages
|
// If no physical address is specified, give the user the next available pages
|
||||||
if phys == 0 {
|
if phys == 0 {
|
||||||
return self.reserve_range(virt_ptr, size, flags);
|
return self.reserve_range(virt as *mut usize, size, flags);
|
||||||
}
|
}
|
||||||
|
|
||||||
// 1. Attempt to claim all physical pages in the range
|
// 1. Attempt to claim all physical pages in the range
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue