mirror of
https://github.com/saymrwulf/xous-core.git
synced 2026-11-18 08:52:45 +00:00
xous: mark MemoryRange fields as private
Mark the private fields in a `MemoryRange` struct as being private. This allows us to perform operations on the memory range armed with the knowledge that the entire range is valid and unaliased. Signed-off-by: Sean Cross <sean@xobs.io>
This commit is contained in:
parent
1fb7d4ebd5
commit
a99839ecd6
9 changed files with 34 additions and 37 deletions
|
|
@ -1041,8 +1041,8 @@ impl Server {
|
||||||
self.tail_generation,
|
self.tail_generation,
|
||||||
original_address.map(|x| x.get()).unwrap_or(0),
|
original_address.map(|x| x.get()).unwrap_or(0),
|
||||||
msg.id,
|
msg.id,
|
||||||
msg.buf.addr.get(),
|
msg.buf.as_ptr() as _,
|
||||||
msg.buf.size.get(),
|
msg.buf.len(),
|
||||||
msg.offset.map(|x| x.get()).unwrap_or(0) as usize,
|
msg.offset.map(|x| x.get()).unwrap_or(0) as usize,
|
||||||
msg.valid.map(|x| x.get()).unwrap_or(0) as usize,
|
msg.valid.map(|x| x.get()).unwrap_or(0) as usize,
|
||||||
),
|
),
|
||||||
|
|
@ -1052,8 +1052,8 @@ impl Server {
|
||||||
self.tail_generation,
|
self.tail_generation,
|
||||||
original_address.map(|x| x.get()).unwrap_or(0),
|
original_address.map(|x| x.get()).unwrap_or(0),
|
||||||
msg.id,
|
msg.id,
|
||||||
msg.buf.addr.get(),
|
msg.buf.as_ptr() as _,
|
||||||
msg.buf.size.get(),
|
msg.buf.len(),
|
||||||
msg.offset.map(|x| x.get()).unwrap_or(0) as usize,
|
msg.offset.map(|x| x.get()).unwrap_or(0) as usize,
|
||||||
msg.valid.map(|x| x.get()).unwrap_or(0) as usize,
|
msg.valid.map(|x| x.get()).unwrap_or(0) as usize,
|
||||||
),
|
),
|
||||||
|
|
@ -1063,8 +1063,8 @@ impl Server {
|
||||||
self.tail_generation,
|
self.tail_generation,
|
||||||
original_address.map(|x| x.get()).unwrap_or(0),
|
original_address.map(|x| x.get()).unwrap_or(0),
|
||||||
msg.id,
|
msg.id,
|
||||||
msg.buf.addr.get(),
|
msg.buf.as_ptr() as _,
|
||||||
msg.buf.size.get(),
|
msg.buf.len(),
|
||||||
msg.offset.map(|x| x.get()).unwrap_or(0) as usize,
|
msg.offset.map(|x| x.get()).unwrap_or(0) as usize,
|
||||||
msg.valid.map(|x| x.get()).unwrap_or(0) as usize,
|
msg.valid.map(|x| x.get()).unwrap_or(0) as usize,
|
||||||
),
|
),
|
||||||
|
|
@ -1118,8 +1118,8 @@ impl Server {
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
xous_kernel::Message::Move(msg) => {
|
xous_kernel::Message::Move(msg) => {
|
||||||
let server_address = msg.buf.addr.get();
|
let server_address = msg.buf.as_ptr() as _;
|
||||||
let len = msg.buf.size.get();
|
let len = msg.buf.len();
|
||||||
QueuedMessage::WaitingForget(
|
QueuedMessage::WaitingForget(
|
||||||
pid.get() as _,
|
pid.get() as _,
|
||||||
tid as _,
|
tid as _,
|
||||||
|
|
@ -1130,8 +1130,8 @@ impl Server {
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
xous_kernel::Message::MutableBorrow(msg) | xous_kernel::Message::Borrow(msg) => {
|
xous_kernel::Message::MutableBorrow(msg) | xous_kernel::Message::Borrow(msg) => {
|
||||||
let server_address = msg.buf.addr.get();
|
let server_address = msg.buf.as_ptr() as _;
|
||||||
let len = msg.buf.size.get();
|
let len = msg.buf.len();
|
||||||
QueuedMessage::WaitingReturnMemory(
|
QueuedMessage::WaitingReturnMemory(
|
||||||
pid.get() as _,
|
pid.get() as _,
|
||||||
tid as _,
|
tid as _,
|
||||||
|
|
|
||||||
|
|
@ -80,7 +80,7 @@ fn send_message(pid: PID, thread: TID, cid: CID, message: Message) -> SysCallRes
|
||||||
let client_address = match &message {
|
let client_address = match &message {
|
||||||
Message::Scalar(_) | Message::BlockingScalar(_) => None,
|
Message::Scalar(_) | Message::BlockingScalar(_) => None,
|
||||||
Message::Move(msg) | Message::MutableBorrow(msg) | Message::Borrow(msg) => {
|
Message::Move(msg) | Message::MutableBorrow(msg) | Message::Borrow(msg) => {
|
||||||
Some(msg.buf.addr)
|
MemoryAddress::new(msg.buf.as_ptr() as _)
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
@ -312,8 +312,8 @@ fn return_memory(
|
||||||
WaitingMessage::ForgetMemory(range) => {
|
WaitingMessage::ForgetMemory(range) => {
|
||||||
return MemoryManager::with_mut(|mm| {
|
return MemoryManager::with_mut(|mm| {
|
||||||
let mut result = Ok(xous_kernel::Result::Ok);
|
let mut result = Ok(xous_kernel::Result::Ok);
|
||||||
let virt = range.addr.get();
|
let virt = range.as_ptr() as usize;
|
||||||
let size = range.size.get();
|
let size = range.len();
|
||||||
if cfg!(baremetal) && virt & 0xfff != 0 {
|
if cfg!(baremetal) && virt & 0xfff != 0 {
|
||||||
klog!("VIRT NOT DIVISIBLE BY 4: {:08x}", virt);
|
klog!("VIRT NOT DIVISIBLE BY 4: {:08x}", virt);
|
||||||
return Err(xous_kernel::Error::BadAlignment);
|
return Err(xous_kernel::Error::BadAlignment);
|
||||||
|
|
@ -350,7 +350,7 @@ fn return_memory(
|
||||||
#[cfg(baremetal)]
|
#[cfg(baremetal)]
|
||||||
let src_virt = _server_addr.get() as _;
|
let src_virt = _server_addr.get() as _;
|
||||||
#[cfg(not(baremetal))]
|
#[cfg(not(baremetal))]
|
||||||
let src_virt = buf.addr.get() as _;
|
let src_virt = buf.as_ptr() as _;
|
||||||
|
|
||||||
// Return the memory to the calling process
|
// Return the memory to the calling process
|
||||||
ss.return_memory(
|
ss.return_memory(
|
||||||
|
|
@ -662,18 +662,18 @@ pub fn handle_inner(pid: PID, tid: TID, in_irq: bool, call: SysCall) -> SysCallR
|
||||||
if mm.is_main_memory(phys_ptr) {
|
if mm.is_main_memory(phys_ptr) {
|
||||||
println!(
|
println!(
|
||||||
"Going to zero out {} bytes @ {:08x}",
|
"Going to zero out {} bytes @ {:08x}",
|
||||||
range.size.get(),
|
range.len(),
|
||||||
range.addr.get()
|
range.as_ptr() as usize,
|
||||||
);
|
);
|
||||||
unsafe {
|
unsafe {
|
||||||
range
|
range
|
||||||
.as_mut_ptr()
|
.as_mut_ptr()
|
||||||
.write_bytes(0, range.size.get() / mem::size_of::<usize>())
|
.write_bytes(0, range.len() / mem::size_of::<usize>())
|
||||||
};
|
};
|
||||||
// println!("Done zeroing out");
|
// println!("Done zeroing out");
|
||||||
}
|
}
|
||||||
for offset in
|
for offset in
|
||||||
(range.addr.get()..(range.addr.get() + range.size.get())).step_by(PAGE_SIZE)
|
(range.as_ptr() as usize..(range.as_ptr() as usize + range.len())).step_by(PAGE_SIZE)
|
||||||
{
|
{
|
||||||
// println!("Handing page to user");
|
// println!("Handing page to user");
|
||||||
crate::arch::mem::hand_page_to_user(offset as *mut u8)
|
crate::arch::mem::hand_page_to_user(offset as *mut u8)
|
||||||
|
|
|
||||||
|
|
@ -40,14 +40,14 @@ fn map_fonts() {
|
||||||
fontlen as usize,
|
fontlen as usize,
|
||||||
xous::MemoryFlags::R,
|
xous::MemoryFlags::R,
|
||||||
).expect("couldn't map fonts");
|
).expect("couldn't map fonts");
|
||||||
log::info!("font base at virtual 0x{:08x}, len of 0x{:08x}", usize::from(fontregion.addr), usize::from(fontregion.size));
|
log::info!("font base at virtual 0x{:08x}, len of 0x{:08x}", fontregion.as_ptr() as usize, usize::from(fontregion.len()));
|
||||||
|
|
||||||
log::trace!("mapping regular font to 0x{:08x}", usize::from(fontregion.addr) + fontmap::REGULAR_OFFSET as usize);
|
log::trace!("mapping regular font to 0x{:08x}", fontregion.as_ptr() as usize + fontmap::REGULAR_OFFSET as usize);
|
||||||
blitstr::map_font(blitstr::GlyphData::Emoji((usize::from(fontregion.addr) + fontmap::EMOJI_OFFSET) as usize));
|
blitstr::map_font(blitstr::GlyphData::Emoji((fontregion.as_ptr() as usize + fontmap::EMOJI_OFFSET) as usize));
|
||||||
blitstr::map_font(blitstr::GlyphData::Hanzi((usize::from(fontregion.addr) + fontmap::HANZI_OFFSET) as usize));
|
blitstr::map_font(blitstr::GlyphData::Hanzi((fontregion.as_ptr() as usize + fontmap::HANZI_OFFSET) as usize));
|
||||||
blitstr::map_font(blitstr::GlyphData::Regular((usize::from(fontregion.addr) + fontmap::REGULAR_OFFSET) as usize));
|
blitstr::map_font(blitstr::GlyphData::Regular((fontregion.as_ptr() as usize + fontmap::REGULAR_OFFSET) as usize));
|
||||||
blitstr::map_font(blitstr::GlyphData::Small((usize::from(fontregion.addr) + fontmap::SMALL_OFFSET) as usize));
|
blitstr::map_font(blitstr::GlyphData::Small((fontregion.as_ptr() as usize + fontmap::SMALL_OFFSET) as usize));
|
||||||
blitstr::map_font(blitstr::GlyphData::Bold((usize::from(fontregion.addr) + fontmap::BOLD_OFFSET) as usize));
|
blitstr::map_font(blitstr::GlyphData::Bold((fontregion.as_ptr() as usize + fontmap::BOLD_OFFSET) as usize));
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(not(target_os = "none"))]
|
#[cfg(not(target_os = "none"))]
|
||||||
|
|
|
||||||
|
|
@ -56,7 +56,7 @@ impl Uart {
|
||||||
unsafe {
|
unsafe {
|
||||||
DEFAULT_UART_ADDR = uart.as_mut_ptr() as _;
|
DEFAULT_UART_ADDR = uart.as_mut_ptr() as _;
|
||||||
}
|
}
|
||||||
println!("Mapped UART @ {:08x}", uart.addr.get());
|
println!("Mapped UART @ {:08x}", uart.as_ptr() as usize);
|
||||||
// core::mem::forget(uart);
|
// core::mem::forget(uart);
|
||||||
|
|
||||||
println!("Allocating IRQ...");
|
println!("Allocating IRQ...");
|
||||||
|
|
|
||||||
|
|
@ -128,7 +128,7 @@ mod implementation {
|
||||||
)
|
)
|
||||||
.expect("couldn't map serial port");
|
.expect("couldn't map serial port");
|
||||||
unsafe { crate::debug::DEFAULT_UART_ADDR = uart.as_mut_ptr() as _ };
|
unsafe { crate::debug::DEFAULT_UART_ADDR = uart.as_mut_ptr() as _ };
|
||||||
println!("Mapped UART @ {:08x}", uart.addr.get());
|
println!("Mapped UART @ {:08x}", uart.as_ptr() as usize);
|
||||||
|
|
||||||
println!("Process: map success!");
|
println!("Process: map success!");
|
||||||
crate::debug::DEFAULT.enable_rx();
|
crate::debug::DEFAULT.enable_rx();
|
||||||
|
|
|
||||||
|
|
@ -45,8 +45,8 @@ impl<'a> Buffer<'a> {
|
||||||
)
|
)
|
||||||
.expect("Buffer: error in new()/map_memory");
|
.expect("Buffer: error in new()/map_memory");
|
||||||
|
|
||||||
let mut valid = new_mem;
|
let valid =
|
||||||
valid.size = MemorySize::new(len + remainder).unwrap();
|
unsafe { MemoryRange::new(new_mem.as_mut_ptr() as usize, len + remainder).unwrap() };
|
||||||
Buffer {
|
Buffer {
|
||||||
range: new_mem,
|
range: new_mem,
|
||||||
slice: unsafe {
|
slice: unsafe {
|
||||||
|
|
|
||||||
|
|
@ -1,7 +1,7 @@
|
||||||
//! A Carton is an object that wraps another object for shipping across the kernel
|
//! 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.
|
//! boundary. Structs that are stored in Cartons can be sent as messages.
|
||||||
|
|
||||||
use crate::{Error, MemoryMessage, MemoryRange, MemorySize, Message, CID};
|
use crate::{Error, MemoryMessage, MemoryRange, Message, CID};
|
||||||
|
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
pub struct Carton<'a> {
|
pub struct Carton<'a> {
|
||||||
|
|
@ -30,8 +30,8 @@ impl<'a> Carton<'a> {
|
||||||
unsafe {
|
unsafe {
|
||||||
core::ptr::copy(src_mem, new_mem.as_mut_ptr(), bytes.len());
|
core::ptr::copy(src_mem, new_mem.as_mut_ptr(), bytes.len());
|
||||||
};
|
};
|
||||||
let mut valid = new_mem;
|
let valid =
|
||||||
valid.size = MemorySize::new(bytes.len()).unwrap();
|
unsafe { MemoryRange::new(new_mem.as_mut_ptr() as usize, bytes.len()).unwrap() };
|
||||||
Carton {
|
Carton {
|
||||||
range: new_mem,
|
range: new_mem,
|
||||||
slice: unsafe { core::slice::from_raw_parts_mut(new_mem.as_mut_ptr(), bytes.len()) },
|
slice: unsafe { core::slice::from_raw_parts_mut(new_mem.as_mut_ptr(), bytes.len()) },
|
||||||
|
|
|
||||||
|
|
@ -124,8 +124,8 @@ pub type CpuID = usize;
|
||||||
|
|
||||||
#[derive(Debug, PartialEq, Copy, Clone)]
|
#[derive(Debug, PartialEq, Copy, Clone)]
|
||||||
pub struct MemoryRange {
|
pub struct MemoryRange {
|
||||||
pub addr: MemoryAddress,
|
addr: MemoryAddress,
|
||||||
pub size: MemorySize,
|
size: MemorySize,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(feature = "bitflags")]
|
#[cfg(feature = "bitflags")]
|
||||||
|
|
|
||||||
|
|
@ -59,9 +59,6 @@ impl<'a> StringBuffer<'a> {
|
||||||
)
|
)
|
||||||
.expect("Buffer: error in new()/map_memory");
|
.expect("Buffer: error in new()/map_memory");
|
||||||
|
|
||||||
let mut valid = new_mem;
|
|
||||||
valid.size = MemorySize::new(capacity + remainder).unwrap();
|
|
||||||
|
|
||||||
StringBuffer {
|
StringBuffer {
|
||||||
bytes: Some(unsafe {
|
bytes: Some(unsafe {
|
||||||
core::slice::from_raw_parts_mut(new_mem.as_mut_ptr(), capacity + remainder)
|
core::slice::from_raw_parts_mut(new_mem.as_mut_ptr(), capacity + remainder)
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue