mirror of
https://github.com/saymrwulf/xous-core.git
synced 2026-11-19 09:00:54 +00:00
format xous-rs
This commit is contained in:
parent
34da894173
commit
1917c07a35
29 changed files with 369 additions and 1138 deletions
|
|
@ -1,6 +1,7 @@
|
||||||
/// These are Xous-specific IRQ numbers that doesn't directly correspond to the chip's IRQ numbers.
|
/// These are Xous-specific IRQ numbers that doesn't directly correspond to the chip's IRQ numbers.
|
||||||
/// In fact, there are 70+ interrupt sources in ATSAMA5D27 that won't fit in the 32 bit map used in Xous.
|
/// In fact, there are 70+ interrupt sources in ATSAMA5D27 that won't fit in the 32 bit map used in Xous.
|
||||||
/// The current solution is to pick a subset of 32 interrupts that are most likely to be used by Xous and specify them here.
|
/// The current solution is to pick a subset of 32 interrupts that are most likely to be used by Xous and
|
||||||
|
/// specify them here.
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
pub enum IrqNumber {
|
pub enum IrqNumber {
|
||||||
PeriodicIntervalTimer = 0,
|
PeriodicIntervalTimer = 0,
|
||||||
|
|
@ -11,19 +12,19 @@ pub enum IrqNumber {
|
||||||
Uart3 = 4,
|
Uart3 = 4,
|
||||||
Uart4 = 5,
|
Uart4 = 5,
|
||||||
|
|
||||||
Pioa = 6,
|
Pioa = 6,
|
||||||
Piob = 7,
|
Piob = 7,
|
||||||
Pioc = 8,
|
Pioc = 8,
|
||||||
Piod = 9,
|
Piod = 9,
|
||||||
|
|
||||||
Isi = 10,
|
Isi = 10,
|
||||||
Lcdc = 11,
|
Lcdc = 11,
|
||||||
|
|
||||||
Uhphs = 12,
|
Uhphs = 12,
|
||||||
Udphs = 13,
|
Udphs = 13,
|
||||||
|
|
||||||
Tc0 = 14,
|
Tc0 = 14,
|
||||||
Tc1 = 15,
|
Tc1 = 15,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl TryFrom<usize> for IrqNumber {
|
impl TryFrom<usize> for IrqNumber {
|
||||||
|
|
@ -54,7 +55,7 @@ impl TryFrom<usize> for IrqNumber {
|
||||||
14 => Ok(Tc0),
|
14 => Ok(Tc0),
|
||||||
15 => Ok(Tc1),
|
15 => Ok(Tc1),
|
||||||
|
|
||||||
_ => Err(())
|
_ => Err(()),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -15,13 +15,9 @@ pub struct ProcessHandle {
|
||||||
pub cid: crate::CID,
|
pub cid: crate::CID,
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn wait_thread<T>(_joiner: WaitHandle<T>) -> crate::SysCallResult {
|
pub fn wait_thread<T>(_joiner: WaitHandle<T>) -> crate::SysCallResult { todo!() }
|
||||||
todo!()
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn create_process_pre(_args: &ProcessArgs) -> core::result::Result<ProcessInit, crate::Error> {
|
pub fn create_process_pre(_args: &ProcessArgs) -> core::result::Result<ProcessInit, crate::Error> { todo!() }
|
||||||
todo!()
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn create_process_post(
|
pub fn create_process_post(
|
||||||
_args: ProcessArgs,
|
_args: ProcessArgs,
|
||||||
|
|
@ -50,10 +46,7 @@ where
|
||||||
todo!()
|
todo!()
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn create_thread_post<F, T>(
|
pub fn create_thread_post<F, T>(_f: F, _thread_id: TID) -> core::result::Result<WaitHandle<T>, crate::Error>
|
||||||
_f: F,
|
|
||||||
_thread_id: TID,
|
|
||||||
) -> core::result::Result<WaitHandle<T>, crate::Error>
|
|
||||||
where
|
where
|
||||||
F: FnOnce() -> T,
|
F: FnOnce() -> T,
|
||||||
F: Send + 'static,
|
F: Send + 'static,
|
||||||
|
|
@ -193,13 +186,7 @@ where
|
||||||
T: Send + 'static,
|
T: Send + 'static,
|
||||||
U: Send + 'static,
|
U: Send + 'static,
|
||||||
{
|
{
|
||||||
create_thread_n_pre(
|
create_thread_n_pre(*f as usize, unsafe { core::mem::transmute(arg) }, &0, &0, &0)
|
||||||
*f as usize,
|
|
||||||
unsafe { core::mem::transmute(arg) },
|
|
||||||
&0,
|
|
||||||
&0,
|
|
||||||
&0,
|
|
||||||
)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn create_thread_simple_post<T, U>(
|
pub fn create_thread_simple_post<T, U>(
|
||||||
|
|
@ -250,10 +237,7 @@ pub fn create_thread_n_post<U>(
|
||||||
where
|
where
|
||||||
U: Send + 'static,
|
U: Send + 'static,
|
||||||
{
|
{
|
||||||
Ok(WaitHandle {
|
Ok(WaitHandle { tid: thread_id, data: core::marker::PhantomData })
|
||||||
tid: thread_id,
|
|
||||||
data: core::marker::PhantomData,
|
|
||||||
})
|
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn map_memory_pre(
|
pub fn map_memory_pre(
|
||||||
|
|
@ -275,13 +259,9 @@ pub fn map_memory_post(
|
||||||
Ok(range)
|
Ok(range)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn unmap_memory_pre(_range: &MemoryRange) -> core::result::Result<(), crate::Error> {
|
pub fn unmap_memory_pre(_range: &MemoryRange) -> core::result::Result<(), crate::Error> { Ok(()) }
|
||||||
Ok(())
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn unmap_memory_post(_range: MemoryRange) -> core::result::Result<(), crate::Error> {
|
pub fn unmap_memory_post(_range: MemoryRange) -> core::result::Result<(), crate::Error> { Ok(()) }
|
||||||
Ok(())
|
|
||||||
}
|
|
||||||
|
|
||||||
#[derive(Debug, Clone, Copy, PartialEq)]
|
#[derive(Debug, Clone, Copy, PartialEq)]
|
||||||
pub struct ThreadInit {
|
pub struct ThreadInit {
|
||||||
|
|
@ -295,22 +275,8 @@ pub struct ThreadInit {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl ThreadInit {
|
impl ThreadInit {
|
||||||
pub fn new(
|
pub fn new(call: usize, stack: MemoryRange, arg1: usize, arg2: usize, arg3: usize, arg4: usize) -> Self {
|
||||||
call: usize,
|
ThreadInit { call, stack, arg1, arg2, arg3, arg4 }
|
||||||
stack: MemoryRange,
|
|
||||||
arg1: usize,
|
|
||||||
arg2: usize,
|
|
||||||
arg3: usize,
|
|
||||||
arg4: usize,
|
|
||||||
) -> Self {
|
|
||||||
ThreadInit {
|
|
||||||
call,
|
|
||||||
stack,
|
|
||||||
arg1,
|
|
||||||
arg2,
|
|
||||||
arg3,
|
|
||||||
arg4,
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -4,33 +4,24 @@ pub struct ProcessArgs;
|
||||||
pub struct ProcessInit;
|
pub struct ProcessInit;
|
||||||
impl TryFrom<[usize; 7]> for ProcessInit {
|
impl TryFrom<[usize; 7]> for ProcessInit {
|
||||||
type Error = crate::Error;
|
type Error = crate::Error;
|
||||||
fn try_from(_src: [usize; 7]) -> Result<ProcessInit, Self::Error> {
|
|
||||||
todo!()
|
fn try_from(_src: [usize; 7]) -> Result<ProcessInit, Self::Error> { todo!() }
|
||||||
}
|
|
||||||
}
|
}
|
||||||
impl Into<[usize; 7]> for &ProcessInit {
|
impl Into<[usize; 7]> for &ProcessInit {
|
||||||
fn into(self) -> [usize; 7] {
|
fn into(self) -> [usize; 7] { todo!() }
|
||||||
todo!()
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
#[derive(Debug, PartialEq, Eq)]
|
#[derive(Debug, PartialEq, Eq)]
|
||||||
pub struct ProcessStartup;
|
pub struct ProcessStartup;
|
||||||
impl From<&[usize; 7]> for ProcessStartup {
|
impl From<&[usize; 7]> for ProcessStartup {
|
||||||
fn from(_src: &[usize; 7]) -> ProcessStartup {
|
fn from(_src: &[usize; 7]) -> ProcessStartup { todo!() }
|
||||||
todo!()
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
impl From<[usize; 8]> for ProcessStartup {
|
impl From<[usize; 8]> for ProcessStartup {
|
||||||
fn from(_src: [usize; 8]) -> ProcessStartup {
|
fn from(_src: [usize; 8]) -> ProcessStartup { todo!() }
|
||||||
todo!()
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Into<[usize; 7]> for &ProcessStartup {
|
impl Into<[usize; 7]> for &ProcessStartup {
|
||||||
fn into(self) -> [usize; 7] {
|
fn into(self) -> [usize; 7] { todo!() }
|
||||||
todo!()
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
#[derive(Debug, PartialEq, Eq)]
|
#[derive(Debug, PartialEq, Eq)]
|
||||||
pub struct ProcessKey;
|
pub struct ProcessKey;
|
||||||
|
|
|
||||||
|
|
@ -36,19 +36,13 @@ impl Arguments {
|
||||||
}
|
}
|
||||||
|
|
||||||
fn as_result(&self) -> crate::Result {
|
fn as_result(&self) -> crate::Result {
|
||||||
crate::Result::from_args([
|
crate::Result::from_args([self.a0, self.a1, self.a2, self.a3, self.a4, self.a5, self.a6, self.a7])
|
||||||
self.a0, self.a1, self.a2, self.a3, self.a4, self.a5, self.a6, self.a7,
|
|
||||||
])
|
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn set_result(&mut self, res: &crate::Result) {
|
pub fn set_result(&mut self, res: &crate::Result) { *self = Self::from_array(&res.to_args()); }
|
||||||
*self = Self::from_array(&res.to_args());
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn as_syscall(&self) -> core::result::Result<SysCall, crate::Error> {
|
pub fn as_syscall(&self) -> core::result::Result<SysCall, crate::Error> {
|
||||||
SysCall::from_args(
|
SysCall::from_args(self.a0, self.a1, self.a2, self.a3, self.a4, self.a5, self.a6, self.a7)
|
||||||
self.a0, self.a1, self.a2, self.a3, self.a4, self.a5, self.a6, self.a7,
|
|
||||||
)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -21,25 +21,19 @@ pub fn map_memory_post(
|
||||||
_range: MemoryRange,
|
_range: MemoryRange,
|
||||||
) -> core::result::Result<MemoryRange, Error> {
|
) -> core::result::Result<MemoryRange, Error> {
|
||||||
// let rounded_size = (size + PAGE_SIZE - 1) & !(PAGE_SIZE - 1);
|
// let rounded_size = (size + PAGE_SIZE - 1) & !(PAGE_SIZE - 1);
|
||||||
let layout = Layout::from_size_align(size, PAGE_SIZE)
|
let layout = Layout::from_size_align(size, PAGE_SIZE).unwrap().pad_to_align();
|
||||||
.unwrap()
|
|
||||||
.pad_to_align();
|
|
||||||
let mem = unsafe { alloc(layout) } as usize;
|
let mem = unsafe { alloc(layout) } as usize;
|
||||||
|
|
||||||
// println!("Allocated {} bytes (requested {}) @ {:016x}", rounded_size, size, mem);
|
// println!("Allocated {} bytes (requested {}) @ {:016x}", rounded_size, size, mem);
|
||||||
unsafe { MemoryRange::new(mem, size) }
|
unsafe { MemoryRange::new(mem, size) }
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn unmap_memory_pre(_range: &MemoryRange) -> core::result::Result<(), Error> {
|
pub fn unmap_memory_pre(_range: &MemoryRange) -> core::result::Result<(), Error> { Ok(()) }
|
||||||
Ok(())
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn unmap_memory_post(range: MemoryRange) -> core::result::Result<(), Error> {
|
pub fn unmap_memory_post(range: MemoryRange) -> core::result::Result<(), Error> {
|
||||||
// println!("Request to free {} bytes @ {:016x}", range.len(), range.as_ptr() as usize);
|
// println!("Request to free {} bytes @ {:016x}", range.len(), range.as_ptr() as usize);
|
||||||
// let rounded_size = (range.len() + 4095) / 4096;
|
// let rounded_size = (range.len() + 4095) / 4096;
|
||||||
let layout = Layout::from_size_align(range.len(), PAGE_SIZE)
|
let layout = Layout::from_size_align(range.len(), PAGE_SIZE).unwrap().pad_to_align();
|
||||||
.unwrap()
|
|
||||||
.pad_to_align();
|
|
||||||
let ptr = range.as_mut_ptr();
|
let ptr = range.as_mut_ptr();
|
||||||
unsafe { dealloc(ptr, layout) };
|
unsafe { dealloc(ptr, layout) };
|
||||||
Ok(())
|
Ok(())
|
||||||
|
|
|
||||||
|
|
@ -106,13 +106,9 @@ lazy_static::lazy_static! {
|
||||||
pub static ref CHILD_PROCESS_ADDRESS: Arc<Mutex<SocketAddr>> = Arc::new(Mutex::new(SocketAddr::new(IpAddr::V4(Ipv4Addr::new(127, 0, 0, 1)), 0)));
|
pub static ref CHILD_PROCESS_ADDRESS: Arc<Mutex<SocketAddr>> = Arc::new(Mutex::new(SocketAddr::new(IpAddr::V4(Ipv4Addr::new(127, 0, 0, 1)), 0)));
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn set_xous_address(new_address: SocketAddr) {
|
pub fn set_xous_address(new_address: SocketAddr) { *CHILD_PROCESS_ADDRESS.lock().unwrap() = new_address; }
|
||||||
*CHILD_PROCESS_ADDRESS.lock().unwrap() = new_address;
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn set_thread_id(new_tid: TID) {
|
pub fn set_thread_id(new_tid: TID) { THREAD_ID.with(|tid| *tid.borrow_mut() = Some(new_tid)); }
|
||||||
THREAD_ID.with(|tid| *tid.borrow_mut() = Some(new_tid));
|
|
||||||
}
|
|
||||||
|
|
||||||
#[derive(PartialEq)]
|
#[derive(PartialEq)]
|
||||||
enum CallMemoryKind {
|
enum CallMemoryKind {
|
||||||
|
|
@ -151,11 +147,7 @@ pub fn syscall(call: SysCall) -> SysCallResult {
|
||||||
panic!("call had memory, but was unrecognized")
|
panic!("call had memory, but was unrecognized")
|
||||||
};
|
};
|
||||||
|
|
||||||
SERVER_CONNECTION
|
SERVER_CONNECTION.call_mem_tracker.lock().unwrap().insert(tid, (range, kind));
|
||||||
.call_mem_tracker
|
|
||||||
.lock()
|
|
||||||
.unwrap()
|
|
||||||
.insert(tid, (range, kind));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// let start_time = std::time::Instant::now();
|
// let start_time = std::time::Instant::now();
|
||||||
|
|
@ -180,7 +172,8 @@ pub fn syscall(call: SysCall) -> SysCallResult {
|
||||||
// .remove(&tid)
|
// .remove(&tid)
|
||||||
// .is_some());
|
// .is_some());
|
||||||
if let Some(val) = result {
|
if let Some(val) = result {
|
||||||
// println!("[{:2}:{:2}] Syscall took {:7} usec: {:x?}", PROCESS_ID.get(), tid, start_time.elapsed().as_micros(), call);
|
// println!("[{:2}:{:2}] Syscall took {:7} usec: {:x?}", PROCESS_ID.get(), tid,
|
||||||
|
// start_time.elapsed().as_micros(), call);
|
||||||
return val;
|
return val;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -206,8 +199,7 @@ fn read_next_syscall_result(
|
||||||
|
|
||||||
// Read the Thread ID, which comes across first, followed by the 8 words of
|
// Read the Thread ID, which comes across first, followed by the 8 words of
|
||||||
// the message data.
|
// the message data.
|
||||||
let msg_thread_id =
|
let msg_thread_id = TID::from_le_bytes(raw_bytes_chunks.next().unwrap().try_into().unwrap());
|
||||||
TID::from_le_bytes(raw_bytes_chunks.next().unwrap().try_into().unwrap());
|
|
||||||
for (pkt_word, word) in pkt.iter_mut().zip(raw_bytes_chunks) {
|
for (pkt_word, word) in pkt.iter_mut().zip(raw_bytes_chunks) {
|
||||||
*pkt_word = usize::from_le_bytes(word.try_into().unwrap());
|
*pkt_word = usize::from_le_bytes(word.try_into().unwrap());
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,15 +1,14 @@
|
||||||
|
use core::convert::{TryFrom, TryInto};
|
||||||
|
|
||||||
use super::CHILD_PROCESS_ADDRESS;
|
use super::CHILD_PROCESS_ADDRESS;
|
||||||
pub use crate::PID;
|
pub use crate::PID;
|
||||||
use core::convert::{TryFrom, TryInto};
|
|
||||||
|
|
||||||
/// A 16-byte random nonce that identifies this process to the kernel. This
|
/// A 16-byte random nonce that identifies this process to the kernel. This
|
||||||
/// is usually provided through the environment variable `XOUS_PROCESS_KEY`.
|
/// is usually provided through the environment variable `XOUS_PROCESS_KEY`.
|
||||||
#[derive(Copy, Clone, Debug, PartialEq)]
|
#[derive(Copy, Clone, Debug, PartialEq)]
|
||||||
pub struct ProcessKey(pub(crate) [u8; 16]);
|
pub struct ProcessKey(pub(crate) [u8; 16]);
|
||||||
impl ProcessKey {
|
impl ProcessKey {
|
||||||
pub fn new(key: [u8; 16]) -> ProcessKey {
|
pub fn new(key: [u8; 16]) -> ProcessKey { ProcessKey(key) }
|
||||||
ProcessKey(key)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
impl core::fmt::Display for ProcessKey {
|
impl core::fmt::Display for ProcessKey {
|
||||||
|
|
@ -45,12 +44,7 @@ pub struct ProcessArgs {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl ProcessArgs {
|
impl ProcessArgs {
|
||||||
pub fn new(name: &str, command: String) -> ProcessArgs {
|
pub fn new(name: &str, command: String) -> ProcessArgs { ProcessArgs { command, name: name.to_owned() } }
|
||||||
ProcessArgs {
|
|
||||||
command,
|
|
||||||
name: name.to_owned(),
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
impl From<&ProcessInit> for [usize; 7] {
|
impl From<&ProcessInit> for [usize; 7] {
|
||||||
|
|
@ -69,6 +63,7 @@ impl From<&ProcessInit> for [usize; 7] {
|
||||||
|
|
||||||
impl TryFrom<[usize; 7]> for ProcessInit {
|
impl TryFrom<[usize; 7]> for ProcessInit {
|
||||||
type Error = crate::Error;
|
type Error = crate::Error;
|
||||||
|
|
||||||
fn try_from(src: [usize; 7]) -> core::result::Result<ProcessInit, crate::Error> {
|
fn try_from(src: [usize; 7]) -> core::result::Result<ProcessInit, crate::Error> {
|
||||||
let mut exploded = vec![];
|
let mut exploded = vec![];
|
||||||
for word in src[0..4].iter() {
|
for word in src[0..4].iter() {
|
||||||
|
|
@ -76,9 +71,7 @@ impl TryFrom<[usize; 7]> for ProcessInit {
|
||||||
}
|
}
|
||||||
let mut key = [0u8; 16];
|
let mut key = [0u8; 16];
|
||||||
key.copy_from_slice(&exploded);
|
key.copy_from_slice(&exploded);
|
||||||
Ok(ProcessInit {
|
Ok(ProcessInit { key: ProcessKey(key) })
|
||||||
key: ProcessKey(key),
|
|
||||||
})
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -90,26 +83,18 @@ pub struct ProcessStartup {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl ProcessStartup {
|
impl ProcessStartup {
|
||||||
pub fn new(pid: crate::PID) -> Self {
|
pub fn new(pid: crate::PID) -> Self { ProcessStartup { pid } }
|
||||||
ProcessStartup { pid }
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn pid(&self) -> crate::PID {
|
pub fn pid(&self) -> crate::PID { self.pid }
|
||||||
self.pid
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
impl core::fmt::Display for ProcessStartup {
|
impl core::fmt::Display for ProcessStartup {
|
||||||
fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
|
fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result { write!(f, "{}", self.pid) }
|
||||||
write!(f, "{}", self.pid)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
impl From<&[usize; 7]> for ProcessStartup {
|
impl From<&[usize; 7]> for ProcessStartup {
|
||||||
fn from(src: &[usize; 7]) -> ProcessStartup {
|
fn from(src: &[usize; 7]) -> ProcessStartup {
|
||||||
ProcessStartup {
|
ProcessStartup { pid: crate::PID::new(src[0] as _).unwrap() }
|
||||||
pid: crate::PID::new(src[0] as _).unwrap(),
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -121,9 +106,7 @@ impl From<[usize; 8]> for ProcessStartup {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl From<&ProcessStartup> for [usize; 7] {
|
impl From<&ProcessStartup> for [usize; 7] {
|
||||||
fn from(startup: &ProcessStartup) -> [usize; 7] {
|
fn from(startup: &ProcessStartup) -> [usize; 7] { [startup.pid.get() as _, 0, 0, 0, 0, 0, 0] }
|
||||||
[startup.pid.get() as _, 0, 0, 0, 0, 0, 0]
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
|
|
@ -174,11 +157,5 @@ pub fn wait_process(mut joiner: ProcessHandle) -> crate::SysCallResult {
|
||||||
.0
|
.0
|
||||||
.wait()
|
.wait()
|
||||||
.or(Err(crate::Error::InternalError))
|
.or(Err(crate::Error::InternalError))
|
||||||
.and_then(|e| {
|
.and_then(|e| if e.success() { Ok(crate::Result::Ok) } else { Err(crate::Error::UnknownError) })
|
||||||
if e.success() {
|
|
||||||
Ok(crate::Result::Ok)
|
|
||||||
} else {
|
|
||||||
Err(crate::Error::UnknownError)
|
|
||||||
}
|
|
||||||
})
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -11,9 +11,7 @@ thread_local!(pub static THREAD_ID: RefCell<Option<TID>> = RefCell::new(None));
|
||||||
pub struct ThreadInit {}
|
pub struct ThreadInit {}
|
||||||
pub struct WaitHandle<T>(std::thread::JoinHandle<T>);
|
pub struct WaitHandle<T>(std::thread::JoinHandle<T>);
|
||||||
|
|
||||||
pub fn thread_to_args(call: usize, _init: &ThreadInit) -> [usize; 8] {
|
pub fn thread_to_args(call: usize, _init: &ThreadInit) -> [usize; 8] { [call, 0, 0, 0, 0, 0, 0, 0] }
|
||||||
[call, 0, 0, 0, 0, 0, 0, 0]
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn args_to_thread(
|
pub fn args_to_thread(
|
||||||
_a1: usize,
|
_a1: usize,
|
||||||
|
|
@ -169,10 +167,7 @@ where
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Spawn a new thread with the given thread ID.
|
/// Spawn a new thread with the given thread ID.
|
||||||
pub fn create_thread_post<F, U>(
|
pub fn create_thread_post<F, U>(f: F, thread_id: TID) -> core::result::Result<WaitHandle<U>, crate::Error>
|
||||||
f: F,
|
|
||||||
thread_id: TID,
|
|
||||||
) -> core::result::Result<WaitHandle<U>, crate::Error>
|
|
||||||
where
|
where
|
||||||
F: FnOnce() -> U,
|
F: FnOnce() -> U,
|
||||||
F: Send + 'static,
|
F: Send + 'static,
|
||||||
|
|
@ -188,11 +183,7 @@ where
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn wait_thread<T>(joiner: WaitHandle<T>) -> crate::SysCallResult {
|
pub fn wait_thread<T>(joiner: WaitHandle<T>) -> crate::SysCallResult {
|
||||||
joiner
|
joiner.0.join().map(|_| Result::Ok).map_err(|_| crate::Error::InternalError)
|
||||||
.0
|
|
||||||
.join()
|
|
||||||
.map(|_| Result::Ok)
|
|
||||||
.map_err(|_| crate::Error::InternalError)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static FAKE_THREAD_COUNTER: AtomicUsize = AtomicUsize::new(65536);
|
static FAKE_THREAD_COUNTER: AtomicUsize = AtomicUsize::new(65536);
|
||||||
|
|
|
||||||
|
|
@ -8,17 +8,9 @@ pub mod riscv;
|
||||||
#[cfg(all(target_os = "xous", target_arch = "riscv32"))]
|
#[cfg(all(target_os = "xous", target_arch = "riscv32"))]
|
||||||
pub use riscv::*;
|
pub use riscv::*;
|
||||||
|
|
||||||
#[cfg(all(
|
#[cfg(all(not(feature = "processes-as-threads"), not(target_os = "xous"), not(target_arch = "arm"),))]
|
||||||
not(feature="processes-as-threads"),
|
|
||||||
not(target_os = "xous"),
|
|
||||||
not(target_arch = "arm"),
|
|
||||||
))]
|
|
||||||
pub mod hosted;
|
pub mod hosted;
|
||||||
#[cfg(all(
|
#[cfg(all(not(feature = "processes-as-threads"), not(target_os = "xous"), not(target_arch = "arm"),))]
|
||||||
not(feature="processes-as-threads"),
|
|
||||||
not(target_os = "xous"),
|
|
||||||
not(target_arch = "arm"),
|
|
||||||
))]
|
|
||||||
pub use hosted::*;
|
pub use hosted::*;
|
||||||
|
|
||||||
#[cfg(feature = "processes-as-threads")]
|
#[cfg(feature = "processes-as-threads")]
|
||||||
|
|
|
||||||
|
|
@ -19,10 +19,6 @@ pub fn map_memory_post(
|
||||||
Ok(range)
|
Ok(range)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn unmap_memory_pre(_range: &MemoryRange) -> core::result::Result<(), Error> {
|
pub fn unmap_memory_pre(_range: &MemoryRange) -> core::result::Result<(), Error> { Ok(()) }
|
||||||
Ok(())
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn unmap_memory_post(_range: MemoryRange) -> core::result::Result<(), Error> {
|
pub fn unmap_memory_post(_range: MemoryRange) -> core::result::Result<(), Error> { Ok(()) }
|
||||||
Ok(())
|
|
||||||
}
|
|
||||||
|
|
|
||||||
|
|
@ -105,10 +105,7 @@ where
|
||||||
todo!()
|
todo!()
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn create_thread_post<F, T>(
|
pub fn create_thread_post<F, T>(_f: F, _thread_id: TID) -> core::result::Result<WaitHandle<T>, crate::Error>
|
||||||
_f: F,
|
|
||||||
_thread_id: TID,
|
|
||||||
) -> core::result::Result<WaitHandle<T>, crate::Error>
|
|
||||||
where
|
where
|
||||||
F: FnOnce() -> T,
|
F: FnOnce() -> T,
|
||||||
F: Send + 'static,
|
F: Send + 'static,
|
||||||
|
|
@ -253,13 +250,7 @@ where
|
||||||
T: Send + 'static,
|
T: Send + 'static,
|
||||||
U: Send + 'static,
|
U: Send + 'static,
|
||||||
{
|
{
|
||||||
create_thread_n_pre(
|
create_thread_n_pre(*f as usize, unsafe { core::mem::transmute(arg) }, &0, &0, &0)
|
||||||
*f as usize,
|
|
||||||
unsafe { core::mem::transmute(arg) },
|
|
||||||
&0,
|
|
||||||
&0,
|
|
||||||
&0,
|
|
||||||
)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn create_thread_simple_post<T, U>(
|
pub fn create_thread_simple_post<T, U>(
|
||||||
|
|
@ -310,16 +301,7 @@ pub fn create_thread_n_post<U>(
|
||||||
where
|
where
|
||||||
U: Send + 'static,
|
U: Send + 'static,
|
||||||
{
|
{
|
||||||
Ok(WaitHandle {
|
Ok(WaitHandle { tid: thread_id, data: core::marker::PhantomData })
|
||||||
tid: thread_id,
|
|
||||||
data: core::marker::PhantomData,
|
|
||||||
})
|
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn cache_flush() {
|
pub fn cache_flush() { unsafe { core::arch::asm!("fence") }; }
|
||||||
unsafe {
|
|
||||||
core::arch::asm!(
|
|
||||||
"fence"
|
|
||||||
)
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
|
||||||
|
|
@ -68,14 +68,11 @@ impl From<&ProcessInit> for [usize; 7] {
|
||||||
|
|
||||||
impl TryFrom<[usize; 7]> for ProcessInit {
|
impl TryFrom<[usize; 7]> for ProcessInit {
|
||||||
type Error = crate::Error;
|
type Error = crate::Error;
|
||||||
|
|
||||||
fn try_from(src: [usize; 7]) -> Result<ProcessInit, Self::Error> {
|
fn try_from(src: [usize; 7]) -> Result<ProcessInit, Self::Error> {
|
||||||
Ok(ProcessInit {
|
Ok(ProcessInit {
|
||||||
stack: unsafe {
|
stack: unsafe { crate::MemoryRange::new(src[0], src[1]).or(Err(crate::Error::OutOfMemory))? },
|
||||||
crate::MemoryRange::new(src[0], src[1]).or(Err(crate::Error::OutOfMemory))?
|
text: unsafe { crate::MemoryRange::new(src[2], src[3]).or(Err(crate::Error::OutOfMemory))? },
|
||||||
},
|
|
||||||
text: unsafe {
|
|
||||||
crate::MemoryRange::new(src[2], src[3]).or(Err(crate::Error::OutOfMemory))?
|
|
||||||
},
|
|
||||||
text_destination: crate::MemoryAddress::new(src[4]).ok_or(crate::Error::OutOfMemory)?,
|
text_destination: crate::MemoryAddress::new(src[4]).ok_or(crate::Error::OutOfMemory)?,
|
||||||
start: crate::MemoryAddress::new(src[5]).ok_or(crate::Error::OutOfMemory)?,
|
start: crate::MemoryAddress::new(src[5]).ok_or(crate::Error::OutOfMemory)?,
|
||||||
})
|
})
|
||||||
|
|
@ -94,17 +91,12 @@ pub struct ProcessStartup {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl ProcessStartup {
|
impl ProcessStartup {
|
||||||
pub fn new(pid: crate::PID, connection: crate::CID) -> Self {
|
pub fn new(pid: crate::PID, connection: crate::CID) -> Self { ProcessStartup { pid, connection } }
|
||||||
ProcessStartup { pid, connection }
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
impl From<&[usize; 7]> for ProcessStartup {
|
impl From<&[usize; 7]> for ProcessStartup {
|
||||||
fn from(src: &[usize; 7]) -> ProcessStartup {
|
fn from(src: &[usize; 7]) -> ProcessStartup {
|
||||||
ProcessStartup {
|
ProcessStartup { pid: crate::PID::new(src[0] as _).unwrap(), connection: src[1] as _ }
|
||||||
pid: crate::PID::new(src[0] as _).unwrap(),
|
|
||||||
connection: src[1] as _,
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -115,17 +107,12 @@ impl From<[usize; 8]> for ProcessStartup {
|
||||||
None => unsafe { crate::PID::new_unchecked(255) },
|
None => unsafe { crate::PID::new_unchecked(255) },
|
||||||
};
|
};
|
||||||
let cid = src[2] as _;
|
let cid = src[2] as _;
|
||||||
ProcessStartup {
|
ProcessStartup { pid, connection: cid }
|
||||||
pid,
|
|
||||||
connection: cid,
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl From<&ProcessStartup> for [usize; 7] {
|
impl From<&ProcessStartup> for [usize; 7] {
|
||||||
fn from(src: &ProcessStartup) -> [usize; 7] {
|
fn from(src: &ProcessStartup) -> [usize; 7] { [src.pid.get() as _, src.connection as _, 0, 0, 0, 0, 0] }
|
||||||
[src.pid.get() as _, src.connection as _, 0, 0, 0, 0, 0]
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
pub struct ProcessHandle {
|
pub struct ProcessHandle {
|
||||||
|
|
@ -136,9 +123,7 @@ pub struct ProcessHandle {
|
||||||
#[derive(Copy, Clone, Debug, PartialEq)]
|
#[derive(Copy, Clone, Debug, PartialEq)]
|
||||||
pub struct ProcessKey([u8; 8]);
|
pub struct ProcessKey([u8; 8]);
|
||||||
impl ProcessKey {
|
impl ProcessKey {
|
||||||
pub fn new(key: [u8; 8]) -> ProcessKey {
|
pub fn new(key: [u8; 8]) -> ProcessKey { ProcessKey(key) }
|
||||||
ProcessKey(key)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Convert the `ProcessArgs` structure passed by the user into a `ProcessInit`
|
/// Convert the `ProcessArgs` structure passed by the user into a `ProcessInit`
|
||||||
|
|
@ -172,10 +157,7 @@ pub fn create_process_post(
|
||||||
_init: ProcessInit,
|
_init: ProcessInit,
|
||||||
startup: ProcessStartup,
|
startup: ProcessStartup,
|
||||||
) -> core::result::Result<ProcessHandle, crate::Error> {
|
) -> core::result::Result<ProcessHandle, crate::Error> {
|
||||||
Ok(ProcessHandle {
|
Ok(ProcessHandle { pid: startup.pid, cid: startup.connection })
|
||||||
pid: startup.pid,
|
|
||||||
cid: startup.connection,
|
|
||||||
})
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Wait for a process to terminate.
|
/// Wait for a process to terminate.
|
||||||
|
|
|
||||||
|
|
@ -24,9 +24,7 @@ pub fn map_memory_post(
|
||||||
Ok(unsafe { MemoryRange::new(new_mem.get(), range.len()).unwrap() })
|
Ok(unsafe { MemoryRange::new(new_mem.get(), range.len()).unwrap() })
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn unmap_memory_pre(_range: &MemoryRange) -> core::result::Result<(), Error> {
|
pub fn unmap_memory_pre(_range: &MemoryRange) -> core::result::Result<(), Error> { Ok(()) }
|
||||||
Ok(())
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn unmap_memory_post(range: MemoryRange) -> core::result::Result<(), Error> {
|
pub fn unmap_memory_post(range: MemoryRange) -> core::result::Result<(), Error> {
|
||||||
let layout = Layout::from_size_align(range.len(), 4096).unwrap();
|
let layout = Layout::from_size_align(range.len(), 4096).unwrap();
|
||||||
|
|
|
||||||
|
|
@ -15,9 +15,7 @@ pub use mem::*;
|
||||||
#[derive(Copy, Clone, Debug, PartialEq)]
|
#[derive(Copy, Clone, Debug, PartialEq)]
|
||||||
pub struct ProcessKey([u8; 16]);
|
pub struct ProcessKey([u8; 16]);
|
||||||
impl ProcessKey {
|
impl ProcessKey {
|
||||||
pub fn new(key: [u8; 16]) -> ProcessKey {
|
pub fn new(key: [u8; 16]) -> ProcessKey { ProcessKey(key) }
|
||||||
ProcessKey(key)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
impl core::fmt::Display for ProcessKey {
|
impl core::fmt::Display for ProcessKey {
|
||||||
|
|
@ -58,10 +56,7 @@ where
|
||||||
F: FnOnce(),
|
F: FnOnce(),
|
||||||
{
|
{
|
||||||
pub fn new(name: &str, main: F) -> ProcessArgsAsThread<F> {
|
pub fn new(name: &str, main: F) -> ProcessArgsAsThread<F> {
|
||||||
ProcessArgsAsThread {
|
ProcessArgsAsThread { main, name: name.to_owned() }
|
||||||
main,
|
|
||||||
name: name.to_owned(),
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
pub struct ProcessHandleAsThread(std::thread::JoinHandle<()>);
|
pub struct ProcessHandleAsThread(std::thread::JoinHandle<()>);
|
||||||
|
|
@ -79,11 +74,7 @@ where
|
||||||
// Ensure there is a connection, because after this function returns
|
// Ensure there is a connection, because after this function returns
|
||||||
// we'll make a syscall with CreateProcess(). This should only need
|
// we'll make a syscall with CreateProcess(). This should only need
|
||||||
// to happen for PID1.
|
// to happen for PID1.
|
||||||
Ok(ProcessInit {
|
Ok(ProcessInit { key: PROCESS_KEY.with(|pk| *pk.borrow()).unwrap_or_else(default_process_key) })
|
||||||
key: PROCESS_KEY
|
|
||||||
.with(|pk| *pk.borrow())
|
|
||||||
.unwrap_or_else(default_process_key),
|
|
||||||
})
|
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn create_process_post_as_thread<F>(
|
pub fn create_process_post_as_thread<F>(
|
||||||
|
|
@ -138,12 +129,7 @@ pub struct ProcessArgs {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl ProcessArgs {
|
impl ProcessArgs {
|
||||||
pub fn new(name: &str, command: String) -> ProcessArgs {
|
pub fn new(name: &str, command: String) -> ProcessArgs { ProcessArgs { command, name: name.to_owned() } }
|
||||||
ProcessArgs {
|
|
||||||
command,
|
|
||||||
name: name.to_owned(),
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// This is returned when a process is created
|
/// This is returned when a process is created
|
||||||
|
|
@ -154,26 +140,18 @@ pub struct ProcessStartup {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl ProcessStartup {
|
impl ProcessStartup {
|
||||||
pub fn new(pid: crate::PID) -> Self {
|
pub fn new(pid: crate::PID) -> Self { ProcessStartup { pid } }
|
||||||
ProcessStartup { pid }
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn pid(&self) -> crate::PID {
|
pub fn pid(&self) -> crate::PID { self.pid }
|
||||||
self.pid
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
impl core::fmt::Display for ProcessStartup {
|
impl core::fmt::Display for ProcessStartup {
|
||||||
fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
|
fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result { write!(f, "{}", self.pid) }
|
||||||
write!(f, "{}", self.pid)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
impl From<&[usize; 7]> for ProcessStartup {
|
impl From<&[usize; 7]> for ProcessStartup {
|
||||||
fn from(src: &[usize; 7]) -> ProcessStartup {
|
fn from(src: &[usize; 7]) -> ProcessStartup {
|
||||||
ProcessStartup {
|
ProcessStartup { pid: crate::PID::new(src[0] as _).unwrap() }
|
||||||
pid: crate::PID::new(src[0] as _).unwrap(),
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -185,9 +163,7 @@ impl From<[usize; 8]> for ProcessStartup {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl From<&ProcessStartup> for [usize; 7] {
|
impl From<&ProcessStartup> for [usize; 7] {
|
||||||
fn from(startup: &ProcessStartup) -> [usize; 7] {
|
fn from(startup: &ProcessStartup) -> [usize; 7] { [startup.pid.get() as _, 0, 0, 0, 0, 0, 0] }
|
||||||
[startup.pid.get() as _, 0, 0, 0, 0, 0, 0]
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
impl From<&ProcessInit> for [usize; 7] {
|
impl From<&ProcessInit> for [usize; 7] {
|
||||||
|
|
@ -206,6 +182,7 @@ impl From<&ProcessInit> for [usize; 7] {
|
||||||
|
|
||||||
impl TryFrom<[usize; 7]> for ProcessInit {
|
impl TryFrom<[usize; 7]> for ProcessInit {
|
||||||
type Error = crate::Error;
|
type Error = crate::Error;
|
||||||
|
|
||||||
fn try_from(src: [usize; 7]) -> core::result::Result<ProcessInit, crate::Error> {
|
fn try_from(src: [usize; 7]) -> core::result::Result<ProcessInit, crate::Error> {
|
||||||
let mut exploded = vec![];
|
let mut exploded = vec![];
|
||||||
for word in src[0..4].into_iter() {
|
for word in src[0..4].into_iter() {
|
||||||
|
|
@ -213,9 +190,7 @@ impl TryFrom<[usize; 7]> for ProcessInit {
|
||||||
}
|
}
|
||||||
let mut key = [0u8; 16];
|
let mut key = [0u8; 16];
|
||||||
key.copy_from_slice(&exploded);
|
key.copy_from_slice(&exploded);
|
||||||
Ok(ProcessInit {
|
Ok(ProcessInit { key: ProcessKey(key) })
|
||||||
key: ProcessKey(key),
|
|
||||||
})
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -230,11 +205,7 @@ pub fn create_process_pre(_args: &ProcessArgs) -> core::result::Result<ProcessIn
|
||||||
// Ensure there is a connection, because after this function returns
|
// Ensure there is a connection, because after this function returns
|
||||||
// we'll make a syscall with CreateProcess(). This should only need
|
// we'll make a syscall with CreateProcess(). This should only need
|
||||||
// to happen for PID1.
|
// to happen for PID1.
|
||||||
Ok(ProcessInit {
|
Ok(ProcessInit { key: PROCESS_KEY.with(|pk| *pk.borrow()).unwrap_or_else(default_process_key) })
|
||||||
key: PROCESS_KEY
|
|
||||||
.with(|pk| *pk.borrow())
|
|
||||||
.unwrap_or_else(default_process_key),
|
|
||||||
})
|
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn create_process_post(
|
pub fn create_process_post(
|
||||||
|
|
@ -275,13 +246,7 @@ pub fn wait_process(mut joiner: ProcessHandle) -> crate::SysCallResult {
|
||||||
.0
|
.0
|
||||||
.wait()
|
.wait()
|
||||||
.or(Err(crate::Error::InternalError))
|
.or(Err(crate::Error::InternalError))
|
||||||
.and_then(|e| {
|
.and_then(|e| if e.success() { Ok(crate::Result::Ok) } else { Err(crate::Error::UnknownError) })
|
||||||
if e.success() {
|
|
||||||
Ok(crate::Result::Ok)
|
|
||||||
} else {
|
|
||||||
Err(crate::Error::UnknownError)
|
|
||||||
}
|
|
||||||
})
|
|
||||||
}
|
}
|
||||||
|
|
||||||
pub struct WaitHandle<T>(std::thread::JoinHandle<T>);
|
pub struct WaitHandle<T>(std::thread::JoinHandle<T>);
|
||||||
|
|
@ -293,9 +258,7 @@ struct ServerConnection {
|
||||||
mailbox: Arc<Mutex<HashMap<TID, Result>>>,
|
mailbox: Arc<Mutex<HashMap<TID, Result>>>,
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn thread_to_args(call: usize, _init: &ThreadInit) -> [usize; 8] {
|
pub fn thread_to_args(call: usize, _init: &ThreadInit) -> [usize; 8] { [call, 0, 0, 0, 0, 0, 0, 0] }
|
||||||
[call, 0, 0, 0, 0, 0, 0, 0]
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn process_to_args(call: usize, init: &ProcessInit) -> [usize; 8] {
|
pub fn process_to_args(call: usize, init: &ProcessInit) -> [usize; 8] {
|
||||||
[
|
[
|
||||||
|
|
@ -338,9 +301,7 @@ pub fn args_to_process(
|
||||||
v.extend_from_slice(&(a4 as u32).to_le_bytes());
|
v.extend_from_slice(&(a4 as u32).to_le_bytes());
|
||||||
let mut key = [0u8; 16];
|
let mut key = [0u8; 16];
|
||||||
key.copy_from_slice(&v);
|
key.copy_from_slice(&v);
|
||||||
Ok(ProcessInit {
|
Ok(ProcessInit { key: ProcessKey(key) })
|
||||||
key: ProcessKey(key),
|
|
||||||
})
|
|
||||||
}
|
}
|
||||||
|
|
||||||
thread_local!(static NETWORK_CONNECT_ADDRESS: RefCell<Option<SocketAddr>> = RefCell::new(None));
|
thread_local!(static NETWORK_CONNECT_ADDRESS: RefCell<Option<SocketAddr>> = RefCell::new(None));
|
||||||
|
|
@ -362,9 +323,7 @@ fn default_xous_address() -> SocketAddr {
|
||||||
}
|
}
|
||||||
|
|
||||||
fn default_process_key() -> ProcessKey {
|
fn default_process_key() -> ProcessKey {
|
||||||
std::env::var("XOUS_PROCESS_KEY")
|
std::env::var("XOUS_PROCESS_KEY").map(|s| s.as_str().into()).unwrap_or(ProcessKey([0u8; 16]))
|
||||||
.map(|s| s.as_str().into())
|
|
||||||
.unwrap_or(ProcessKey([0u8; 16]))
|
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn set_process_key(new_key: &[u8; 16]) {
|
pub fn set_process_key(new_key: &[u8; 16]) {
|
||||||
|
|
@ -382,9 +341,7 @@ pub fn set_xous_address(new_address: SocketAddr) {
|
||||||
|
|
||||||
/// Get the network address for this particular thread.
|
/// Get the network address for this particular thread.
|
||||||
fn xous_address() -> SocketAddr {
|
fn xous_address() -> SocketAddr {
|
||||||
NETWORK_CONNECT_ADDRESS
|
NETWORK_CONNECT_ADDRESS.with(|nca| *nca.borrow()).unwrap_or_else(default_xous_address)
|
||||||
.with(|nca| *nca.borrow())
|
|
||||||
.unwrap_or_else(default_xous_address)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn create_thread_0_pre<U>(_f: &fn() -> U) -> core::result::Result<ThreadInit, crate::Error>
|
pub fn create_thread_0_pre<U>(_f: &fn() -> U) -> core::result::Result<ThreadInit, crate::Error>
|
||||||
|
|
@ -528,18 +485,14 @@ where
|
||||||
Ok(ThreadInit {})
|
Ok(ThreadInit {})
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn create_thread_post<F, U>(
|
pub fn create_thread_post<F, U>(f: F, thread_id: TID) -> core::result::Result<WaitHandle<U>, crate::Error>
|
||||||
f: F,
|
|
||||||
thread_id: TID,
|
|
||||||
) -> core::result::Result<WaitHandle<U>, crate::Error>
|
|
||||||
where
|
where
|
||||||
F: FnOnce() -> U,
|
F: FnOnce() -> U,
|
||||||
F: Send + 'static,
|
F: Send + 'static,
|
||||||
U: Send + 'static,
|
U: Send + 'static,
|
||||||
{
|
{
|
||||||
let server_address = xous_address();
|
let server_address = xous_address();
|
||||||
let server_connection =
|
let server_connection = XOUS_SERVER_CONNECTION.with(|xsc| xsc.borrow().as_ref().unwrap().clone());
|
||||||
XOUS_SERVER_CONNECTION.with(|xsc| xsc.borrow().as_ref().unwrap().clone());
|
|
||||||
let process_id = PROCESS_ID.with(|pid| *pid.borrow());
|
let process_id = PROCESS_ID.with(|pid| *pid.borrow());
|
||||||
let call_for_thread = CALL_FOR_THREAD.with(|cft| cft.borrow().clone());
|
let call_for_thread = CALL_FOR_THREAD.with(|cft| cft.borrow().clone());
|
||||||
Ok(std::thread::Builder::new()
|
Ok(std::thread::Builder::new()
|
||||||
|
|
@ -556,11 +509,7 @@ where
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn wait_thread<T>(joiner: WaitHandle<T>) -> crate::SysCallResult {
|
pub fn wait_thread<T>(joiner: WaitHandle<T>) -> crate::SysCallResult {
|
||||||
joiner
|
joiner.0.join().map(|_| Result::Ok).map_err(|_| crate::Error::InternalError)
|
||||||
.0
|
|
||||||
.join()
|
|
||||||
.map(|_| Result::Ok)
|
|
||||||
.map_err(|_| crate::Error::InternalError)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn ensure_connection() -> core::result::Result<(), crate::Error> {
|
pub fn ensure_connection() -> core::result::Result<(), crate::Error> {
|
||||||
|
|
@ -569,9 +518,7 @@ pub fn ensure_connection() -> core::result::Result<(), crate::Error> {
|
||||||
if xsc.is_none() {
|
if xsc.is_none() {
|
||||||
NETWORK_CONNECT_ADDRESS.with(|nca| {
|
NETWORK_CONNECT_ADDRESS.with(|nca| {
|
||||||
let addr = nca.borrow().unwrap_or_else(default_xous_address);
|
let addr = nca.borrow().unwrap_or_else(default_xous_address);
|
||||||
let pid1_key = PROCESS_KEY
|
let pid1_key = PROCESS_KEY.with(|pk| *pk.borrow()).unwrap_or_else(default_process_key);
|
||||||
.with(|pk| *pk.borrow())
|
|
||||||
.unwrap_or_else(default_process_key);
|
|
||||||
match xous_connect_impl(addr, &pid1_key) {
|
match xous_connect_impl(addr, &pid1_key) {
|
||||||
Ok(a) => {
|
Ok(a) => {
|
||||||
*xsc = Some(a);
|
*xsc = Some(a);
|
||||||
|
|
@ -586,10 +533,7 @@ pub fn ensure_connection() -> core::result::Result<(), crate::Error> {
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
fn xous_connect_impl(
|
fn xous_connect_impl(addr: SocketAddr, key: &ProcessKey) -> core::result::Result<ServerConnection, ()> {
|
||||||
addr: SocketAddr,
|
|
||||||
key: &ProcessKey,
|
|
||||||
) -> core::result::Result<ServerConnection, ()> {
|
|
||||||
// eprintln!("Opening connection to Xous server @ {} with key {:?}...", addr, key);
|
// eprintln!("Opening connection to Xous server @ {} with key {:?}...", addr, key);
|
||||||
assert_ne!(&key.0, &[0u8; 16]);
|
assert_ne!(&key.0, &[0u8; 16]);
|
||||||
match TcpStream::connect(addr) {
|
match TcpStream::connect(addr) {
|
||||||
|
|
@ -633,27 +577,18 @@ pub fn syscall(call: SysCall) -> SysCallResult {
|
||||||
let call = crate::SysCall::from_args(nr, a1, a2, a3, a4, a5, a6, a7).unwrap();
|
let call = crate::SysCall::from_args(nr, a1, a2, a3, a4, a5, a6, a7).unwrap();
|
||||||
|
|
||||||
let mut xsc_borrowed = xsc.borrow_mut();
|
let mut xsc_borrowed = xsc.borrow_mut();
|
||||||
let xsc_asmut = xsc_borrowed.as_mut().expect("not connected to server (did you forget to create a thread with xous::create_thread()?)");
|
let xsc_asmut = xsc_borrowed.as_mut().expect(
|
||||||
|
"not connected to server (did you forget to create a thread with xous::create_thread()?)",
|
||||||
|
);
|
||||||
loop {
|
loop {
|
||||||
_xous_syscall_to(
|
_xous_syscall_to(nr, a1, a2, a3, a4, a5, a6, a7, &call, xsc_asmut);
|
||||||
nr,
|
|
||||||
a1,
|
|
||||||
a2,
|
|
||||||
a3,
|
|
||||||
a4,
|
|
||||||
a5,
|
|
||||||
a6,
|
|
||||||
a7,
|
|
||||||
&call,
|
|
||||||
xsc_asmut
|
|
||||||
);
|
|
||||||
_xous_syscall_result(&mut ret, *tid.borrow(), xsc_asmut);
|
_xous_syscall_result(&mut ret, *tid.borrow(), xsc_asmut);
|
||||||
match ret {
|
match ret {
|
||||||
Result::Error(e) => return Err(e),
|
Result::Error(e) => return Err(e),
|
||||||
Result::RetryCall => (),
|
Result::RetryCall => (),
|
||||||
other => return Ok(other),
|
other => return Ok(other),
|
||||||
}
|
}
|
||||||
std::thread::sleep(std::time::Duration::from_millis(50));
|
std::thread::sleep(std::time::Duration::from_millis(50));
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
@ -719,8 +654,7 @@ fn _xous_syscall_result(ret: &mut Result, thread_id: TID, server_connection: &Se
|
||||||
|
|
||||||
// Read the Thread ID, which comes across first, followed by the 8 words of
|
// Read the Thread ID, which comes across first, followed by the 8 words of
|
||||||
// the message data.
|
// the message data.
|
||||||
let msg_thread_id =
|
let msg_thread_id = usize::from_le_bytes(raw_bytes_chunks.next().unwrap().try_into().unwrap());
|
||||||
usize::from_le_bytes(raw_bytes_chunks.next().unwrap().try_into().unwrap());
|
|
||||||
for (pkt_word, word) in pkt.iter_mut().zip(raw_bytes_chunks) {
|
for (pkt_word, word) in pkt.iter_mut().zip(raw_bytes_chunks) {
|
||||||
*pkt_word = usize::from_le_bytes(word.try_into().unwrap());
|
*pkt_word = usize::from_le_bytes(word.try_into().unwrap());
|
||||||
}
|
}
|
||||||
|
|
@ -751,9 +685,7 @@ fn _xous_syscall_result(ret: &mut Result, thread_id: TID, server_connection: &Se
|
||||||
let call = CALL_FOR_THREAD.with(|cft| {
|
let call = CALL_FOR_THREAD.with(|cft| {
|
||||||
let cft_borrowed = cft.borrow();
|
let cft_borrowed = cft.borrow();
|
||||||
let mut cft_mtx = cft_borrowed.lock().unwrap();
|
let mut cft_mtx = cft_borrowed.lock().unwrap();
|
||||||
cft_mtx
|
cft_mtx.remove(&msg_thread_id).expect("thread didn't declare whether it has data")
|
||||||
.remove(&msg_thread_id)
|
|
||||||
.expect("thread didn't declare whether it has data")
|
|
||||||
});
|
});
|
||||||
|
|
||||||
// If the client is passing us memory, remap the array to our own space.
|
// If the client is passing us memory, remap the array to our own space.
|
||||||
|
|
@ -772,8 +704,7 @@ fn _xous_syscall_result(ret: &mut Result, thread_id: TID, server_connection: &Se
|
||||||
assert_eq!(data.len(), data.capacity());
|
assert_eq!(data.len(), data.capacity());
|
||||||
let len = data.len();
|
let len = data.len();
|
||||||
let addr = data.as_mut_ptr();
|
let addr = data.as_mut_ptr();
|
||||||
memory_message.buf =
|
memory_message.buf = unsafe { crate::MemoryRange::new(addr as _, len).unwrap() };
|
||||||
unsafe { crate::MemoryRange::new(addr as _, len).unwrap() };
|
|
||||||
}
|
}
|
||||||
_ => (),
|
_ => (),
|
||||||
}
|
}
|
||||||
|
|
@ -787,11 +718,7 @@ fn _xous_syscall_result(ret: &mut Result, thread_id: TID, server_connection: &Se
|
||||||
let mut data = unsafe { slice::from_raw_parts_mut(mem.as_mut_ptr(), mem.len()) };
|
let mut data = unsafe { slice::from_raw_parts_mut(mem.as_mut_ptr(), mem.len()) };
|
||||||
|
|
||||||
// If it's a Borrow, verify the contents haven't changed.
|
// If it's a Borrow, verify the contents haven't changed.
|
||||||
let previous_data = if call.is_borrow() {
|
let previous_data = if call.is_borrow() { Some(data.to_vec()) } else { None };
|
||||||
Some(data.to_vec())
|
|
||||||
} else {
|
|
||||||
None
|
|
||||||
};
|
|
||||||
|
|
||||||
if let Err(e) = stream.read_exact(&mut data) {
|
if let Err(e) = stream.read_exact(&mut data) {
|
||||||
eprintln!("Server shut down: {}", e);
|
eprintln!("Server shut down: {}", e);
|
||||||
|
|
@ -814,8 +741,7 @@ fn _xous_syscall_result(ret: &mut Result, thread_id: TID, server_connection: &Se
|
||||||
// If we're returning memory to the Server, then reconstitute the buffer we just passed,
|
// If we're returning memory to the Server, then reconstitute the buffer we just passed,
|
||||||
// and Drop it so it can be freed.
|
// and Drop it so it can be freed.
|
||||||
if call.is_return_memory() {
|
if call.is_return_memory() {
|
||||||
let rebuilt =
|
let rebuilt = unsafe { Vec::from_raw_parts(mem.as_mut_ptr(), mem.len(), mem.len()) };
|
||||||
unsafe { Vec::from_raw_parts(mem.as_mut_ptr(), mem.len(), mem.len()) };
|
|
||||||
drop(rebuilt);
|
drop(rebuilt);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -27,8 +27,7 @@ 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 valid =
|
let valid = unsafe { MemoryRange::new(new_mem.as_mut_ptr() as usize, 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()) },
|
||||||
|
|
@ -41,48 +40,29 @@ impl<'a> Carton<'a> {
|
||||||
// Leak the memory buffer, since it will be taken care of
|
// Leak the memory buffer, since it will be taken care of
|
||||||
// when the MemoryMessage is dropped.
|
// when the MemoryMessage is dropped.
|
||||||
self.should_drop = false;
|
self.should_drop = false;
|
||||||
MemoryMessage {
|
MemoryMessage { id, buf: self.valid, offset: None, valid: None }
|
||||||
id,
|
|
||||||
buf: self.valid,
|
|
||||||
offset: None,
|
|
||||||
valid: None,
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Perform an immutable lend of this Carton to the specified server.
|
/// Perform an immutable lend of this Carton to the specified server.
|
||||||
/// This function will block until the server returns.
|
/// This function will block until the server returns.
|
||||||
pub fn lend(&self, connection: CID, id: usize) -> Result<crate::Result, Error> {
|
pub fn lend(&self, connection: CID, id: usize) -> Result<crate::Result, Error> {
|
||||||
let msg = MemoryMessage {
|
let msg = MemoryMessage { id, buf: self.valid, offset: None, valid: None };
|
||||||
id,
|
|
||||||
buf: self.valid,
|
|
||||||
offset: None,
|
|
||||||
valid: None,
|
|
||||||
};
|
|
||||||
crate::send_message(connection, Message::Borrow(msg))
|
crate::send_message(connection, Message::Borrow(msg))
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Perform a mutable lend of this Carton to the server.
|
/// Perform a mutable lend of this Carton to the server.
|
||||||
pub fn lend_mut(&mut self, connection: CID, id: usize) -> Result<crate::Result, Error> {
|
pub fn lend_mut(&mut self, connection: CID, id: usize) -> Result<crate::Result, Error> {
|
||||||
let msg = MemoryMessage {
|
let msg = MemoryMessage { id, buf: self.valid, offset: None, valid: None };
|
||||||
id,
|
|
||||||
buf: self.valid,
|
|
||||||
offset: None,
|
|
||||||
valid: None,
|
|
||||||
};
|
|
||||||
crate::send_message(connection, Message::MutableBorrow(msg))
|
crate::send_message(connection, Message::MutableBorrow(msg))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<'a> AsRef<MemoryRange> for Carton<'a> {
|
impl<'a> AsRef<MemoryRange> for Carton<'a> {
|
||||||
fn as_ref(&self) -> &MemoryRange {
|
fn as_ref(&self) -> &MemoryRange { &self.valid }
|
||||||
&self.valid
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<'a> AsRef<[u8]> for Carton<'a> {
|
impl<'a> AsRef<[u8]> for Carton<'a> {
|
||||||
fn as_ref(&self) -> &[u8] {
|
fn as_ref(&self) -> &[u8] { self.slice }
|
||||||
self.slice
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<'a> Drop for Carton<'a> {
|
impl<'a> Drop for Carton<'a> {
|
||||||
|
|
|
||||||
|
|
@ -109,44 +109,32 @@ impl SID {
|
||||||
Some(SID(sid))
|
Some(SID(sid))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
pub const fn from_u32(a0: u32, a1: u32, a2: u32, a3: u32) -> SID {
|
|
||||||
SID([a0, a1, a2, a3])
|
pub const fn from_u32(a0: u32, a1: u32, a2: u32, a3: u32) -> SID { SID([a0, a1, a2, a3]) }
|
||||||
}
|
|
||||||
pub const fn from_array(a: [u32; 4]) -> SID {
|
pub const fn from_array(a: [u32; 4]) -> SID { SID(a) }
|
||||||
SID(a)
|
|
||||||
}
|
pub const fn to_u32(&self) -> (u32, u32, u32, u32) { (self.0[0], self.0[1], self.0[2], self.0[3]) }
|
||||||
pub const fn to_u32(&self) -> (u32, u32, u32, u32) {
|
|
||||||
(self.0[0], self.0[1], self.0[2], self.0[3])
|
pub const fn to_array(&self) -> [u32; 4] { self.0 }
|
||||||
}
|
|
||||||
pub const fn to_array(&self) -> [u32; 4] {
|
|
||||||
self.0
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
impl core::str::FromStr for SID {
|
impl core::str::FromStr for SID {
|
||||||
type Err = ();
|
type Err = ();
|
||||||
|
|
||||||
fn from_str(s: &str) -> core::result::Result<SID, ()> {
|
fn from_str(s: &str) -> core::result::Result<SID, ()> { Self::from_bytes(s.as_bytes()).ok_or(()) }
|
||||||
Self::from_bytes(s.as_bytes()).ok_or(())
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
impl From<[u32; 4]> for SID {
|
impl From<[u32; 4]> for SID {
|
||||||
fn from(src: [u32; 4]) -> Self {
|
fn from(src: [u32; 4]) -> Self { Self::from_u32(src[0], src[1], src[2], src[3]) }
|
||||||
Self::from_u32(src[0], src[1], src[2], src[3])
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
impl From<&[u32; 4]> for SID {
|
impl From<&[u32; 4]> for SID {
|
||||||
fn from(src: &[u32; 4]) -> Self {
|
fn from(src: &[u32; 4]) -> Self { Self::from_array(*src) }
|
||||||
Self::from_array(*src)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
impl From<SID> for [u32; 4] {
|
impl From<SID> for [u32; 4] {
|
||||||
fn from(s: SID) -> [u32; 4] {
|
fn from(s: SID) -> [u32; 4] { s.0 }
|
||||||
s.0
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Connection ID
|
/// Connection ID
|
||||||
|
|
@ -232,6 +220,7 @@ impl Error {
|
||||||
_ => UnknownError,
|
_ => UnknownError,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn to_usize(&self) -> usize {
|
pub fn to_usize(&self) -> usize {
|
||||||
use crate::Error::*;
|
use crate::Error::*;
|
||||||
match *self {
|
match *self {
|
||||||
|
|
@ -379,10 +368,7 @@ pub enum Result {
|
||||||
None,
|
None,
|
||||||
|
|
||||||
/// Memory was returned, and more information is available.
|
/// Memory was returned, and more information is available.
|
||||||
MemoryReturned(
|
MemoryReturned(Option<MemorySize> /* offset */, Option<MemorySize> /* valid */),
|
||||||
Option<MemorySize>, /* offset */
|
|
||||||
Option<MemorySize>, /* valid */
|
|
||||||
),
|
|
||||||
|
|
||||||
/// Returned when a process has started. This describes the new process to
|
/// Returned when a process has started. This describes the new process to
|
||||||
/// the caller.
|
/// the caller.
|
||||||
|
|
@ -399,9 +385,7 @@ pub enum Result {
|
||||||
|
|
||||||
impl Result {
|
impl Result {
|
||||||
fn add_opcode(opcode: usize, args: [usize; 7]) -> [usize; 8] {
|
fn add_opcode(opcode: usize, args: [usize; 7]) -> [usize; 8] {
|
||||||
[
|
[opcode, args[0], args[1], args[2], args[3], args[4], args[5], args[6]]
|
||||||
opcode, args[0], args[1], args[2], args[3], args[4], args[5], args[6],
|
|
||||||
]
|
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn to_args(&self) -> [usize; 8] {
|
pub fn to_args(&self) -> [usize; 8] {
|
||||||
|
|
@ -421,9 +405,7 @@ impl Result {
|
||||||
Result::ConnectionID(cid) => [7, *cid as usize, 0, 0, 0, 0, 0, 0],
|
Result::ConnectionID(cid) => [7, *cid as usize, 0, 0, 0, 0, 0, 0],
|
||||||
Result::MessageEnvelope(me) => {
|
Result::MessageEnvelope(me) => {
|
||||||
let me_enc = me.to_usize();
|
let me_enc = me.to_usize();
|
||||||
[
|
[9, me_enc[0], me_enc[1], me_enc[2], me_enc[3], me_enc[4], me_enc[5], me_enc[6]]
|
||||||
9, me_enc[0], me_enc[1], me_enc[2], me_enc[3], me_enc[4], me_enc[5], me_enc[6],
|
|
||||||
]
|
|
||||||
}
|
}
|
||||||
Result::ThreadID(ctx) => [10, *ctx, 0, 0, 0, 0, 0, 0],
|
Result::ThreadID(ctx) => [10, *ctx, 0, 0, 0, 0, 0, 0],
|
||||||
Result::ProcessID(pid) => [11, pid.get() as _, 0, 0, 0, 0, 0, 0],
|
Result::ProcessID(pid) => [11, pid.get() as _, 0, 0, 0, 0, 0, 0],
|
||||||
|
|
@ -433,16 +415,7 @@ impl Result {
|
||||||
Result::Scalar2(a, b) => [15, *a, *b, 0, 0, 0, 0, 0],
|
Result::Scalar2(a, b) => [15, *a, *b, 0, 0, 0, 0, 0],
|
||||||
Result::NewServerID(sid, cid) => {
|
Result::NewServerID(sid, cid) => {
|
||||||
let s = sid.to_u32();
|
let s = sid.to_u32();
|
||||||
[
|
[8, s.0 as _, s.1 as _, s.2 as _, s.3 as _, *cid as usize, 0, 0]
|
||||||
8,
|
|
||||||
s.0 as _,
|
|
||||||
s.1 as _,
|
|
||||||
s.2 as _,
|
|
||||||
s.3 as _,
|
|
||||||
*cid as usize,
|
|
||||||
0,
|
|
||||||
0,
|
|
||||||
]
|
|
||||||
}
|
}
|
||||||
Result::RetryCall => [16, 0, 0, 0, 0, 0, 0, 0],
|
Result::RetryCall => [16, 0, 0, 0, 0, 0, 0, 0],
|
||||||
Result::None => [17, 0, 0, 0, 0, 0, 0, 0],
|
Result::None => [17, 0, 0, 0, 0, 0, 0, 0],
|
||||||
|
|
@ -460,9 +433,7 @@ impl Result {
|
||||||
Result::Scalar5(a, b, c, d, e) => [20, *a, *b, *c, *d, *e, 0, 0],
|
Result::Scalar5(a, b, c, d, e) => [20, *a, *b, *c, *d, *e, 0, 0],
|
||||||
Result::Message(message) => {
|
Result::Message(message) => {
|
||||||
let encoded = message.to_usize();
|
let encoded = message.to_usize();
|
||||||
[
|
[21, encoded[0], encoded[1], encoded[2], encoded[3], encoded[4], encoded[5], 0]
|
||||||
21, encoded[0], encoded[1], encoded[2], encoded[3], encoded[4], encoded[5], 0,
|
|
||||||
]
|
|
||||||
}
|
}
|
||||||
Result::UnknownResult(arg1, arg2, arg3, arg4, arg5, arg6, arg7) => {
|
Result::UnknownResult(arg1, arg2, arg3, arg4, arg5, arg6, arg7) => {
|
||||||
[usize::MAX, *arg1, *arg2, *arg3, *arg4, *arg5, *arg6, *arg7]
|
[usize::MAX, *arg1, *arg2, *arg3, *arg4, *arg5, *arg6, *arg7]
|
||||||
|
|
@ -492,12 +463,7 @@ impl Result {
|
||||||
}
|
}
|
||||||
4 => Result::ReadyThreads(src[1], src[2], src[3], src[4], src[5], src[6], src[7]),
|
4 => Result::ReadyThreads(src[1], src[2], src[3], src[4], src[5], src[6], src[7]),
|
||||||
5 => Result::ResumeProcess,
|
5 => Result::ResumeProcess,
|
||||||
6 => Result::ServerID(SID::from_u32(
|
6 => Result::ServerID(SID::from_u32(src[1] as _, src[2] as _, src[3] as _, src[4] as _)),
|
||||||
src[1] as _,
|
|
||||||
src[2] as _,
|
|
||||||
src[3] as _,
|
|
||||||
src[4] as _,
|
|
||||||
)),
|
|
||||||
7 => Result::ConnectionID(src[1] as CID),
|
7 => Result::ConnectionID(src[1] as CID),
|
||||||
8 => Result::NewServerID(
|
8 => Result::NewServerID(
|
||||||
SID::from_u32(src[1] as _, src[2] as _, src[3] as _, src[4] as _),
|
SID::from_u32(src[1] as _, src[2] as _, src[3] as _, src[4] as _),
|
||||||
|
|
@ -518,9 +484,7 @@ impl Result {
|
||||||
None => return Result::Error(Error::InternalError),
|
None => return Result::Error(Error::InternalError),
|
||||||
Some(s) => Message::Move(s),
|
Some(s) => Message::Move(s),
|
||||||
},
|
},
|
||||||
3 => Message::Scalar(ScalarMessage::from_usize(
|
3 => Message::Scalar(ScalarMessage::from_usize(src[3], src[4], src[5], src[6], src[7])),
|
||||||
src[3], src[4], src[5], src[6], src[7],
|
|
||||||
)),
|
|
||||||
4 => Message::BlockingScalar(ScalarMessage::from_usize(
|
4 => Message::BlockingScalar(ScalarMessage::from_usize(
|
||||||
src[3], src[4], src[5], src[6], src[7],
|
src[3], src[4], src[5], src[6], src[7],
|
||||||
)),
|
)),
|
||||||
|
|
@ -555,12 +519,10 @@ impl Result {
|
||||||
None => return Result::Error(Error::InternalError),
|
None => return Result::Error(Error::InternalError),
|
||||||
Some(s) => Message::Move(s),
|
Some(s) => Message::Move(s),
|
||||||
},
|
},
|
||||||
3 => Message::Scalar(ScalarMessage::from_usize(
|
3 => Message::Scalar(ScalarMessage::from_usize(src[2], src[3], src[4], src[5], src[6])),
|
||||||
src[2], src[3], src[4], src[5], src[6],
|
4 => {
|
||||||
)),
|
Message::BlockingScalar(ScalarMessage::from_usize(src[2], src[3], src[4], src[5], src[6]))
|
||||||
4 => Message::BlockingScalar(ScalarMessage::from_usize(
|
}
|
||||||
src[2], src[3], src[4], src[5], src[6],
|
|
||||||
)),
|
|
||||||
_ => return Result::Error(Error::InternalError),
|
_ => return Result::Error(Error::InternalError),
|
||||||
}),
|
}),
|
||||||
_ => Result::UnknownResult(src[0], src[1], src[2], src[3], src[4], src[5], src[6]),
|
_ => Result::UnknownResult(src[0], src[1], src[2], src[3], src[4], src[5], src[6]),
|
||||||
|
|
@ -578,9 +540,7 @@ impl Result {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl From<Error> for Result {
|
impl From<Error> for Result {
|
||||||
fn from(e: Error) -> Self {
|
fn from(e: Error) -> Self { Result::Error(e) }
|
||||||
Result::Error(e)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
pub type SysCallRequest = core::result::Result<crate::syscall::SysCall, Error>;
|
pub type SysCallRequest = core::result::Result<crate::syscall::SysCall, Error>;
|
||||||
|
|
@ -589,7 +549,7 @@ pub type SysCallResult = core::result::Result<Result, Error>;
|
||||||
#[macro_export]
|
#[macro_export]
|
||||||
macro_rules! msg_scalar_unpack {
|
macro_rules! msg_scalar_unpack {
|
||||||
// the args are `tt` so that you can specify _ as the arg
|
// the args are `tt` so that you can specify _ as the arg
|
||||||
($msg:ident, $arg1:tt, $arg2:tt, $arg3:tt, $arg4:tt, $body: block) => {{
|
($msg:ident, $arg1:tt, $arg2:tt, $arg3:tt, $arg4:tt, $body:block) => {{
|
||||||
if let xous::Message::Scalar(xous::ScalarMessage {
|
if let xous::Message::Scalar(xous::ScalarMessage {
|
||||||
id: _,
|
id: _,
|
||||||
arg1: $arg1,
|
arg1: $arg1,
|
||||||
|
|
@ -608,7 +568,7 @@ macro_rules! msg_scalar_unpack {
|
||||||
#[macro_export]
|
#[macro_export]
|
||||||
macro_rules! msg_blocking_scalar_unpack {
|
macro_rules! msg_blocking_scalar_unpack {
|
||||||
// the args are `tt` so that you can specify _ as the arg
|
// the args are `tt` so that you can specify _ as the arg
|
||||||
($msg:ident, $arg1:tt, $arg2:tt, $arg3:tt, $arg4:tt, $body: block) => {{
|
($msg:ident, $arg1:tt, $arg2:tt, $arg3:tt, $arg4:tt, $body:block) => {{
|
||||||
if let xous::Message::BlockingScalar(xous::ScalarMessage {
|
if let xous::Message::BlockingScalar(xous::ScalarMessage {
|
||||||
id: _,
|
id: _,
|
||||||
arg1: $arg1,
|
arg1: $arg1,
|
||||||
|
|
|
||||||
|
|
@ -2,4 +2,4 @@
|
||||||
pub enum Limits {
|
pub enum Limits {
|
||||||
HeapMaximum = 1,
|
HeapMaximum = 1,
|
||||||
HeapSize = 2,
|
HeapSize = 2,
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -7,51 +7,33 @@ pub struct MemoryFlags {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl MemoryFlags {
|
impl MemoryFlags {
|
||||||
|
/// Marks the page as the 'device' page for on-chip peripherals.
|
||||||
|
pub const DEV: Self = Self { bits: 0b0001_0000 };
|
||||||
const FLAGS_ALL: usize = 0b111111;
|
const FLAGS_ALL: usize = 0b111111;
|
||||||
|
|
||||||
/// Free this memory
|
/// Free this memory
|
||||||
pub const FREE: Self = Self { bits: 0b0000_0000 };
|
pub const FREE: Self = Self { bits: 0b0000_0000 };
|
||||||
|
/// Allow the CPU to read from this page.
|
||||||
|
pub const R: Self = Self { bits: 0b0000_0010 };
|
||||||
/// Immediately allocate this memory. Otherwise it will
|
/// Immediately allocate this memory. Otherwise it will
|
||||||
/// be demand-paged. This is implicitly set when `phys`
|
/// be demand-paged. This is implicitly set when `phys`
|
||||||
/// is not 0.
|
/// is not 0.
|
||||||
pub const RESERVE: Self = Self { bits: 0b0000_0001 };
|
pub const RESERVE: Self = Self { bits: 0b0000_0001 };
|
||||||
|
|
||||||
/// Allow the CPU to read from this page.
|
|
||||||
pub const R: Self = Self { bits: 0b0000_0010 };
|
|
||||||
|
|
||||||
/// Allow the CPU to write to this page.
|
/// Allow the CPU to write to this page.
|
||||||
pub const W: Self = Self { bits: 0b0000_0100 };
|
pub const W: Self = Self { bits: 0b0000_0100 };
|
||||||
|
|
||||||
/// Allow the CPU to execute from this page.
|
/// Allow the CPU to execute from this page.
|
||||||
pub const X: Self = Self { bits: 0b0000_1000 };
|
pub const X: Self = Self { bits: 0b0000_1000 };
|
||||||
|
|
||||||
/// Marks the page as the 'device' page for on-chip peripherals.
|
pub fn bits(&self) -> usize { self.bits }
|
||||||
pub const DEV: Self = Self { bits: 0b0001_0000 };
|
|
||||||
|
|
||||||
pub fn bits(&self) -> usize {
|
|
||||||
self.bits
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn from_bits(raw: usize) -> Option<MemoryFlags> {
|
pub fn from_bits(raw: usize) -> Option<MemoryFlags> {
|
||||||
if raw > Self::FLAGS_ALL {
|
if raw > Self::FLAGS_ALL { None } else { Some(MemoryFlags { bits: raw }) }
|
||||||
None
|
|
||||||
} else {
|
|
||||||
Some(MemoryFlags { bits: raw })
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn is_empty(&self) -> bool {
|
pub fn is_empty(&self) -> bool { self.bits == 0 }
|
||||||
self.bits == 0
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn empty() -> MemoryFlags {
|
pub fn empty() -> MemoryFlags { MemoryFlags { bits: 0 } }
|
||||||
MemoryFlags { bits: 0 }
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn all() -> MemoryFlags {
|
pub fn all() -> MemoryFlags { MemoryFlags { bits: Self::FLAGS_ALL } }
|
||||||
MemoryFlags { bits: Self::FLAGS_ALL }
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// impl core::fmt::Debug for MemoryFlags {
|
// impl core::fmt::Debug for MemoryFlags {
|
||||||
|
|
@ -87,15 +69,11 @@ impl MemoryFlags {
|
||||||
// }
|
// }
|
||||||
|
|
||||||
impl core::fmt::Binary for MemoryFlags {
|
impl core::fmt::Binary for MemoryFlags {
|
||||||
fn fmt(&self, f: &mut core::fmt::Formatter) -> core::fmt::Result {
|
fn fmt(&self, f: &mut core::fmt::Formatter) -> core::fmt::Result { core::fmt::Binary::fmt(&self.bits, f) }
|
||||||
core::fmt::Binary::fmt(&self.bits, f)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
impl core::fmt::Octal for MemoryFlags {
|
impl core::fmt::Octal for MemoryFlags {
|
||||||
fn fmt(&self, f: &mut core::fmt::Formatter) -> core::fmt::Result {
|
fn fmt(&self, f: &mut core::fmt::Formatter) -> core::fmt::Result { core::fmt::Octal::fmt(&self.bits, f) }
|
||||||
core::fmt::Octal::fmt(&self.bits, f)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
impl core::fmt::LowerHex for MemoryFlags {
|
impl core::fmt::LowerHex for MemoryFlags {
|
||||||
|
|
@ -115,19 +93,13 @@ impl core::ops::BitOr for MemoryFlags {
|
||||||
|
|
||||||
/// Returns the union of the two sets of flags.
|
/// Returns the union of the two sets of flags.
|
||||||
#[inline]
|
#[inline]
|
||||||
fn bitor(self, other: MemoryFlags) -> Self {
|
fn bitor(self, other: MemoryFlags) -> Self { Self { bits: self.bits | other.bits } }
|
||||||
Self {
|
|
||||||
bits: self.bits | other.bits,
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
impl core::ops::BitOrAssign for MemoryFlags {
|
impl core::ops::BitOrAssign for MemoryFlags {
|
||||||
/// Adds the set of flags.
|
/// Adds the set of flags.
|
||||||
#[inline]
|
#[inline]
|
||||||
fn bitor_assign(&mut self, other: Self) {
|
fn bitor_assign(&mut self, other: Self) { self.bits |= other.bits; }
|
||||||
self.bits |= other.bits;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
impl core::ops::BitXor for MemoryFlags {
|
impl core::ops::BitXor for MemoryFlags {
|
||||||
|
|
@ -135,19 +107,13 @@ impl core::ops::BitXor for MemoryFlags {
|
||||||
|
|
||||||
/// Returns the left flags, but with all the right flags toggled.
|
/// Returns the left flags, but with all the right flags toggled.
|
||||||
#[inline]
|
#[inline]
|
||||||
fn bitxor(self, other: Self) -> Self {
|
fn bitxor(self, other: Self) -> Self { Self { bits: self.bits ^ other.bits } }
|
||||||
Self {
|
|
||||||
bits: self.bits ^ other.bits,
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
impl core::ops::BitXorAssign for MemoryFlags {
|
impl core::ops::BitXorAssign for MemoryFlags {
|
||||||
/// Toggles the set of flags.
|
/// Toggles the set of flags.
|
||||||
#[inline]
|
#[inline]
|
||||||
fn bitxor_assign(&mut self, other: Self) {
|
fn bitxor_assign(&mut self, other: Self) { self.bits ^= other.bits; }
|
||||||
self.bits ^= other.bits;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
impl core::ops::BitAnd for MemoryFlags {
|
impl core::ops::BitAnd for MemoryFlags {
|
||||||
|
|
@ -155,19 +121,13 @@ impl core::ops::BitAnd for MemoryFlags {
|
||||||
|
|
||||||
/// Returns the intersection between the two sets of flags.
|
/// Returns the intersection between the two sets of flags.
|
||||||
#[inline]
|
#[inline]
|
||||||
fn bitand(self, other: Self) -> Self {
|
fn bitand(self, other: Self) -> Self { Self { bits: self.bits & other.bits } }
|
||||||
Self {
|
|
||||||
bits: self.bits & other.bits,
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
impl core::ops::BitAndAssign for MemoryFlags {
|
impl core::ops::BitAndAssign for MemoryFlags {
|
||||||
/// Disables all flags disabled in the set.
|
/// Disables all flags disabled in the set.
|
||||||
#[inline]
|
#[inline]
|
||||||
fn bitand_assign(&mut self, other: Self) {
|
fn bitand_assign(&mut self, other: Self) { self.bits &= other.bits; }
|
||||||
self.bits &= other.bits;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
impl core::ops::Sub for MemoryFlags {
|
impl core::ops::Sub for MemoryFlags {
|
||||||
|
|
@ -175,19 +135,13 @@ impl core::ops::Sub for MemoryFlags {
|
||||||
|
|
||||||
/// Returns the set difference of the two sets of flags.
|
/// Returns the set difference of the two sets of flags.
|
||||||
#[inline]
|
#[inline]
|
||||||
fn sub(self, other: Self) -> Self {
|
fn sub(self, other: Self) -> Self { Self { bits: self.bits & !other.bits } }
|
||||||
Self {
|
|
||||||
bits: self.bits & !other.bits,
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
impl core::ops::SubAssign for MemoryFlags {
|
impl core::ops::SubAssign for MemoryFlags {
|
||||||
/// Disables all flags enabled in the set.
|
/// Disables all flags enabled in the set.
|
||||||
#[inline]
|
#[inline]
|
||||||
fn sub_assign(&mut self, other: Self) {
|
fn sub_assign(&mut self, other: Self) { self.bits &= !other.bits; }
|
||||||
self.bits &= !other.bits;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
impl core::ops::Not for MemoryFlags {
|
impl core::ops::Not for MemoryFlags {
|
||||||
|
|
@ -195,7 +149,5 @@ impl core::ops::Not for MemoryFlags {
|
||||||
|
|
||||||
/// Returns the complement of this set of flags.
|
/// Returns the complement of this set of flags.
|
||||||
#[inline]
|
#[inline]
|
||||||
fn not(self) -> Self {
|
fn not(self) -> Self { Self { bits: !self.bits } & MemoryFlags { bits: 15 } }
|
||||||
Self { bits: !self.bits } & MemoryFlags { bits: 15 }
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -19,21 +19,13 @@ impl MemoryRange {
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn len(&self) -> usize {
|
pub fn len(&self) -> usize { self.size.get() }
|
||||||
self.size.get()
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn is_empty(&self) -> bool {
|
pub fn is_empty(&self) -> bool { self.size.get() > 0 }
|
||||||
self.size.get() > 0
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn as_ptr(&self) -> *const u8 {
|
pub fn as_ptr(&self) -> *const u8 { self.addr.get() as *const u8 }
|
||||||
self.addr.get() as *const u8
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn as_mut_ptr(&self) -> *mut u8 {
|
pub fn as_mut_ptr(&self) -> *mut u8 { self.addr.get() as *mut u8 }
|
||||||
self.addr.get() as *mut u8
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Return this memory as a slice of values. The resulting slice
|
/// Return this memory as a slice of values. The resulting slice
|
||||||
/// will cover the maximum number of elements given the size of `T`.
|
/// will cover the maximum number of elements given the size of `T`.
|
||||||
|
|
@ -51,10 +43,7 @@ impl MemoryRange {
|
||||||
// be valid, as long as the user hasn't already called `as_ptr()`
|
// be valid, as long as the user hasn't already called `as_ptr()`
|
||||||
// and done something unsound with the resulting pointer.
|
// and done something unsound with the resulting pointer.
|
||||||
unsafe {
|
unsafe {
|
||||||
core::slice::from_raw_parts(
|
core::slice::from_raw_parts(self.as_ptr() as *const T, self.len() / core::mem::size_of::<T>())
|
||||||
self.as_ptr() as *const T,
|
|
||||||
self.len() / core::mem::size_of::<T>(),
|
|
||||||
)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -40,9 +40,7 @@ impl Envelope {
|
||||||
unsafe { core::ptr::read(&manual_self.body) }
|
unsafe { core::ptr::read(&manual_self.body) }
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn id(&self) -> MessageId {
|
pub fn id(&self) -> MessageId { self.body.id() }
|
||||||
self.body.id()
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Take this message and forward it to another server.
|
/// Take this message and forward it to another server.
|
||||||
///
|
///
|
||||||
|
|
@ -56,11 +54,7 @@ impl Envelope {
|
||||||
///
|
///
|
||||||
/// If there is an error, then the original Envelope is returned along with the resulting
|
/// If there is an error, then the original Envelope is returned along with the resulting
|
||||||
/// error.
|
/// error.
|
||||||
pub fn forward(
|
pub fn forward(mut self, connection: CID, id: MessageId) -> Result<(), (Envelope, crate::Error)> {
|
||||||
mut self,
|
|
||||||
connection: CID,
|
|
||||||
id: MessageId,
|
|
||||||
) -> Result<(), (Envelope, crate::Error)> {
|
|
||||||
use core::mem::ManuallyDrop;
|
use core::mem::ManuallyDrop;
|
||||||
|
|
||||||
// Update our ID to match the newly-sent message. Reuse the same message struct.
|
// Update our ID to match the newly-sent message. Reuse the same message struct.
|
||||||
|
|
@ -91,10 +85,7 @@ impl Envelope {
|
||||||
return Err((ManuallyDrop::into_inner(manual_self), e));
|
return Err((ManuallyDrop::into_inner(manual_self), e));
|
||||||
}
|
}
|
||||||
|
|
||||||
Err((
|
Err((ManuallyDrop::into_inner(manual_self), crate::Error::MemoryInUse))
|
||||||
ManuallyDrop::into_inner(manual_self),
|
|
||||||
crate::Error::MemoryInUse,
|
|
||||||
))
|
|
||||||
}
|
}
|
||||||
Message::BlockingScalar(_) => {
|
Message::BlockingScalar(_) => {
|
||||||
let result = crate::send_message(connection, body);
|
let result = crate::send_message(connection, body);
|
||||||
|
|
@ -113,10 +104,7 @@ impl Envelope {
|
||||||
}
|
}
|
||||||
return Ok(());
|
return Ok(());
|
||||||
}
|
}
|
||||||
Err((
|
Err((ManuallyDrop::into_inner(manual_self), crate::Error::MemoryInUse))
|
||||||
ManuallyDrop::into_inner(manual_self),
|
|
||||||
crate::Error::MemoryInUse,
|
|
||||||
))
|
|
||||||
}
|
}
|
||||||
|
|
||||||
Message::Borrow(_) | Message::MutableBorrow(_) | Message::Scalar(_) => {
|
Message::Borrow(_) | Message::MutableBorrow(_) | Message::Scalar(_) => {
|
||||||
|
|
|
||||||
|
|
@ -1 +1 @@
|
||||||
pub type Id = usize;
|
pub type Id = usize;
|
||||||
|
|
|
||||||
|
|
@ -73,13 +73,9 @@ impl MemoryMessage {
|
||||||
let offset = MemoryAddress::new(offset);
|
let offset = MemoryAddress::new(offset);
|
||||||
let valid = MemorySize::new(valid);
|
let valid = MemorySize::new(valid);
|
||||||
|
|
||||||
Some(MemoryMessage {
|
Some(MemoryMessage { id, buf, offset, valid })
|
||||||
id,
|
|
||||||
buf,
|
|
||||||
offset,
|
|
||||||
valid,
|
|
||||||
})
|
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn to_usize(&self) -> [usize; 5] {
|
pub fn to_usize(&self) -> [usize; 5] {
|
||||||
[
|
[
|
||||||
self.id,
|
self.id,
|
||||||
|
|
@ -103,24 +99,11 @@ pub struct ScalarMessage {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl ScalarMessage {
|
impl ScalarMessage {
|
||||||
pub fn from_usize(
|
pub fn from_usize(id: usize, arg1: usize, arg2: usize, arg3: usize, arg4: usize) -> ScalarMessage {
|
||||||
id: usize,
|
ScalarMessage { id, arg1, arg2, arg3, arg4 }
|
||||||
arg1: usize,
|
|
||||||
arg2: usize,
|
|
||||||
arg3: usize,
|
|
||||||
arg4: usize,
|
|
||||||
) -> ScalarMessage {
|
|
||||||
ScalarMessage {
|
|
||||||
id,
|
|
||||||
arg1,
|
|
||||||
arg2,
|
|
||||||
arg3,
|
|
||||||
arg4,
|
|
||||||
}
|
|
||||||
}
|
|
||||||
pub fn to_usize(&self) -> [usize; 5] {
|
|
||||||
[self.id, self.arg1, self.arg2, self.arg3, self.arg4]
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn to_usize(&self) -> [usize; 5] { [self.id, self.arg1, self.arg2, self.arg3, self.arg4] }
|
||||||
}
|
}
|
||||||
|
|
||||||
#[repr(usize)]
|
#[repr(usize)]
|
||||||
|
|
@ -135,20 +118,8 @@ pub enum Message {
|
||||||
unsafe impl Send for Message {}
|
unsafe impl Send for Message {}
|
||||||
|
|
||||||
impl Message {
|
impl Message {
|
||||||
pub fn new_scalar(
|
pub fn new_scalar(id: usize, arg1: usize, arg2: usize, arg3: usize, arg4: usize) -> crate::Message {
|
||||||
id: usize,
|
Message::Scalar(crate::ScalarMessage { id, arg1, arg2, arg3, arg4 })
|
||||||
arg1: usize,
|
|
||||||
arg2: usize,
|
|
||||||
arg3: usize,
|
|
||||||
arg4: usize,
|
|
||||||
) -> crate::Message {
|
|
||||||
Message::Scalar(crate::ScalarMessage {
|
|
||||||
id,
|
|
||||||
arg1,
|
|
||||||
arg2,
|
|
||||||
arg3,
|
|
||||||
arg4,
|
|
||||||
})
|
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn new_blocking_scalar(
|
pub fn new_blocking_scalar(
|
||||||
|
|
@ -158,13 +129,7 @@ impl Message {
|
||||||
arg3: usize,
|
arg3: usize,
|
||||||
arg4: usize,
|
arg4: usize,
|
||||||
) -> crate::Message {
|
) -> crate::Message {
|
||||||
Message::BlockingScalar(crate::ScalarMessage {
|
Message::BlockingScalar(crate::ScalarMessage { id, arg1, arg2, arg3, arg4 })
|
||||||
id,
|
|
||||||
arg1,
|
|
||||||
arg2,
|
|
||||||
arg3,
|
|
||||||
arg4,
|
|
||||||
})
|
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn new_lend(
|
pub fn new_lend(
|
||||||
|
|
@ -173,12 +138,7 @@ impl Message {
|
||||||
offset: Option<MemoryAddress>,
|
offset: Option<MemoryAddress>,
|
||||||
valid: Option<MemorySize>,
|
valid: Option<MemorySize>,
|
||||||
) -> crate::Message {
|
) -> crate::Message {
|
||||||
Message::Borrow(crate::MemoryMessage {
|
Message::Borrow(crate::MemoryMessage { id, buf, offset, valid })
|
||||||
id,
|
|
||||||
buf,
|
|
||||||
offset,
|
|
||||||
valid,
|
|
||||||
})
|
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn new_lend_mut(
|
pub fn new_lend_mut(
|
||||||
|
|
@ -187,12 +147,7 @@ impl Message {
|
||||||
offset: Option<MemoryAddress>,
|
offset: Option<MemoryAddress>,
|
||||||
valid: Option<MemorySize>,
|
valid: Option<MemorySize>,
|
||||||
) -> crate::Message {
|
) -> crate::Message {
|
||||||
Message::MutableBorrow(crate::MemoryMessage {
|
Message::MutableBorrow(crate::MemoryMessage { id, buf, offset, valid })
|
||||||
id,
|
|
||||||
buf,
|
|
||||||
offset,
|
|
||||||
valid,
|
|
||||||
})
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Determine whether the specified Message will block
|
/// Determine whether the specified Message will block
|
||||||
|
|
@ -211,13 +166,9 @@ impl Message {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn is_scalar(&self) -> bool {
|
pub fn is_scalar(&self) -> bool { !self.has_memory() }
|
||||||
!self.has_memory()
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn memory(&self) -> Option<&MemoryRange> {
|
pub fn memory(&self) -> Option<&MemoryRange> { self.memory_message().map(|msg| &msg.buf) }
|
||||||
self.memory_message().map(|msg| &msg.buf)
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn memory_message(&self) -> Option<&MemoryMessage> {
|
pub fn memory_message(&self) -> Option<&MemoryMessage> {
|
||||||
match self {
|
match self {
|
||||||
|
|
@ -242,13 +193,11 @@ impl Message {
|
||||||
|
|
||||||
pub fn scalar_message_mut(&mut self) -> Option<&mut ScalarMessage> {
|
pub fn scalar_message_mut(&mut self) -> Option<&mut ScalarMessage> {
|
||||||
match self {
|
match self {
|
||||||
Message::MutableBorrow(_)
|
Message::MutableBorrow(_) | Message::Borrow(_) | Message::Move(_) | Message::Scalar(_) => None,
|
||||||
| Message::Borrow(_)
|
|
||||||
| Message::Move(_)
|
|
||||||
| Message::Scalar(_) => None,
|
|
||||||
Message::BlockingScalar(scalar) => Some(scalar),
|
Message::BlockingScalar(scalar) => Some(scalar),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub(crate) fn message_type(&self) -> usize {
|
pub(crate) fn message_type(&self) -> usize {
|
||||||
match *self {
|
match *self {
|
||||||
Message::MutableBorrow(_) => 1,
|
Message::MutableBorrow(_) => 1,
|
||||||
|
|
@ -283,14 +232,13 @@ impl Message {
|
||||||
Message::Scalar(m) => (3, m.to_usize()),
|
Message::Scalar(m) => (3, m.to_usize()),
|
||||||
Message::BlockingScalar(m) => (4, m.to_usize()),
|
Message::BlockingScalar(m) => (4, m.to_usize()),
|
||||||
};
|
};
|
||||||
[
|
[ret.0, ret.1[0], ret.1[1], ret.1[2], ret.1[3], ret.1[4]]
|
||||||
ret.0, ret.1[0], ret.1[1], ret.1[2], ret.1[3], ret.1[4],
|
|
||||||
]
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl TryFrom<(usize, usize, usize, usize, usize, usize)> for Message {
|
impl TryFrom<(usize, usize, usize, usize, usize, usize)> for Message {
|
||||||
type Error = ();
|
type Error = ();
|
||||||
|
|
||||||
fn try_from(
|
fn try_from(
|
||||||
value: (usize, usize, usize, usize, usize, usize),
|
value: (usize, usize, usize, usize, usize, usize),
|
||||||
) -> core::result::Result<Self, Self::Error> {
|
) -> core::result::Result<Self, Self::Error> {
|
||||||
|
|
|
||||||
|
|
@ -6,13 +6,9 @@ pub struct Sender {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Sender {
|
impl Sender {
|
||||||
pub fn to_usize(&self) -> usize {
|
pub fn to_usize(&self) -> usize { self.data }
|
||||||
self.data
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn from_usize(data: usize) -> Self {
|
pub fn from_usize(data: usize) -> Self { Sender { data } }
|
||||||
Sender { data }
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn pid(&self) -> Option<PID> {
|
pub fn pid(&self) -> Option<PID> {
|
||||||
let pid_u8 = ((self.data >> 24) & 0xff) as u8;
|
let pid_u8 = ((self.data >> 24) & 0xff) as u8;
|
||||||
|
|
|
||||||
|
|
@ -16,6 +16,4 @@ pub fn id() -> u32 {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn set_id(id: u32) {
|
pub fn set_id(id: u32) { CACHED_PID.store(id, Ordering::Relaxed); }
|
||||||
CACHED_PID.store(id, Ordering::Relaxed);
|
|
||||||
}
|
|
||||||
|
|
|
||||||
|
|
@ -1 +1 @@
|
||||||
pub mod nameserver;
|
pub mod nameserver;
|
||||||
|
|
|
||||||
|
|
@ -12,13 +12,7 @@ struct ConnectRequest {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Default for ConnectRequest {
|
impl Default for ConnectRequest {
|
||||||
fn default() -> Self {
|
fn default() -> Self { ConnectRequest { name: [0u8; 64], len: 0, _padding: [0u8; 4096 - 4 - 64] } }
|
||||||
ConnectRequest {
|
|
||||||
name: [0u8; 64],
|
|
||||||
len: 0,
|
|
||||||
_padding: [0u8; 4096 - 4 - 64],
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
impl ConnectRequest {
|
impl ConnectRequest {
|
||||||
|
|
@ -45,11 +39,7 @@ impl ConnectRequest {
|
||||||
return None;
|
return None;
|
||||||
}
|
}
|
||||||
|
|
||||||
if cr.len == 0 {
|
if cr.len == 0 { None } else { Some(cr) }
|
||||||
None
|
|
||||||
} else {
|
|
||||||
Some(cr)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -7,28 +7,17 @@ pub struct String<const N: usize> {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<const N: usize> String<N> {
|
impl<const N: usize> String<N> {
|
||||||
pub fn new() -> String<N> {
|
pub fn new() -> String<N> { String { bytes: [0; N], len: 0 } }
|
||||||
String {
|
|
||||||
bytes: [0; N],
|
|
||||||
len: 0,
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn as_bytes(&self) -> [u8; N] {
|
pub fn as_bytes(&self) -> [u8; N] { self.bytes }
|
||||||
self.bytes
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn as_str(&self) -> core::result::Result<&str, core::str::Utf8Error> {
|
pub fn as_str(&self) -> core::result::Result<&str, core::str::Utf8Error> {
|
||||||
core::str::from_utf8(&self.bytes[0..self.len as usize])
|
core::str::from_utf8(&self.bytes[0..self.len as usize])
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn len(&self) -> usize {
|
pub fn len(&self) -> usize { self.len as usize }
|
||||||
self.len as usize
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn is_empty(&self) -> bool {
|
pub fn is_empty(&self) -> bool { self.len == 0 }
|
||||||
self.len == 0
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Clear the contents of this String and set the length to 0
|
/// Clear the contents of this String and set the length to 0
|
||||||
pub fn clear(&mut self) {
|
pub fn clear(&mut self) {
|
||||||
|
|
@ -36,9 +25,7 @@ impl<const N: usize> String<N> {
|
||||||
self.bytes = [0; N];
|
self.bytes = [0; N];
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn to_str(&self) -> &str {
|
pub fn to_str(&self) -> &str { unsafe { core::str::from_utf8_unchecked(&self.bytes[0..self.len()]) } }
|
||||||
unsafe { core::str::from_utf8_unchecked(&self.bytes[0..self.len()]) }
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn push(&mut self, ch: char) -> core::result::Result<usize, Error> {
|
pub fn push(&mut self, ch: char) -> core::result::Result<usize, Error> {
|
||||||
match ch.len_utf8() {
|
match ch.len_utf8() {
|
||||||
|
|
@ -93,13 +80,12 @@ impl<const N: usize> String<N> {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<const N: usize> Default for String<N> {
|
impl<const N: usize> Default for String<N> {
|
||||||
fn default() -> Self {
|
fn default() -> Self { Self::new() }
|
||||||
Self::new()
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<const N: usize> core::str::FromStr for String<N> {
|
impl<const N: usize> core::str::FromStr for String<N> {
|
||||||
type Err = &'static str;
|
type Err = &'static str;
|
||||||
|
|
||||||
fn from_str(src: &str) -> core::result::Result<String<N>, &'static str> {
|
fn from_str(src: &str) -> core::result::Result<String<N>, &'static str> {
|
||||||
let mut s = Self::new();
|
let mut s = Self::new();
|
||||||
// Copy the string into our backing store.
|
// Copy the string into our backing store.
|
||||||
|
|
@ -119,9 +105,7 @@ impl<const N: usize> core::str::FromStr for String<N> {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<const N: usize> core::fmt::Display for String<N> {
|
impl<const N: usize> core::fmt::Display for String<N> {
|
||||||
fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
|
fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result { write!(f, "{}", self.to_str()) }
|
||||||
write!(f, "{}", self.to_str())
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<const N: usize> core::fmt::Write for String<N> {
|
impl<const N: usize> core::fmt::Write for String<N> {
|
||||||
|
|
@ -137,21 +121,16 @@ impl<const N: usize> core::fmt::Write for String<N> {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<const N: usize> core::fmt::Debug for String<N> {
|
impl<const N: usize> core::fmt::Debug for String<N> {
|
||||||
fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
|
fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result { write!(f, "{}", self.to_str()) }
|
||||||
write!(f, "{}", self.to_str())
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<const N: usize> core::convert::AsRef<str> for String<N> {
|
impl<const N: usize> core::convert::AsRef<str> for String<N> {
|
||||||
fn as_ref(&self) -> &str {
|
fn as_ref(&self) -> &str { self.to_str() }
|
||||||
self.to_str()
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<const N: usize> PartialEq for String<N> {
|
impl<const N: usize> PartialEq for String<N> {
|
||||||
fn eq(&self, other: &Self) -> bool {
|
fn eq(&self, other: &Self) -> bool {
|
||||||
self.bytes[..self.len as usize] == other.bytes[..other.len as usize]
|
self.bytes[..self.len as usize] == other.bytes[..other.len as usize] && self.len == other.len
|
||||||
&& self.len == other.len
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,6 @@
|
||||||
use crate::{
|
use crate::{
|
||||||
map_memory, send_message, unmap_memory, Error, MemoryMessage, MemoryRange, MemorySize, Message,
|
map_memory, send_message, unmap_memory, Error, MemoryMessage, MemoryRange, MemorySize, Message, Result,
|
||||||
Result, CID,
|
CID,
|
||||||
};
|
};
|
||||||
|
|
||||||
/// A buffered String suitable for sending across as a message
|
/// A buffered String suitable for sending across as a message
|
||||||
|
|
@ -26,23 +26,13 @@ pub struct StringBuffer<'a> {
|
||||||
impl<'a> StringBuffer<'a> {
|
impl<'a> StringBuffer<'a> {
|
||||||
/// Create a new StringBuffer with no backing. This will get
|
/// Create a new StringBuffer with no backing. This will get
|
||||||
/// resized as soon as data is written to it.
|
/// resized as soon as data is written to it.
|
||||||
pub fn new() -> Self {
|
pub fn new() -> Self { StringBuffer { bytes: None, length: 0, should_free: true, memory_message: None } }
|
||||||
StringBuffer {
|
|
||||||
bytes: None,
|
|
||||||
length: 0,
|
|
||||||
should_free: true,
|
|
||||||
memory_message: None,
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Create a new StringBuffer with enough space to hold
|
/// Create a new StringBuffer with enough space to hold
|
||||||
/// `usize` characters
|
/// `usize` characters
|
||||||
pub fn with_capacity(capacity: usize) -> Self {
|
pub fn with_capacity(capacity: usize) -> Self {
|
||||||
let remainder = if ((capacity & 0xFFF) == 0) && (capacity > 0) {
|
let remainder =
|
||||||
0
|
if ((capacity & 0xFFF) == 0) && (capacity > 0) { 0 } else { 0x1000 - (capacity & 0xFFF) };
|
||||||
} else {
|
|
||||||
0x1000 - (capacity & 0xFFF)
|
|
||||||
};
|
|
||||||
|
|
||||||
let flags = crate::MemoryFlags::R | crate::MemoryFlags::W;
|
let flags = crate::MemoryFlags::R | crate::MemoryFlags::W;
|
||||||
|
|
||||||
|
|
@ -90,14 +80,10 @@ impl<'a> StringBuffer<'a> {
|
||||||
let new_slice = if rounded_new_capacity > 0 {
|
let new_slice = if rounded_new_capacity > 0 {
|
||||||
let new_mem = map_memory(None, None, rounded_new_capacity, flags)
|
let new_mem = map_memory(None, None, rounded_new_capacity, flags)
|
||||||
.expect("Buffer: error in new()/map_memory");
|
.expect("Buffer: error in new()/map_memory");
|
||||||
let new_slice = unsafe {
|
let new_slice =
|
||||||
core::slice::from_raw_parts_mut(new_mem.as_mut_ptr(), rounded_new_capacity)
|
unsafe { core::slice::from_raw_parts_mut(new_mem.as_mut_ptr(), rounded_new_capacity) };
|
||||||
};
|
|
||||||
// Copy the existing string to the new slice
|
// Copy the existing string to the new slice
|
||||||
for (dest_byte, src_byte) in new_slice
|
for (dest_byte, src_byte) in new_slice.iter_mut().zip(self.as_bytes()[0..self.len()].iter()) {
|
||||||
.iter_mut()
|
|
||||||
.zip(self.as_bytes()[0..self.len()].iter())
|
|
||||||
{
|
|
||||||
*dest_byte = *src_byte;
|
*dest_byte = *src_byte;
|
||||||
}
|
}
|
||||||
Some(new_slice)
|
Some(new_slice)
|
||||||
|
|
@ -108,8 +94,7 @@ impl<'a> StringBuffer<'a> {
|
||||||
if let Some(old_slice) = self.bytes.take() {
|
if let Some(old_slice) = self.bytes.take() {
|
||||||
let old_addr = old_slice.as_ptr();
|
let old_addr = old_slice.as_ptr();
|
||||||
let old_length = old_slice.len();
|
let old_length = old_slice.len();
|
||||||
unmap_memory(unsafe { MemoryRange::new(old_addr as usize, old_length).unwrap() })
|
unmap_memory(unsafe { MemoryRange::new(old_addr as usize, old_length).unwrap() }).unwrap();
|
||||||
.unwrap();
|
|
||||||
}
|
}
|
||||||
self.bytes = new_slice;
|
self.bytes = new_slice;
|
||||||
|
|
||||||
|
|
@ -119,37 +104,19 @@ impl<'a> StringBuffer<'a> {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn as_bytes(&self) -> &[u8] {
|
pub fn as_bytes(&self) -> &[u8] { if let Some(bytes) = &self.bytes { bytes } else { &[] } }
|
||||||
if let Some(bytes) = &self.bytes {
|
|
||||||
bytes
|
|
||||||
} else {
|
|
||||||
&[]
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn as_bytes_mut(&mut self) -> &mut [u8] {
|
pub fn as_bytes_mut(&mut self) -> &mut [u8] {
|
||||||
if let Some(bytes) = self.bytes.as_mut() {
|
if let Some(bytes) = self.bytes.as_mut() { bytes } else { &mut [] }
|
||||||
bytes
|
|
||||||
} else {
|
|
||||||
&mut []
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn as_str(&self) -> core::result::Result<&str, core::str::Utf8Error> {
|
pub fn as_str(&self) -> core::result::Result<&str, core::str::Utf8Error> {
|
||||||
if let Some(bytes) = &self.bytes {
|
if let Some(bytes) = &self.bytes { core::str::from_utf8(&bytes[0..self.len()]) } else { Ok("") }
|
||||||
core::str::from_utf8(&bytes[0..self.len()])
|
|
||||||
} else {
|
|
||||||
Ok("")
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn len(&self) -> usize {
|
pub fn len(&self) -> usize { self.length as usize }
|
||||||
self.length as usize
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn is_empty(&self) -> bool {
|
pub fn is_empty(&self) -> bool { self.length == 0 }
|
||||||
self.length == 0
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Clear the contents of this String and set the length to 0
|
/// Clear the contents of this String and set the length to 0
|
||||||
pub fn clear(&mut self) {
|
pub fn clear(&mut self) {
|
||||||
|
|
@ -169,8 +136,7 @@ impl<'a> StringBuffer<'a> {
|
||||||
|
|
||||||
fn create_memory_message(&self, id: u32) -> MemoryMessage {
|
fn create_memory_message(&self, id: u32) -> MemoryMessage {
|
||||||
if let Some(bytes) = &self.bytes {
|
if let Some(bytes) = &self.bytes {
|
||||||
let backing_store =
|
let backing_store = unsafe { MemoryRange::new(bytes.as_ptr() as _, bytes.len()).unwrap() };
|
||||||
unsafe { MemoryRange::new(bytes.as_ptr() as _, bytes.len()).unwrap() };
|
|
||||||
MemoryMessage {
|
MemoryMessage {
|
||||||
id: id as usize,
|
id: id as usize,
|
||||||
buf: backing_store,
|
buf: backing_store,
|
||||||
|
|
@ -189,10 +155,7 @@ impl<'a> StringBuffer<'a> {
|
||||||
pub unsafe fn from_memory_message(mem: &'a MemoryMessage) -> Self {
|
pub unsafe fn from_memory_message(mem: &'a MemoryMessage) -> Self {
|
||||||
StringBuffer {
|
StringBuffer {
|
||||||
// range: mem.buf,
|
// range: mem.buf,
|
||||||
bytes: Some(core::slice::from_raw_parts_mut(
|
bytes: Some(core::slice::from_raw_parts_mut(mem.buf.as_mut_ptr(), mem.buf.len())),
|
||||||
mem.buf.as_mut_ptr(),
|
|
||||||
mem.buf.len(),
|
|
||||||
)),
|
|
||||||
length: mem.valid.map(|v| v.get()).unwrap_or(0) as u32,
|
length: mem.valid.map(|v| v.get()).unwrap_or(0) as u32,
|
||||||
// offset: mem.offset,
|
// offset: mem.offset,
|
||||||
should_free: false,
|
should_free: false,
|
||||||
|
|
@ -207,10 +170,7 @@ impl<'a> StringBuffer<'a> {
|
||||||
pub unsafe fn from_memory_message_mut(mem: &'a mut MemoryMessage) -> Self {
|
pub unsafe fn from_memory_message_mut(mem: &'a mut MemoryMessage) -> Self {
|
||||||
StringBuffer {
|
StringBuffer {
|
||||||
// range: mem.buf,
|
// range: mem.buf,
|
||||||
bytes: Some(core::slice::from_raw_parts_mut(
|
bytes: Some(core::slice::from_raw_parts_mut(mem.buf.as_mut_ptr(), mem.buf.len())),
|
||||||
mem.buf.as_mut_ptr(),
|
|
||||||
mem.buf.len(),
|
|
||||||
)),
|
|
||||||
length: mem.valid.map(|v| v.get()).unwrap_or(0) as u32,
|
length: mem.valid.map(|v| v.get()).unwrap_or(0) as u32,
|
||||||
// valid: mem.buf,
|
// valid: mem.buf,
|
||||||
// offset: mem.offset,
|
// offset: mem.offset,
|
||||||
|
|
@ -249,6 +209,7 @@ impl<'a> StringBuffer<'a> {
|
||||||
|
|
||||||
impl<'a> core::str::FromStr for StringBuffer<'a> {
|
impl<'a> core::str::FromStr for StringBuffer<'a> {
|
||||||
type Err = &'static str;
|
type Err = &'static str;
|
||||||
|
|
||||||
fn from_str(src: &str) -> core::result::Result<StringBuffer<'a>, &'static str> {
|
fn from_str(src: &str) -> core::result::Result<StringBuffer<'a>, &'static str> {
|
||||||
let mut s = Self::with_capacity(src.len());
|
let mut s = Self::with_capacity(src.len());
|
||||||
// Copy the string into our backing store.
|
// Copy the string into our backing store.
|
||||||
|
|
@ -269,15 +230,11 @@ impl<'a> core::str::FromStr for StringBuffer<'a> {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<'a> Default for StringBuffer<'a> {
|
impl<'a> Default for StringBuffer<'a> {
|
||||||
fn default() -> Self {
|
fn default() -> Self { Self::new() }
|
||||||
Self::new()
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<'a> core::fmt::Display for StringBuffer<'a> {
|
impl<'a> core::fmt::Display for StringBuffer<'a> {
|
||||||
fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
|
fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result { write!(f, "{}", self.to_str()) }
|
||||||
write!(f, "{}", self.to_str())
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<'a> core::fmt::Write for StringBuffer<'a> {
|
impl<'a> core::fmt::Write for StringBuffer<'a> {
|
||||||
|
|
@ -299,21 +256,16 @@ impl<'a> core::fmt::Write for StringBuffer<'a> {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<'a> core::fmt::Debug for StringBuffer<'a> {
|
impl<'a> core::fmt::Debug for StringBuffer<'a> {
|
||||||
fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
|
fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result { write!(f, "{}", self.to_str()) }
|
||||||
write!(f, "{}", self.to_str())
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<'a> core::convert::AsRef<str> for StringBuffer<'a> {
|
impl<'a> core::convert::AsRef<str> for StringBuffer<'a> {
|
||||||
fn as_ref(&self) -> &str {
|
fn as_ref(&self) -> &str { self.to_str() }
|
||||||
self.to_str()
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<'a> PartialEq for StringBuffer<'a> {
|
impl<'a> PartialEq for StringBuffer<'a> {
|
||||||
fn eq(&self, other: &Self) -> bool {
|
fn eq(&self, other: &Self) -> bool {
|
||||||
self.length == other.length
|
self.length == other.length && self.as_bytes()[..self.len()] == other.as_bytes()[..other.len()]
|
||||||
&& self.as_bytes()[..self.len()] == other.as_bytes()[..other.len()]
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -322,9 +274,8 @@ impl<'a> Eq for StringBuffer<'a> {}
|
||||||
impl<'a> Drop for StringBuffer<'a> {
|
impl<'a> Drop for StringBuffer<'a> {
|
||||||
fn drop(&mut self) {
|
fn drop(&mut self) {
|
||||||
if self.should_free && !self.as_bytes().is_empty() {
|
if self.should_free && !self.as_bytes().is_empty() {
|
||||||
let range = unsafe {
|
let range =
|
||||||
MemoryRange::new(self.as_bytes().as_ptr() as _, self.as_bytes().len()).unwrap()
|
unsafe { MemoryRange::new(self.as_bytes().as_ptr() as _, self.as_bytes().len()).unwrap() };
|
||||||
};
|
|
||||||
unmap_memory(range).expect("Buffer: failed to drop memory");
|
unmap_memory(range).expect("Buffer: failed to drop memory");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,18 +1,17 @@
|
||||||
use crate::{
|
|
||||||
pid_from_usize, CpuID, Error, MemoryAddress, MemoryFlags, MemoryMessage, MemoryRange,
|
|
||||||
MemorySize, MemoryType, Message, MessageEnvelope, MessageSender, ProcessArgs, ProcessInit,
|
|
||||||
Result, ScalarMessage, SysCallResult, ThreadInit, CID, PID, SID, TID,
|
|
||||||
};
|
|
||||||
use core::convert::{TryFrom, TryInto};
|
use core::convert::{TryFrom, TryInto};
|
||||||
|
|
||||||
/* https://github.com/betrusted-io/xous-core/issues/90
|
/* https://github.com/betrusted-io/xous-core/issues/90
|
||||||
use crate::Exception
|
use crate::Exception
|
||||||
*/
|
*/
|
||||||
|
|
||||||
// use num_derive::FromPrimitive;
|
// use num_derive::FromPrimitive;
|
||||||
// use num_traits::FromPrimitive;
|
// use num_traits::FromPrimitive;
|
||||||
|
|
||||||
#[cfg(feature = "processes-as-threads")]
|
#[cfg(feature = "processes-as-threads")]
|
||||||
pub use crate::arch::ProcessArgsAsThread;
|
pub use crate::arch::ProcessArgsAsThread;
|
||||||
|
use crate::{
|
||||||
|
pid_from_usize, CpuID, Error, MemoryAddress, MemoryFlags, MemoryMessage, MemoryRange, MemorySize,
|
||||||
|
MemoryType, Message, MessageEnvelope, MessageSender, ProcessArgs, ProcessInit, Result, ScalarMessage,
|
||||||
|
SysCallResult, ThreadInit, CID, PID, SID, TID,
|
||||||
|
};
|
||||||
|
|
||||||
#[derive(Debug, PartialEq)]
|
#[derive(Debug, PartialEq)]
|
||||||
pub enum SysCall {
|
pub enum SysCall {
|
||||||
|
|
@ -29,11 +28,10 @@ pub enum SysCall {
|
||||||
///
|
///
|
||||||
/// # Errors
|
/// # Errors
|
||||||
///
|
///
|
||||||
/// * **BadAlignment**: Either the physical or virtual addresses aren't
|
/// * **BadAlignment**: Either the physical or virtual addresses aren't page-aligned, or the size isn't a
|
||||||
/// page-aligned, or the size isn't a multiple of the
|
/// multiple of the page width.
|
||||||
/// page width.
|
/// * **OutOfMemory**: A contiguous chunk of memory couldn't be found, or the system's memory size has
|
||||||
/// * **OutOfMemory**: A contiguous chunk of memory couldn't be found, or
|
/// been exceeded.
|
||||||
/// the system's memory size has been exceeded.
|
|
||||||
MapMemory(
|
MapMemory(
|
||||||
Option<MemoryAddress>, /* phys */
|
Option<MemoryAddress>, /* phys */
|
||||||
Option<MemoryAddress>, /* virt */
|
Option<MemoryAddress>, /* virt */
|
||||||
|
|
@ -47,7 +45,6 @@ pub enum SysCall {
|
||||||
///
|
///
|
||||||
/// * **BadAlignment**: The memory range was not page-aligned
|
/// * **BadAlignment**: The memory range was not page-aligned
|
||||||
/// * **BadAddress**: A page in the range was not mapped
|
/// * **BadAddress**: A page in the range was not mapped
|
||||||
///
|
|
||||||
UnmapMemory(MemoryRange),
|
UnmapMemory(MemoryRange),
|
||||||
|
|
||||||
/// Sets the offset and size of a given memory region. This call may only
|
/// Sets the offset and size of a given memory region. This call may only
|
||||||
|
|
@ -58,9 +55,8 @@ pub enum SysCall {
|
||||||
///
|
///
|
||||||
/// # Errors
|
/// # Errors
|
||||||
///
|
///
|
||||||
/// * **BadAlignment**: Either the physical or virtual addresses aren't
|
/// * **BadAlignment**: Either the physical or virtual addresses aren't page-aligned, or the size isn't a
|
||||||
/// page-aligned, or the size isn't a multiple of the
|
/// multiple of the page width.
|
||||||
/// page width.
|
|
||||||
/// * **BadAddress**: The address conflicts with the kernel
|
/// * **BadAddress**: The address conflicts with the kernel
|
||||||
SetMemRegion(
|
SetMemRegion(
|
||||||
PID, /* pid */
|
PID, /* pid */
|
||||||
|
|
@ -76,34 +72,29 @@ pub enum SysCall {
|
||||||
///
|
///
|
||||||
/// # Returns
|
/// # Returns
|
||||||
///
|
///
|
||||||
/// * **MemoryRange(
|
/// * **MemoryRange( *mut usize, /* The newly-allocated offset */ usize, /* The amount of data added
|
||||||
/// *mut usize, /* The newly-allocated offset */
|
/// */ )**
|
||||||
/// usize, /* The amount of data added */
|
|
||||||
/// )**
|
|
||||||
///
|
///
|
||||||
/// # Errors
|
/// # Errors
|
||||||
///
|
///
|
||||||
/// * **BadAlignment**: Either the physical or virtual addresses aren't
|
/// * **BadAlignment**: Either the physical or virtual addresses aren't page-aligned, or the size isn't a
|
||||||
/// page-aligned, or the size isn't a multiple of the
|
/// multiple of the page width.
|
||||||
/// page width.
|
/// * **OutOfMemory**: A contiguous chunk of memory couldn't be found, or the system's memory size has
|
||||||
/// * **OutOfMemory**: A contiguous chunk of memory couldn't be found, or
|
/// been exceeded.
|
||||||
/// the system's memory size has been exceeded.
|
|
||||||
IncreaseHeap(usize /* number of bytes to add */, MemoryFlags),
|
IncreaseHeap(usize /* number of bytes to add */, MemoryFlags),
|
||||||
|
|
||||||
/// Remove the given number of bytes from the heap.
|
/// Remove the given number of bytes from the heap.
|
||||||
///
|
///
|
||||||
/// # Returns
|
/// # Returns
|
||||||
///
|
///
|
||||||
/// * **MemoryRange(*mut usize /* The base of the heap */, usize /* the new
|
/// * **MemoryRange(*mut usize /* The base of the heap */, usize /* the new size of the heap */)
|
||||||
/// size of the heap */)
|
|
||||||
///
|
///
|
||||||
/// # Errors
|
/// # Errors
|
||||||
///
|
///
|
||||||
/// * **BadAlignment**: Either the physical or virtual addresses aren't
|
/// * **BadAlignment**: Either the physical or virtual addresses aren't page-aligned, or the size isn't a
|
||||||
/// page-aligned, or the size isn't a multiple of the
|
/// multiple of the page width.
|
||||||
/// page width.
|
/// * **OutOfMemory**: A contiguous chunk of memory couldn't be found, or the system's memory size has
|
||||||
/// * **OutOfMemory**: A contiguous chunk of memory couldn't be found, or
|
/// been exceeded.
|
||||||
/// the system's memory size has been exceeded.
|
|
||||||
DecreaseHeap(usize /* desired heap size */),
|
DecreaseHeap(usize /* desired heap size */),
|
||||||
|
|
||||||
/// Set the specified flags on the virtual address range. This can be used
|
/// Set the specified flags on the virtual address range. This can be used
|
||||||
|
|
@ -119,10 +110,9 @@ pub enum SysCall {
|
||||||
///
|
///
|
||||||
/// # Errors
|
/// # Errors
|
||||||
///
|
///
|
||||||
/// * **ProcessNotChild**: The given PID is not a child of the current
|
/// * **ProcessNotChild**: The given PID is not a child of the current process.
|
||||||
/// process.
|
/// * **MemoryInUse**: The given PID has already been started, and it is not legal to modify memory flags
|
||||||
/// * **MemoryInUse**: The given PID has already been started, and it is not
|
/// anymore.
|
||||||
/// legal to modify memory flags anymore.
|
|
||||||
UpdateMemoryFlags(
|
UpdateMemoryFlags(
|
||||||
MemoryRange, /* range of memory to update flags for */
|
MemoryRange, /* range of memory to update flags for */
|
||||||
MemoryFlags, /* new flags */
|
MemoryFlags, /* new flags */
|
||||||
|
|
@ -163,10 +153,9 @@ pub enum SysCall {
|
||||||
/// # Errors
|
/// # Errors
|
||||||
///
|
///
|
||||||
/// * **ServerNotFound**: The given SID is not active or has terminated
|
/// * **ServerNotFound**: The given SID is not active or has terminated
|
||||||
/// * **ProcessNotFound**: The parent process terminated when we were getting ready
|
/// * **ProcessNotFound**: The parent process terminated when we were getting ready to block. This is an
|
||||||
/// to block. This is an internal error.
|
/// internal error.
|
||||||
/// * **BlockedProcess**: When running in Hosted mode, this indicates that this
|
/// * **BlockedProcess**: When running in Hosted mode, this indicates that this thread is blocking.
|
||||||
/// thread is blocking.
|
|
||||||
ReceiveMessage(SID),
|
ReceiveMessage(SID),
|
||||||
|
|
||||||
/// If a message is available for the specified server, return that message
|
/// If a message is available for the specified server, return that message
|
||||||
|
|
@ -181,8 +170,8 @@ pub enum SysCall {
|
||||||
/// # Errors
|
/// # Errors
|
||||||
///
|
///
|
||||||
/// * **ServerNotFound**: The given SID is not active or has terminated
|
/// * **ServerNotFound**: The given SID is not active or has terminated
|
||||||
/// * **ProcessNotFound**: The parent process terminated when we were getting ready
|
/// * **ProcessNotFound**: The parent process terminated when we were getting ready to block. This is an
|
||||||
/// to block. This is an internal error.
|
/// internal error.
|
||||||
TryReceiveMessage(SID),
|
TryReceiveMessage(SID),
|
||||||
|
|
||||||
/// Stop running the given process and return control to the parent. This
|
/// Stop running the given process and return control to the parent. This
|
||||||
|
|
@ -191,8 +180,7 @@ pub enum SysCall {
|
||||||
///
|
///
|
||||||
/// # Errors
|
/// # Errors
|
||||||
///
|
///
|
||||||
/// * **ProcessNotChild**: The given PID is not a child of the current
|
/// * **ProcessNotChild**: The given PID is not a child of the current process
|
||||||
/// process
|
|
||||||
ReturnToParent(PID, CpuID),
|
ReturnToParent(PID, CpuID),
|
||||||
|
|
||||||
/// Claims an interrupt and unmasks it immediately. The provided function
|
/// Claims an interrupt and unmasks it immediately. The provided function
|
||||||
|
|
@ -205,8 +193,7 @@ pub enum SysCall {
|
||||||
///
|
///
|
||||||
/// # Errors
|
/// # Errors
|
||||||
///
|
///
|
||||||
/// * **InterruptNotFound**: The specified interrupt isn't valid on this
|
/// * **InterruptNotFound**: The specified interrupt isn't valid on this system
|
||||||
/// system
|
|
||||||
/// * **InterruptInUse**: The specified interrupt has already been claimed
|
/// * **InterruptInUse**: The specified interrupt has already been claimed
|
||||||
ClaimInterrupt(
|
ClaimInterrupt(
|
||||||
usize, /* IRQ number */
|
usize, /* IRQ number */
|
||||||
|
|
@ -219,8 +206,7 @@ pub enum SysCall {
|
||||||
///
|
///
|
||||||
/// # Errors
|
/// # Errors
|
||||||
///
|
///
|
||||||
/// * **InterruptNotFound**: The specified interrupt doesn't exist, or isn't
|
/// * **InterruptNotFound**: The specified interrupt doesn't exist, or isn't assigned to this process.
|
||||||
/// assigned to this process.
|
|
||||||
FreeInterrupt(usize /* IRQ number */),
|
FreeInterrupt(usize /* IRQ number */),
|
||||||
|
|
||||||
/// Resumes a process using the given context. A parent could use this
|
/// Resumes a process using the given context. A parent could use this
|
||||||
|
|
@ -266,8 +252,7 @@ pub enum SysCall {
|
||||||
/// # Errors
|
/// # Errors
|
||||||
///
|
///
|
||||||
/// * **ProcessNotFound**: The requested process does not exist
|
/// * **ProcessNotFound**: The requested process does not exist
|
||||||
/// * **ProcessNotChild**: The given process was not a child process, and
|
/// * **ProcessNotChild**: The given process was not a child process, and therefore couldn't be resumed.
|
||||||
/// therefore couldn't be resumed.
|
|
||||||
/// * **ProcessTerminated**: The process has crashed.
|
/// * **ProcessTerminated**: The process has crashed.
|
||||||
SwitchTo(PID, usize /* context ID */),
|
SwitchTo(PID, usize /* context ID */),
|
||||||
|
|
||||||
|
|
@ -286,13 +271,12 @@ pub enum SysCall {
|
||||||
///
|
///
|
||||||
/// # Returns
|
/// # Returns
|
||||||
///
|
///
|
||||||
/// * **NewServerID(sid, cid)**: The specified SID, along with the connection ID
|
/// * **NewServerID(sid, cid)**: The specified SID, along with the connection ID for this process to talk
|
||||||
/// for this process to talk to the server.
|
/// to the server.
|
||||||
///
|
///
|
||||||
/// # Errors
|
/// # Errors
|
||||||
///
|
///
|
||||||
/// * **OutOfMemory**: The server table was full and a new server couldn't
|
/// * **OutOfMemory**: The server table was full and a new server couldn't be created.
|
||||||
/// be created.
|
|
||||||
/// * **ServerExists**: The server hash is already in use.
|
/// * **ServerExists**: The server hash is already in use.
|
||||||
CreateServerWithAddress(SID /* server hash */),
|
CreateServerWithAddress(SID /* server hash */),
|
||||||
|
|
||||||
|
|
@ -329,9 +313,8 @@ pub enum SysCall {
|
||||||
/// * **Scalar2**: The Server returned a `Scalar2` value
|
/// * **Scalar2**: The Server returned a `Scalar2` value
|
||||||
/// * **Scalar5**: The Server returned a `Scalar5` value
|
/// * **Scalar5**: The Server returned a `Scalar5` value
|
||||||
/// * **BlockedProcess**: In Hosted mode, the target process is now blocked
|
/// * **BlockedProcess**: In Hosted mode, the target process is now blocked
|
||||||
/// * **Message**: For Scalar messages, this includes the args as returned
|
/// * **Message**: For Scalar messages, this includes the args as returned by the server. For
|
||||||
/// by the server. For MemoryMessages, this will include
|
/// MemoryMessages, this will include the Opcode, Offset, and Valid fields.
|
||||||
/// the Opcode, Offset, and Valid fields.
|
|
||||||
///
|
///
|
||||||
/// # Errors
|
/// # Errors
|
||||||
///
|
///
|
||||||
|
|
@ -395,8 +378,7 @@ pub enum SysCall {
|
||||||
///
|
///
|
||||||
/// # Errors
|
/// # Errors
|
||||||
///
|
///
|
||||||
/// * **OutOfMemory**: The server table was full and a new server couldn't
|
/// * **OutOfMemory**: The server table was full and a new server couldn't be created.
|
||||||
/// be created.
|
|
||||||
CreateServer,
|
CreateServer,
|
||||||
|
|
||||||
/// Returns a 128-bit server ID, but does not create the server itself.
|
/// Returns a 128-bit server ID, but does not create the server itself.
|
||||||
|
|
@ -427,10 +409,7 @@ pub enum SysCall {
|
||||||
|
|
||||||
/// A function to call when there is an exception such as a memory fault
|
/// A function to call when there is an exception such as a memory fault
|
||||||
/// or illegal instruction.
|
/// or illegal instruction.
|
||||||
SetExceptionHandler(
|
SetExceptionHandler(usize /* function pointer */, usize /* stack pointer */),
|
||||||
usize, /* function pointer */
|
|
||||||
usize, /* stack pointer */
|
|
||||||
),
|
|
||||||
|
|
||||||
/// Adjust one of the limits within this process. Note that you must pass
|
/// Adjust one of the limits within this process. Note that you must pass
|
||||||
/// the current limit value in order to set the new limit. The current limit
|
/// the current limit value in order to set the new limit. The current limit
|
||||||
|
|
@ -439,14 +418,11 @@ pub enum SysCall {
|
||||||
///
|
///
|
||||||
/// ## Arguments
|
/// ## Arguments
|
||||||
///
|
///
|
||||||
/// * **Index**: The item to adjust. Currently the following limits
|
/// * **Index**: The item to adjust. Currently the following limits are supported: 1: Maximum heap size
|
||||||
/// are supported:
|
/// 2: Current heap size
|
||||||
/// 1: Maximum heap size
|
/// * **Current Limit**: Pass the current limit value here. The current limit must match in order for the
|
||||||
/// 2: Current heap size
|
/// new limit to take effect. This is used to avoid a race condition if two threads try to set the same
|
||||||
/// * **Current Limit**: Pass the current limit value here. The current
|
/// limit.
|
||||||
/// limit must match in order for the new limit to take
|
|
||||||
/// effect. This is used to avoid a race condition if two
|
|
||||||
/// threads try to set the same limit.
|
|
||||||
/// * **Proposed Limit**: The new value that you would like to use.
|
/// * **Proposed Limit**: The new value that you would like to use.
|
||||||
///
|
///
|
||||||
/// ## Returns
|
/// ## Returns
|
||||||
|
|
@ -488,9 +464,8 @@ pub enum SysCall {
|
||||||
///
|
///
|
||||||
/// ## Arguments
|
/// ## Arguments
|
||||||
///
|
///
|
||||||
/// * **MessageSender**: This is the `sender` from the message envelope.
|
/// * **MessageSender**: This is the `sender` from the message envelope. It is a unique ID that
|
||||||
/// It is a unique ID that identifies this message,
|
/// identifies this message, as well as the server it came from.
|
||||||
/// as well as the server it came from.
|
|
||||||
///
|
///
|
||||||
/// The remaining arguments depend on whether the message was a `BlockingScalar`
|
/// The remaining arguments depend on whether the message was a `BlockingScalar`
|
||||||
/// message or a `MemoryMessage`. Note that this function should NOT be called
|
/// message or a `MemoryMessage`. Note that this function should NOT be called
|
||||||
|
|
@ -503,10 +478,9 @@ pub enum SysCall {
|
||||||
/// # Errors
|
/// # Errors
|
||||||
///
|
///
|
||||||
/// * **ServerNotFound**: The given SID is not active or has terminated
|
/// * **ServerNotFound**: The given SID is not active or has terminated
|
||||||
/// * **ProcessNotFound**: The parent process terminated when we were getting ready
|
/// * **ProcessNotFound**: The parent process terminated when we were getting ready to block. This is an
|
||||||
/// to block. This is an internal error.
|
/// internal error.
|
||||||
/// * **BlockedProcess**: When running in Hosted mode, this indicates that this
|
/// * **BlockedProcess**: When running in Hosted mode, this indicates that this thread is blocking.
|
||||||
/// thread is blocking.
|
|
||||||
ReplyAndReceiveNext(
|
ReplyAndReceiveNext(
|
||||||
MessageSender, /* ID if the sender that sent this message */
|
MessageSender, /* ID if the sender that sent this message */
|
||||||
usize, /* Return code to the caller */
|
usize, /* Return code to the caller */
|
||||||
|
|
@ -517,7 +491,8 @@ pub enum SysCall {
|
||||||
usize, /* how many args are valid (BlockingScalar) or usize::MAX (MemoryMessge) */
|
usize, /* how many args are valid (BlockingScalar) or usize::MAX (MemoryMessge) */
|
||||||
),
|
),
|
||||||
|
|
||||||
/// Returns the physical address corresponding to a virtual address for a given process, if such a mapping exists.
|
/// Returns the physical address corresponding to a virtual address for a given process, if such a
|
||||||
|
/// mapping exists.
|
||||||
///
|
///
|
||||||
/// ## Arguments
|
/// ## Arguments
|
||||||
/// * **pid**: The PID
|
/// * **pid**: The PID
|
||||||
|
|
@ -638,16 +613,7 @@ impl SysCallNumber {
|
||||||
|
|
||||||
impl SysCall {
|
impl SysCall {
|
||||||
fn add_opcode(opcode: SysCallNumber, args: [usize; 7]) -> [usize; 8] {
|
fn add_opcode(opcode: SysCallNumber, args: [usize; 7]) -> [usize; 8] {
|
||||||
[
|
[opcode as usize, args[0], args[1], args[2], args[3], args[4], args[5], args[6]]
|
||||||
opcode as usize,
|
|
||||||
args[0],
|
|
||||||
args[1],
|
|
||||||
args[2],
|
|
||||||
args[3],
|
|
||||||
args[4],
|
|
||||||
args[5],
|
|
||||||
args[6],
|
|
||||||
]
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Convert the SysCall into an array of eight `usize` elements,
|
/// Convert the SysCall into an array of eight `usize` elements,
|
||||||
|
|
@ -671,43 +637,18 @@ impl SysCall {
|
||||||
0,
|
0,
|
||||||
0,
|
0,
|
||||||
],
|
],
|
||||||
SysCall::UnmapMemory(range) => [
|
SysCall::UnmapMemory(range) => {
|
||||||
SysCallNumber::UnmapMemory as usize,
|
[SysCallNumber::UnmapMemory as usize, range.as_ptr() as usize, range.len(), 0, 0, 0, 0, 0]
|
||||||
range.as_ptr() as usize,
|
}
|
||||||
range.len(),
|
|
||||||
0,
|
|
||||||
0,
|
|
||||||
0,
|
|
||||||
0,
|
|
||||||
0,
|
|
||||||
],
|
|
||||||
SysCall::Yield => [SysCallNumber::Yield as usize, 0, 0, 0, 0, 0, 0, 0],
|
SysCall::Yield => [SysCallNumber::Yield as usize, 0, 0, 0, 0, 0, 0, 0],
|
||||||
SysCall::WaitEvent => [SysCallNumber::WaitEvent as usize, 0, 0, 0, 0, 0, 0, 0],
|
SysCall::WaitEvent => [SysCallNumber::WaitEvent as usize, 0, 0, 0, 0, 0, 0, 0],
|
||||||
SysCall::ReceiveMessage(sid) => {
|
SysCall::ReceiveMessage(sid) => {
|
||||||
let s = sid.to_u32();
|
let s = sid.to_u32();
|
||||||
[
|
[SysCallNumber::ReceiveMessage as usize, s.0 as _, s.1 as _, s.2 as _, s.3 as _, 0, 0, 0]
|
||||||
SysCallNumber::ReceiveMessage as usize,
|
|
||||||
s.0 as _,
|
|
||||||
s.1 as _,
|
|
||||||
s.2 as _,
|
|
||||||
s.3 as _,
|
|
||||||
0,
|
|
||||||
0,
|
|
||||||
0,
|
|
||||||
]
|
|
||||||
}
|
}
|
||||||
SysCall::TryReceiveMessage(sid) => {
|
SysCall::TryReceiveMessage(sid) => {
|
||||||
let s = sid.to_u32();
|
let s = sid.to_u32();
|
||||||
[
|
[SysCallNumber::TryReceiveMessage as usize, s.0 as _, s.1 as _, s.2 as _, s.3 as _, 0, 0, 0]
|
||||||
SysCallNumber::TryReceiveMessage as usize,
|
|
||||||
s.0 as _,
|
|
||||||
s.1 as _,
|
|
||||||
s.2 as _,
|
|
||||||
s.3 as _,
|
|
||||||
0,
|
|
||||||
0,
|
|
||||||
0,
|
|
||||||
]
|
|
||||||
}
|
}
|
||||||
SysCall::ConnectForProcess(pid, sid) => {
|
SysCall::ConnectForProcess(pid, sid) => {
|
||||||
let s = sid.to_u32();
|
let s = sid.to_u32();
|
||||||
|
|
@ -722,19 +663,10 @@ impl SysCall {
|
||||||
0,
|
0,
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
SysCall::CreateServerId => {
|
SysCall::CreateServerId => [SysCallNumber::CreateServerId as usize, 0, 0, 0, 0, 0, 0, 0],
|
||||||
[SysCallNumber::CreateServerId as usize, 0, 0, 0, 0, 0, 0, 0]
|
SysCall::ReturnToParent(a1, a2) => {
|
||||||
|
[SysCallNumber::ReturnToParent as usize, a1.get() as usize, *a2, 0, 0, 0, 0, 0]
|
||||||
}
|
}
|
||||||
SysCall::ReturnToParent(a1, a2) => [
|
|
||||||
SysCallNumber::ReturnToParent as usize,
|
|
||||||
a1.get() as usize,
|
|
||||||
*a2,
|
|
||||||
0,
|
|
||||||
0,
|
|
||||||
0,
|
|
||||||
0,
|
|
||||||
0,
|
|
||||||
],
|
|
||||||
SysCall::ClaimInterrupt(a1, a2, a3) => [
|
SysCall::ClaimInterrupt(a1, a2, a3) => [
|
||||||
SysCallNumber::ClaimInterrupt as usize,
|
SysCallNumber::ClaimInterrupt as usize,
|
||||||
*a1,
|
*a1,
|
||||||
|
|
@ -745,49 +677,17 @@ impl SysCall {
|
||||||
0,
|
0,
|
||||||
0,
|
0,
|
||||||
],
|
],
|
||||||
SysCall::FreeInterrupt(a1) => {
|
SysCall::FreeInterrupt(a1) => [SysCallNumber::FreeInterrupt as usize, *a1, 0, 0, 0, 0, 0, 0],
|
||||||
[SysCallNumber::FreeInterrupt as usize, *a1, 0, 0, 0, 0, 0, 0]
|
SysCall::SwitchTo(a1, a2) => {
|
||||||
|
[SysCallNumber::SwitchTo as usize, a1.get() as usize, *a2, 0, 0, 0, 0, 0]
|
||||||
}
|
}
|
||||||
SysCall::SwitchTo(a1, a2) => [
|
SysCall::ReadyThreads(a1) => {
|
||||||
SysCallNumber::SwitchTo as usize,
|
[SysCallNumber::ReadyThreads as usize, a1.get() as usize, 0, 0, 0, 0, 0, 0]
|
||||||
a1.get() as usize,
|
}
|
||||||
*a2,
|
SysCall::IncreaseHeap(a1, a2) => {
|
||||||
0,
|
[SysCallNumber::IncreaseHeap as usize, *a1, a2.bits(), 0, 0, 0, 0, 0]
|
||||||
0,
|
}
|
||||||
0,
|
SysCall::DecreaseHeap(a1) => [SysCallNumber::DecreaseHeap as usize, *a1, 0, 0, 0, 0, 0, 0],
|
||||||
0,
|
|
||||||
0,
|
|
||||||
],
|
|
||||||
SysCall::ReadyThreads(a1) => [
|
|
||||||
SysCallNumber::ReadyThreads as usize,
|
|
||||||
a1.get() as usize,
|
|
||||||
0,
|
|
||||||
0,
|
|
||||||
0,
|
|
||||||
0,
|
|
||||||
0,
|
|
||||||
0,
|
|
||||||
],
|
|
||||||
SysCall::IncreaseHeap(a1, a2) => [
|
|
||||||
SysCallNumber::IncreaseHeap as usize,
|
|
||||||
*a1,
|
|
||||||
a2.bits(),
|
|
||||||
0,
|
|
||||||
0,
|
|
||||||
0,
|
|
||||||
0,
|
|
||||||
0,
|
|
||||||
],
|
|
||||||
SysCall::DecreaseHeap(a1) => [
|
|
||||||
SysCallNumber::DecreaseHeap as usize,
|
|
||||||
*a1,
|
|
||||||
0,
|
|
||||||
0,
|
|
||||||
0,
|
|
||||||
0,
|
|
||||||
0,
|
|
||||||
0,
|
|
||||||
],
|
|
||||||
SysCall::UpdateMemoryFlags(a1, a2, a3) => [
|
SysCall::UpdateMemoryFlags(a1, a2, a3) => [
|
||||||
SysCallNumber::UpdateMemoryFlags as usize,
|
SysCallNumber::UpdateMemoryFlags as usize,
|
||||||
a1.as_mut_ptr() as usize,
|
a1.as_mut_ptr() as usize,
|
||||||
|
|
@ -825,16 +725,7 @@ impl SysCall {
|
||||||
SysCall::CreateServer => [SysCallNumber::CreateServer as usize, 0, 0, 0, 0, 0, 0, 0],
|
SysCall::CreateServer => [SysCallNumber::CreateServer as usize, 0, 0, 0, 0, 0, 0, 0],
|
||||||
SysCall::Connect(sid) => {
|
SysCall::Connect(sid) => {
|
||||||
let s = sid.to_u32();
|
let s = sid.to_u32();
|
||||||
[
|
[SysCallNumber::Connect as usize, s.0 as _, s.1 as _, s.2 as _, s.3 as _, 0, 0, 0]
|
||||||
SysCallNumber::Connect as usize,
|
|
||||||
s.0 as _,
|
|
||||||
s.1 as _,
|
|
||||||
s.2 as _,
|
|
||||||
s.3 as _,
|
|
||||||
0,
|
|
||||||
0,
|
|
||||||
0,
|
|
||||||
]
|
|
||||||
}
|
}
|
||||||
SysCall::SendMessage(a1, ref a2) => match a2 {
|
SysCall::SendMessage(a1, ref a2) => match a2 {
|
||||||
Message::MutableBorrow(mm) | Message::Borrow(mm) | Message::Move(mm) => [
|
Message::MutableBorrow(mm) | Message::Borrow(mm) | Message::Move(mm) => [
|
||||||
|
|
@ -882,32 +773,14 @@ impl SysCall {
|
||||||
SysCall::CreateThread(init) => {
|
SysCall::CreateThread(init) => {
|
||||||
crate::arch::thread_to_args(SysCallNumber::CreateThread as usize, init)
|
crate::arch::thread_to_args(SysCallNumber::CreateThread as usize, init)
|
||||||
}
|
}
|
||||||
SysCall::CreateProcess(init) => {
|
SysCall::CreateProcess(init) => Self::add_opcode(SysCallNumber::CreateProcess, init.into()),
|
||||||
Self::add_opcode(SysCallNumber::CreateProcess, init.into())
|
SysCall::TerminateProcess(exit_code) => {
|
||||||
|
[SysCallNumber::TerminateProcess as usize, *exit_code as usize, 0, 0, 0, 0, 0, 0]
|
||||||
}
|
}
|
||||||
SysCall::TerminateProcess(exit_code) => [
|
|
||||||
SysCallNumber::TerminateProcess as usize,
|
|
||||||
*exit_code as usize,
|
|
||||||
0,
|
|
||||||
0,
|
|
||||||
0,
|
|
||||||
0,
|
|
||||||
0,
|
|
||||||
0,
|
|
||||||
],
|
|
||||||
SysCall::Shutdown => [SysCallNumber::Shutdown as usize, 0, 0, 0, 0, 0, 0, 0],
|
SysCall::Shutdown => [SysCallNumber::Shutdown as usize, 0, 0, 0, 0, 0, 0, 0],
|
||||||
SysCall::TryConnect(sid) => {
|
SysCall::TryConnect(sid) => {
|
||||||
let s = sid.to_u32();
|
let s = sid.to_u32();
|
||||||
[
|
[SysCallNumber::TryConnect as usize, s.0 as _, s.1 as _, s.2 as _, s.3 as _, 0, 0, 0]
|
||||||
SysCallNumber::TryConnect as usize,
|
|
||||||
s.0 as _,
|
|
||||||
s.1 as _,
|
|
||||||
s.2 as _,
|
|
||||||
s.3 as _,
|
|
||||||
0,
|
|
||||||
0,
|
|
||||||
0,
|
|
||||||
]
|
|
||||||
}
|
}
|
||||||
SysCall::TrySendMessage(a1, ref a2) => match a2 {
|
SysCall::TrySendMessage(a1, ref a2) => match a2 {
|
||||||
Message::MutableBorrow(mm) | Message::Borrow(mm) | Message::Move(mm) => [
|
Message::MutableBorrow(mm) | Message::Borrow(mm) | Message::Move(mm) => [
|
||||||
|
|
@ -931,85 +804,28 @@ impl SysCall {
|
||||||
sc.arg4,
|
sc.arg4,
|
||||||
],
|
],
|
||||||
},
|
},
|
||||||
SysCall::ReturnScalar1(sender, arg1) => [
|
SysCall::ReturnScalar1(sender, arg1) => {
|
||||||
SysCallNumber::ReturnScalar1 as usize,
|
[SysCallNumber::ReturnScalar1 as usize, sender.to_usize(), *arg1, 0, 0, 0, 0, 0]
|
||||||
sender.to_usize(),
|
}
|
||||||
*arg1,
|
SysCall::ReturnScalar2(sender, arg1, arg2) => {
|
||||||
0,
|
[SysCallNumber::ReturnScalar2 as usize, sender.to_usize(), *arg1, *arg2, 0, 0, 0, 0]
|
||||||
0,
|
}
|
||||||
0,
|
|
||||||
0,
|
|
||||||
0,
|
|
||||||
],
|
|
||||||
SysCall::ReturnScalar2(sender, arg1, arg2) => [
|
|
||||||
SysCallNumber::ReturnScalar2 as usize,
|
|
||||||
sender.to_usize(),
|
|
||||||
*arg1,
|
|
||||||
*arg2,
|
|
||||||
0,
|
|
||||||
0,
|
|
||||||
0,
|
|
||||||
0,
|
|
||||||
],
|
|
||||||
SysCall::GetThreadId => [SysCallNumber::GetThreadId as usize, 0, 0, 0, 0, 0, 0, 0],
|
SysCall::GetThreadId => [SysCallNumber::GetThreadId as usize, 0, 0, 0, 0, 0, 0, 0],
|
||||||
SysCall::GetProcessId => [SysCallNumber::GetProcessId as usize, 0, 0, 0, 0, 0, 0, 0],
|
SysCall::GetProcessId => [SysCallNumber::GetProcessId as usize, 0, 0, 0, 0, 0, 0, 0],
|
||||||
SysCall::DestroyServer(sid) => {
|
SysCall::DestroyServer(sid) => {
|
||||||
let s = sid.to_u32();
|
let s = sid.to_u32();
|
||||||
[
|
[SysCallNumber::DestroyServer as usize, s.0 as _, s.1 as _, s.2 as _, s.3 as _, 0, 0, 0]
|
||||||
SysCallNumber::DestroyServer as usize,
|
}
|
||||||
s.0 as _,
|
SysCall::Disconnect(cid) => [SysCallNumber::Disconnect as usize, *cid as usize, 0, 0, 0, 0, 0, 0],
|
||||||
s.1 as _,
|
SysCall::JoinThread(tid) => [SysCallNumber::JoinThread as usize, *tid, 0, 0, 0, 0, 0, 0],
|
||||||
s.2 as _,
|
SysCall::SetExceptionHandler(pc, sp) => {
|
||||||
s.3 as _,
|
[SysCallNumber::SetExceptionHandler as usize, *pc, *sp, 0, 0, 0, 0, 0]
|
||||||
0,
|
}
|
||||||
0,
|
SysCall::AdjustProcessLimit(index, current, new) => {
|
||||||
0,
|
[SysCallNumber::AdjustProcessLimit as usize, *index, *current, *new, 0, 0, 0, 0]
|
||||||
]
|
|
||||||
}
|
}
|
||||||
SysCall::Disconnect(cid) => [
|
|
||||||
SysCallNumber::Disconnect as usize,
|
|
||||||
*cid as usize,
|
|
||||||
0,
|
|
||||||
0,
|
|
||||||
0,
|
|
||||||
0,
|
|
||||||
0,
|
|
||||||
0,
|
|
||||||
],
|
|
||||||
SysCall::JoinThread(tid) => [
|
|
||||||
SysCallNumber::JoinThread as usize,
|
|
||||||
*tid,
|
|
||||||
0,
|
|
||||||
0,
|
|
||||||
0,
|
|
||||||
0,
|
|
||||||
0,
|
|
||||||
0,
|
|
||||||
],
|
|
||||||
SysCall::SetExceptionHandler(pc, sp) => [
|
|
||||||
SysCallNumber::SetExceptionHandler as usize,
|
|
||||||
*pc,
|
|
||||||
*sp,
|
|
||||||
0,
|
|
||||||
0,
|
|
||||||
0,
|
|
||||||
0,
|
|
||||||
0,
|
|
||||||
],
|
|
||||||
SysCall::AdjustProcessLimit(index, current, new) => [
|
|
||||||
SysCallNumber::AdjustProcessLimit as usize,
|
|
||||||
*index,
|
|
||||||
*current,
|
|
||||||
*new,
|
|
||||||
0,
|
|
||||||
0,
|
|
||||||
0,
|
|
||||||
0,
|
|
||||||
],
|
|
||||||
#[cfg(feature = "v2p")]
|
#[cfg(feature = "v2p")]
|
||||||
SysCall::VirtToPhys(vaddr) => {
|
SysCall::VirtToPhys(vaddr) => [SysCallNumber::VirtToPhys as usize, *vaddr, 0, 0, 0, 0, 0, 0],
|
||||||
[SysCallNumber::VirtToPhys as usize, *vaddr, 0, 0, 0, 0, 0, 0]
|
|
||||||
}
|
|
||||||
SysCall::ReturnScalar5(sender, arg1, arg2, arg3, arg4, arg5) => [
|
SysCall::ReturnScalar5(sender, arg1, arg2, arg3, arg4, arg5) => [
|
||||||
SysCallNumber::ReturnScalar5 as usize,
|
SysCallNumber::ReturnScalar5 as usize,
|
||||||
sender.to_usize(),
|
sender.to_usize(),
|
||||||
|
|
@ -1024,16 +840,9 @@ impl SysCall {
|
||||||
SysCall::VirtToPhysPid(pid, vaddr) => {
|
SysCall::VirtToPhysPid(pid, vaddr) => {
|
||||||
[SysCallNumber::VirtToPhysPid as usize, pid.get() as usize, *vaddr, 0, 0, 0, 0, 0]
|
[SysCallNumber::VirtToPhysPid as usize, pid.get() as usize, *vaddr, 0, 0, 0, 0, 0]
|
||||||
}
|
}
|
||||||
SysCall::Invalid(a1, a2, a3, a4, a5, a6, a7) => [
|
SysCall::Invalid(a1, a2, a3, a4, a5, a6, a7) => {
|
||||||
SysCallNumber::Invalid as usize,
|
[SysCallNumber::Invalid as usize, *a1, *a2, *a3, *a4, *a5, *a6, *a7]
|
||||||
*a1,
|
}
|
||||||
*a2,
|
|
||||||
*a3,
|
|
||||||
*a4,
|
|
||||||
*a5,
|
|
||||||
*a6,
|
|
||||||
*a7,
|
|
||||||
],
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -1055,9 +864,9 @@ impl SysCall {
|
||||||
MemoryAddress::new(a3).ok_or(Error::InvalidSyscall)?,
|
MemoryAddress::new(a3).ok_or(Error::InvalidSyscall)?,
|
||||||
crate::MemoryFlags::from_bits(a4).ok_or(Error::InvalidSyscall)?,
|
crate::MemoryFlags::from_bits(a4).ok_or(Error::InvalidSyscall)?,
|
||||||
),
|
),
|
||||||
SysCallNumber::UnmapMemory => SysCall::UnmapMemory(unsafe {
|
SysCallNumber::UnmapMemory => {
|
||||||
MemoryRange::new(a1, a2).or(Err(Error::InvalidSyscall))
|
SysCall::UnmapMemory(unsafe { MemoryRange::new(a1, a2).or(Err(Error::InvalidSyscall)) }?)
|
||||||
}?),
|
}
|
||||||
SysCallNumber::Yield => SysCall::Yield,
|
SysCallNumber::Yield => SysCall::Yield,
|
||||||
SysCallNumber::WaitEvent => SysCall::WaitEvent,
|
SysCallNumber::WaitEvent => SysCall::WaitEvent,
|
||||||
SysCallNumber::ReceiveMessage => {
|
SysCallNumber::ReceiveMessage => {
|
||||||
|
|
@ -1075,10 +884,9 @@ impl SysCall {
|
||||||
SysCallNumber::FreeInterrupt => SysCall::FreeInterrupt(a1),
|
SysCallNumber::FreeInterrupt => SysCall::FreeInterrupt(a1),
|
||||||
SysCallNumber::SwitchTo => SysCall::SwitchTo(pid_from_usize(a1)?, a2),
|
SysCallNumber::SwitchTo => SysCall::SwitchTo(pid_from_usize(a1)?, a2),
|
||||||
SysCallNumber::ReadyThreads => SysCall::ReadyThreads(pid_from_usize(a1)?),
|
SysCallNumber::ReadyThreads => SysCall::ReadyThreads(pid_from_usize(a1)?),
|
||||||
SysCallNumber::IncreaseHeap => SysCall::IncreaseHeap(
|
SysCallNumber::IncreaseHeap => {
|
||||||
a1,
|
SysCall::IncreaseHeap(a1, crate::MemoryFlags::from_bits(a2).ok_or(Error::InvalidSyscall)?)
|
||||||
crate::MemoryFlags::from_bits(a2).ok_or(Error::InvalidSyscall)?,
|
}
|
||||||
),
|
|
||||||
SysCallNumber::DecreaseHeap => SysCall::DecreaseHeap(a1),
|
SysCallNumber::DecreaseHeap => SysCall::DecreaseHeap(a1),
|
||||||
SysCallNumber::UpdateMemoryFlags => SysCall::UpdateMemoryFlags(
|
SysCallNumber::UpdateMemoryFlags => SysCall::UpdateMemoryFlags(
|
||||||
unsafe { MemoryRange::new(a1, a2) }?,
|
unsafe { MemoryRange::new(a1, a2) }?,
|
||||||
|
|
@ -1095,9 +903,7 @@ impl SysCall {
|
||||||
SysCall::CreateServerWithAddress(SID::from_u32(a1 as _, a2 as _, a3 as _, a4 as _))
|
SysCall::CreateServerWithAddress(SID::from_u32(a1 as _, a2 as _, a3 as _, a4 as _))
|
||||||
}
|
}
|
||||||
SysCallNumber::CreateServer => SysCall::CreateServer,
|
SysCallNumber::CreateServer => SysCall::CreateServer,
|
||||||
SysCallNumber::Connect => {
|
SysCallNumber::Connect => SysCall::Connect(SID::from_u32(a1 as _, a2 as _, a3 as _, a4 as _)),
|
||||||
SysCall::Connect(SID::from_u32(a1 as _, a2 as _, a3 as _, a4 as _))
|
|
||||||
}
|
|
||||||
SysCallNumber::SendMessage => Message::try_from((a2, a3, a4, a5, a6, a7))
|
SysCallNumber::SendMessage => Message::try_from((a2, a3, a4, a5, a6, a7))
|
||||||
.map(|m| SysCall::SendMessage(a1.try_into().unwrap(), m))
|
.map(|m| SysCall::SendMessage(a1.try_into().unwrap(), m))
|
||||||
.unwrap_or_else(|_| SysCall::Invalid(a1, a2, a3, a4, a5, a6, a7)),
|
.unwrap_or_else(|_| SysCall::Invalid(a1, a2, a3, a4, a5, a6, a7)),
|
||||||
|
|
@ -1113,9 +919,7 @@ impl SysCall {
|
||||||
SysCallNumber::CreateThread => {
|
SysCallNumber::CreateThread => {
|
||||||
SysCall::CreateThread(crate::arch::args_to_thread(a1, a2, a3, a4, a5, a6, a7)?)
|
SysCall::CreateThread(crate::arch::args_to_thread(a1, a2, a3, a4, a5, a6, a7)?)
|
||||||
}
|
}
|
||||||
SysCallNumber::CreateProcess => {
|
SysCallNumber::CreateProcess => SysCall::CreateProcess([a1, a2, a3, a4, a5, a6, a7].try_into()?),
|
||||||
SysCall::CreateProcess([a1, a2, a3, a4, a5, a6, a7].try_into()?)
|
|
||||||
}
|
|
||||||
SysCallNumber::TerminateProcess => SysCall::TerminateProcess(a1 as u32),
|
SysCallNumber::TerminateProcess => SysCall::TerminateProcess(a1 as u32),
|
||||||
SysCallNumber::Shutdown => SysCall::Shutdown,
|
SysCallNumber::Shutdown => SysCall::Shutdown,
|
||||||
SysCallNumber::TryConnect => {
|
SysCallNumber::TryConnect => {
|
||||||
|
|
@ -1151,32 +955,16 @@ impl SysCall {
|
||||||
),
|
),
|
||||||
4 => SysCall::TrySendMessage(
|
4 => SysCall::TrySendMessage(
|
||||||
a1 as u32,
|
a1 as u32,
|
||||||
Message::Scalar(ScalarMessage {
|
Message::Scalar(ScalarMessage { id: a3, arg1: a4, arg2: a5, arg3: a6, arg4: a7 }),
|
||||||
id: a3,
|
|
||||||
arg1: a4,
|
|
||||||
arg2: a5,
|
|
||||||
arg3: a6,
|
|
||||||
arg4: a7,
|
|
||||||
}),
|
|
||||||
),
|
),
|
||||||
5 => SysCall::TrySendMessage(
|
5 => SysCall::TrySendMessage(
|
||||||
a1.try_into().unwrap(),
|
a1.try_into().unwrap(),
|
||||||
Message::BlockingScalar(ScalarMessage {
|
Message::BlockingScalar(ScalarMessage { id: a3, arg1: a4, arg2: a5, arg3: a6, arg4: a7 }),
|
||||||
id: a3,
|
|
||||||
arg1: a4,
|
|
||||||
arg2: a5,
|
|
||||||
arg3: a6,
|
|
||||||
arg4: a7,
|
|
||||||
}),
|
|
||||||
),
|
),
|
||||||
_ => SysCall::Invalid(a1, a2, a3, a4, a5, a6, a7),
|
_ => SysCall::Invalid(a1, a2, a3, a4, a5, a6, a7),
|
||||||
},
|
},
|
||||||
SysCallNumber::ReturnScalar1 => {
|
SysCallNumber::ReturnScalar1 => SysCall::ReturnScalar1(MessageSender::from_usize(a1), a2),
|
||||||
SysCall::ReturnScalar1(MessageSender::from_usize(a1), a2)
|
SysCallNumber::ReturnScalar2 => SysCall::ReturnScalar2(MessageSender::from_usize(a1), a2, a3),
|
||||||
}
|
|
||||||
SysCallNumber::ReturnScalar2 => {
|
|
||||||
SysCall::ReturnScalar2(MessageSender::from_usize(a1), a2, a3)
|
|
||||||
}
|
|
||||||
SysCallNumber::ConnectForProcess => SysCall::ConnectForProcess(
|
SysCallNumber::ConnectForProcess => SysCall::ConnectForProcess(
|
||||||
PID::new(a1 as _).ok_or(Error::InvalidSyscall)?,
|
PID::new(a1 as _).ok_or(Error::InvalidSyscall)?,
|
||||||
SID::from_u32(a2 as _, a3 as _, a4 as _, a5 as _),
|
SID::from_u32(a2 as _, a3 as _, a4 as _, a5 as _),
|
||||||
|
|
@ -1206,10 +994,7 @@ impl SysCall {
|
||||||
pub fn has_memory(&self) -> bool {
|
pub fn has_memory(&self) -> bool {
|
||||||
match self {
|
match self {
|
||||||
SysCall::TrySendMessage(_, msg) | SysCall::SendMessage(_, msg) => {
|
SysCall::TrySendMessage(_, msg) | SysCall::SendMessage(_, msg) => {
|
||||||
matches!(
|
matches!(msg, Message::Move(_) | Message::Borrow(_) | Message::MutableBorrow(_))
|
||||||
msg,
|
|
||||||
Message::Move(_) | Message::Borrow(_) | Message::MutableBorrow(_)
|
|
||||||
)
|
|
||||||
}
|
}
|
||||||
SysCall::ReturnMemory(_, _, _, _) => true,
|
SysCall::ReturnMemory(_, _, _, _) => true,
|
||||||
SysCall::ReplyAndReceiveNext(_, _, _, _, _, _, usize::MAX) => true,
|
SysCall::ReplyAndReceiveNext(_, _, _, _, _, _, usize::MAX) => true,
|
||||||
|
|
@ -1249,10 +1034,7 @@ impl SysCall {
|
||||||
|
|
||||||
/// Returns `true` if the associated syscall is returning memory
|
/// Returns `true` if the associated syscall is returning memory
|
||||||
pub fn is_return_memory(&self) -> bool {
|
pub fn is_return_memory(&self) -> bool {
|
||||||
matches!(
|
matches!(self, SysCall::ReturnMemory(..) | SysCall::ReplyAndReceiveNext(_, _, _, _, _, _, usize::MAX))
|
||||||
self,
|
|
||||||
SysCall::ReturnMemory(..) | SysCall::ReplyAndReceiveNext(_, _, _, _, _, _, usize::MAX)
|
|
||||||
)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// If the syscall has memory attached to it, return the memory
|
/// If the syscall has memory attached to it, return the memory
|
||||||
|
|
@ -1324,16 +1106,10 @@ pub fn map_memory(
|
||||||
flags: MemoryFlags,
|
flags: MemoryFlags,
|
||||||
) -> core::result::Result<MemoryRange, Error> {
|
) -> core::result::Result<MemoryRange, Error> {
|
||||||
crate::arch::map_memory_pre(&phys, &virt, size, flags)?;
|
crate::arch::map_memory_pre(&phys, &virt, size, flags)?;
|
||||||
let result = rsyscall(SysCall::MapMemory(
|
let result =
|
||||||
phys,
|
rsyscall(SysCall::MapMemory(phys, virt, MemorySize::new(size).ok_or(Error::InvalidSyscall)?, flags))?;
|
||||||
virt,
|
|
||||||
MemorySize::new(size).ok_or(Error::InvalidSyscall)?,
|
|
||||||
flags,
|
|
||||||
))?;
|
|
||||||
if let Result::MemoryRange(range) = result {
|
if let Result::MemoryRange(range) = result {
|
||||||
Ok(crate::arch::map_memory_post(
|
Ok(crate::arch::map_memory_post(phys, virt, size, flags, range)?)
|
||||||
phys, virt, size, flags, range,
|
|
||||||
)?)
|
|
||||||
} else if let Result::Error(e) = result {
|
} else if let Result::Error(e) = result {
|
||||||
Err(e)
|
Err(e)
|
||||||
} else {
|
} else {
|
||||||
|
|
@ -1358,10 +1134,7 @@ pub fn unmap_memory(range: MemoryRange) -> core::result::Result<(), Error> {
|
||||||
|
|
||||||
/// Update the permissions on the given memory range. Note that permissions may
|
/// Update the permissions on the given memory range. Note that permissions may
|
||||||
/// only be stripped here -- they may never be added.
|
/// only be stripped here -- they may never be added.
|
||||||
pub fn update_memory_flags(
|
pub fn update_memory_flags(range: MemoryRange, flags: MemoryFlags) -> core::result::Result<Result, Error> {
|
||||||
range: MemoryRange,
|
|
||||||
flags: MemoryFlags,
|
|
||||||
) -> core::result::Result<Result, Error> {
|
|
||||||
let result = rsyscall(SysCall::UpdateMemoryFlags(range, flags, None))?;
|
let result = rsyscall(SysCall::UpdateMemoryFlags(range, flags, None))?;
|
||||||
if let Result::Ok = result {
|
if let Result::Ok = result {
|
||||||
Ok(Result::Ok)
|
Ok(Result::Ok)
|
||||||
|
|
@ -1435,11 +1208,7 @@ pub fn return_scalar(sender: MessageSender, val: usize) -> core::result::Result<
|
||||||
|
|
||||||
/// Map the given physical address to the given virtual address.
|
/// Map the given physical address to the given virtual address.
|
||||||
/// The `size` field must be page-aligned.
|
/// The `size` field must be page-aligned.
|
||||||
pub fn return_scalar2(
|
pub fn return_scalar2(sender: MessageSender, val1: usize, val2: usize) -> core::result::Result<(), Error> {
|
||||||
sender: MessageSender,
|
|
||||||
val1: usize,
|
|
||||||
val2: usize,
|
|
||||||
) -> core::result::Result<(), Error> {
|
|
||||||
let result = rsyscall(SysCall::ReturnScalar2(sender, val1, val2))?;
|
let result = rsyscall(SysCall::ReturnScalar2(sender, val1, val2))?;
|
||||||
if let crate::Result::Ok = result {
|
if let crate::Result::Ok = result {
|
||||||
Ok(())
|
Ok(())
|
||||||
|
|
@ -1497,9 +1266,8 @@ pub fn claim_interrupt(
|
||||||
///
|
///
|
||||||
/// # Errors
|
/// # Errors
|
||||||
///
|
///
|
||||||
/// * **OutOfMemory**: No more servers may be created because the server
|
/// * **OutOfMemory**: No more servers may be created because the server count limit has been reached, or the
|
||||||
/// count limit has been reached, or the system does not
|
/// system does not have enough memory for the backing store.
|
||||||
/// have enough memory for the backing store.
|
|
||||||
/// * **ServerExists**: A server has already registered with that name
|
/// * **ServerExists**: A server has already registered with that name
|
||||||
/// * **InvalidString**: The name was not a valid UTF-8 string
|
/// * **InvalidString**: The name was not a valid UTF-8 string
|
||||||
pub fn create_server_with_address(name_bytes: &[u8; 16]) -> core::result::Result<SID, Error> {
|
pub fn create_server_with_address(name_bytes: &[u8; 16]) -> core::result::Result<SID, Error> {
|
||||||
|
|
@ -1522,9 +1290,8 @@ pub fn create_server_with_address(name_bytes: &[u8; 16]) -> core::result::Result
|
||||||
///
|
///
|
||||||
/// # Errors
|
/// # Errors
|
||||||
///
|
///
|
||||||
/// * **OutOfMemory**: No more servers may be created because the server
|
/// * **OutOfMemory**: No more servers may be created because the server count limit has been reached, or the
|
||||||
/// count limit has been reached, or the system does not
|
/// system does not have enough memory for the backing store.
|
||||||
/// have enough memory for the backing store.
|
|
||||||
/// * **ServerExists**: A server has already registered with that name
|
/// * **ServerExists**: A server has already registered with that name
|
||||||
/// * **InvalidString**: The name was not a valid UTF-8 string
|
/// * **InvalidString**: The name was not a valid UTF-8 string
|
||||||
pub fn create_server_with_sid(sid: SID) -> core::result::Result<SID, Error> {
|
pub fn create_server_with_sid(sid: SID) -> core::result::Result<SID, Error> {
|
||||||
|
|
@ -1546,9 +1313,8 @@ pub fn create_server_with_sid(sid: SID) -> core::result::Result<SID, Error> {
|
||||||
/// # Errors
|
/// # Errors
|
||||||
///
|
///
|
||||||
/// * **ServerNotFound**: No more servers may be created
|
/// * **ServerNotFound**: No more servers may be created
|
||||||
/// * **OutOfMemory**: No more servers may be created because the server
|
/// * **OutOfMemory**: No more servers may be created because the server count limit has been reached, or the
|
||||||
/// count limit has been reached, or the system does not
|
/// system does not have enough memory for the backing store.
|
||||||
/// have enough memory for the backing store.
|
|
||||||
pub fn create_server() -> core::result::Result<SID, Error> {
|
pub fn create_server() -> core::result::Result<SID, Error> {
|
||||||
let result = rsyscall(SysCall::CreateServer)?;
|
let result = rsyscall(SysCall::CreateServer)?;
|
||||||
if let Result::NewServerID(sid, _cid) = result {
|
if let Result::NewServerID(sid, _cid) = result {
|
||||||
|
|
@ -1568,7 +1334,6 @@ pub fn create_server() -> core::result::Result<SID, Error> {
|
||||||
/// The implementation is just a call to the kernel-exclusive TRNG to fetch random numbers.
|
/// The implementation is just a call to the kernel-exclusive TRNG to fetch random numbers.
|
||||||
///
|
///
|
||||||
/// # Errors
|
/// # Errors
|
||||||
///
|
|
||||||
pub fn create_server_id() -> core::result::Result<SID, Error> {
|
pub fn create_server_id() -> core::result::Result<SID, Error> {
|
||||||
let result = rsyscall(SysCall::CreateServerId)?;
|
let result = rsyscall(SysCall::CreateServerId)?;
|
||||||
if let Result::ServerID(sid) = result {
|
if let Result::ServerID(sid) = result {
|
||||||
|
|
@ -1608,7 +1373,6 @@ pub fn try_connect(server: SID) -> core::result::Result<CID, Error> {
|
||||||
/// block until a message is received.
|
/// block until a message is received.
|
||||||
///
|
///
|
||||||
/// # Errors
|
/// # Errors
|
||||||
///
|
|
||||||
pub fn receive_message(server: SID) -> core::result::Result<MessageEnvelope, Error> {
|
pub fn receive_message(server: SID) -> core::result::Result<MessageEnvelope, Error> {
|
||||||
let result = rsyscall(SysCall::ReceiveMessage(server)).expect("Couldn't call ReceiveMessage");
|
let result = rsyscall(SysCall::ReceiveMessage(server)).expect("Couldn't call ReceiveMessage");
|
||||||
if let Result::MessageEnvelope(envelope) = result {
|
if let Result::MessageEnvelope(envelope) = result {
|
||||||
|
|
@ -1624,10 +1388,8 @@ pub fn receive_message(server: SID) -> core::result::Result<MessageEnvelope, Err
|
||||||
/// is available, returns `Ok(None)` without blocking
|
/// is available, returns `Ok(None)` without blocking
|
||||||
///
|
///
|
||||||
/// # Errors
|
/// # Errors
|
||||||
///
|
|
||||||
pub fn try_receive_message(server: SID) -> core::result::Result<Option<MessageEnvelope>, Error> {
|
pub fn try_receive_message(server: SID) -> core::result::Result<Option<MessageEnvelope>, Error> {
|
||||||
let result =
|
let result = rsyscall(SysCall::TryReceiveMessage(server)).expect("Couldn't call ReceiveMessage");
|
||||||
rsyscall(SysCall::TryReceiveMessage(server)).expect("Couldn't call ReceiveMessage");
|
|
||||||
if let Result::MessageEnvelope(envelope) = result {
|
if let Result::MessageEnvelope(envelope) = result {
|
||||||
Ok(Some(envelope))
|
Ok(Some(envelope))
|
||||||
} else if result == Result::None {
|
} else if result == Result::None {
|
||||||
|
|
@ -1714,19 +1476,12 @@ pub fn terminate_process(exit_code: u32) -> ! {
|
||||||
|
|
||||||
/// Return execution to the kernel. This function may return at any time,
|
/// Return execution to the kernel. This function may return at any time,
|
||||||
/// including immediately
|
/// including immediately
|
||||||
pub fn yield_slice() {
|
pub fn yield_slice() { rsyscall(SysCall::Yield).ok(); }
|
||||||
rsyscall(SysCall::Yield).ok();
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Return execution to the kernel and wait for a message or an interrupt.
|
/// Return execution to the kernel and wait for a message or an interrupt.
|
||||||
pub fn wait_event() {
|
pub fn wait_event() { rsyscall(SysCall::WaitEvent).ok(); }
|
||||||
rsyscall(SysCall::WaitEvent).ok();
|
|
||||||
}
|
|
||||||
|
|
||||||
#[deprecated(
|
#[deprecated(since = "0.2.0", note = "Please use create_thread_n() or create_thread()")]
|
||||||
since = "0.2.0",
|
|
||||||
note = "Please use create_thread_n() or create_thread()"
|
|
||||||
)]
|
|
||||||
pub fn create_thread_simple<T, U>(
|
pub fn create_thread_simple<T, U>(
|
||||||
f: fn(T) -> U,
|
f: fn(T) -> U,
|
||||||
arg: T,
|
arg: T,
|
||||||
|
|
@ -1879,9 +1634,7 @@ pub fn wait_process_as_thread(joiner: crate::arch::ProcessHandleAsThread) -> Sys
|
||||||
crate::arch::wait_process_as_thread(joiner)
|
crate::arch::wait_process_as_thread(joiner)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn create_process(
|
pub fn create_process(args: ProcessArgs) -> core::result::Result<crate::arch::ProcessHandle, Error> {
|
||||||
args: ProcessArgs,
|
|
||||||
) -> core::result::Result<crate::arch::ProcessHandle, Error> {
|
|
||||||
let process_init = crate::arch::create_process_pre(&args)?;
|
let process_init = crate::arch::create_process_pre(&args)?;
|
||||||
rsyscall(SysCall::CreateProcess(process_init)).and_then(|result| {
|
rsyscall(SysCall::CreateProcess(process_init)).and_then(|result| {
|
||||||
if let Result::NewProcess(startup) = result {
|
if let Result::NewProcess(startup) = result {
|
||||||
|
|
@ -1893,40 +1646,25 @@ pub fn create_process(
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Wait for a thread to finish
|
/// Wait for a thread to finish
|
||||||
pub fn wait_process(joiner: crate::arch::ProcessHandle) -> SysCallResult {
|
pub fn wait_process(joiner: crate::arch::ProcessHandle) -> SysCallResult { crate::arch::wait_process(joiner) }
|
||||||
crate::arch::wait_process(joiner)
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Get the current process ID
|
/// Get the current process ID
|
||||||
pub fn current_pid() -> core::result::Result<PID, Error> {
|
pub fn current_pid() -> core::result::Result<PID, Error> {
|
||||||
rsyscall(SysCall::GetProcessId).and_then(|result| {
|
rsyscall(SysCall::GetProcessId).and_then(|result| {
|
||||||
if let Result::ProcessID(pid) = result {
|
if let Result::ProcessID(pid) = result { Ok(pid) } else { Err(Error::InternalError) }
|
||||||
Ok(pid)
|
|
||||||
} else {
|
|
||||||
Err(Error::InternalError)
|
|
||||||
}
|
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Get the current thread ID
|
/// Get the current thread ID
|
||||||
pub fn current_tid() -> core::result::Result<TID, Error> {
|
pub fn current_tid() -> core::result::Result<TID, Error> {
|
||||||
rsyscall(SysCall::GetThreadId).and_then(|result| {
|
rsyscall(SysCall::GetThreadId).and_then(|result| {
|
||||||
if let Result::ThreadID(tid) = result {
|
if let Result::ThreadID(tid) = result { Ok(tid) } else { Err(Error::InternalError) }
|
||||||
Ok(tid)
|
|
||||||
} else {
|
|
||||||
Err(Error::InternalError)
|
|
||||||
}
|
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn destroy_server(sid: SID) -> core::result::Result<(), Error> {
|
pub fn destroy_server(sid: SID) -> core::result::Result<(), Error> {
|
||||||
rsyscall(SysCall::DestroyServer(sid)).and_then(|result| {
|
rsyscall(SysCall::DestroyServer(sid))
|
||||||
if let Result::Ok = result {
|
.and_then(|result| if let Result::Ok = result { Ok(()) } else { Err(Error::InternalError) })
|
||||||
Ok(())
|
|
||||||
} else {
|
|
||||||
Err(Error::InternalError)
|
|
||||||
}
|
|
||||||
})
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Disconnect the specified connection ID and mark it as free. This
|
/// Disconnect the specified connection ID and mark it as free. This
|
||||||
|
|
@ -1940,13 +1678,8 @@ pub fn destroy_server(sid: SID) -> core::result::Result<(), Error> {
|
||||||
/// in kernel errors or, if the CID is reused, silent failures due to
|
/// in kernel errors or, if the CID is reused, silent failures due to
|
||||||
/// messages going to the wrong server.
|
/// messages going to the wrong server.
|
||||||
pub unsafe fn disconnect(cid: CID) -> core::result::Result<(), Error> {
|
pub unsafe fn disconnect(cid: CID) -> core::result::Result<(), Error> {
|
||||||
rsyscall(SysCall::Disconnect(cid)).and_then(|result| {
|
rsyscall(SysCall::Disconnect(cid))
|
||||||
if let Result::Ok = result {
|
.and_then(|result| if let Result::Ok = result { Ok(()) } else { Err(Error::InternalError) })
|
||||||
Ok(())
|
|
||||||
} else {
|
|
||||||
Err(Error::InternalError)
|
|
||||||
}
|
|
||||||
})
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Block the current thread and wait for the specified thread to
|
/// Block the current thread and wait for the specified thread to
|
||||||
|
|
@ -1987,9 +1720,8 @@ pub fn reply_and_receive_next(
|
||||||
///
|
///
|
||||||
/// * **server**: The SID of the server to receive messages from
|
/// * **server**: The SID of the server to receive messages from
|
||||||
/// * **msg**: An `Option<MessageEnvelope>` specifying the message to return.
|
/// * **msg**: An `Option<MessageEnvelope>` specifying the message to return.
|
||||||
/// * **return_type**: If 1 or 2, responds to a BlockingScalarMessage
|
/// * **return_type**: If 1 or 2, responds to a BlockingScalarMessage with a Scalar1 or a Scalar2. Otherwise,
|
||||||
/// with a Scalar1 or a Scalar2. Otherwise, will respond
|
/// will respond as normal.
|
||||||
/// as normal.
|
|
||||||
pub fn reply_and_receive_next_legacy(
|
pub fn reply_and_receive_next_legacy(
|
||||||
server: SID,
|
server: SID,
|
||||||
msg: &mut Option<MessageEnvelope>,
|
msg: &mut Option<MessageEnvelope>,
|
||||||
|
|
@ -2016,8 +1748,7 @@ pub fn reply_and_receive_next_legacy(
|
||||||
};
|
};
|
||||||
let sender = envelope.sender;
|
let sender = envelope.sender;
|
||||||
core::mem::forget(envelope);
|
core::mem::forget(envelope);
|
||||||
let call =
|
let call = SysCall::ReplyAndReceiveNext(sender, args[0], args[1], args[2], args[3], args[4], rt);
|
||||||
SysCall::ReplyAndReceiveNext(sender, args[0], args[1], args[2], args[3], args[4], rt);
|
|
||||||
match rsyscall(call) {
|
match rsyscall(call) {
|
||||||
Ok(crate::Result::MessageEnvelope(envelope)) => {
|
Ok(crate::Result::MessageEnvelope(envelope)) => {
|
||||||
*msg = Some(envelope);
|
*msg = Some(envelope);
|
||||||
|
|
@ -2070,31 +1801,20 @@ pub fn set_exception_handler(
|
||||||
/// Translate a virtual address to a physical address
|
/// Translate a virtual address to a physical address
|
||||||
#[cfg(feature = "v2p")]
|
#[cfg(feature = "v2p")]
|
||||||
pub fn virt_to_phys(va: usize) -> core::result::Result<usize, Error> {
|
pub fn virt_to_phys(va: usize) -> core::result::Result<usize, Error> {
|
||||||
rsyscall(SysCall::VirtToPhys(va)).and_then(|result| {
|
rsyscall(SysCall::VirtToPhys(va))
|
||||||
if let Result::Scalar1(pa) = result {
|
.and_then(|result| if let Result::Scalar1(pa) = result { Ok(pa) } else { Err(Error::BadAddress) })
|
||||||
Ok(pa)
|
|
||||||
} else {
|
|
||||||
Err(Error::BadAddress)
|
|
||||||
}
|
|
||||||
})
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Translate a virtual address to a physical address for a given process
|
/// Translate a virtual address to a physical address for a given process
|
||||||
#[cfg(feature = "v2p")]
|
#[cfg(feature = "v2p")]
|
||||||
pub fn virt_to_phys_pid(pid: PID, va: usize) -> core::result::Result<usize, Error> {
|
pub fn virt_to_phys_pid(pid: PID, va: usize) -> core::result::Result<usize, Error> {
|
||||||
rsyscall(SysCall::VirtToPhysPid(pid, va)).and_then(|result| {
|
rsyscall(SysCall::VirtToPhysPid(pid, va))
|
||||||
if let Result::Scalar1(pa) = result {
|
.and_then(|result| if let Result::Scalar1(pa) = result { Ok(pa) } else { Err(Error::BadAddress) })
|
||||||
Ok(pa)
|
|
||||||
} else {
|
|
||||||
Err(Error::BadAddress)
|
|
||||||
}
|
|
||||||
})
|
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn increase_heap(bytes: usize, flags: MemoryFlags) -> core::result::Result<MemoryRange, ()> {
|
pub fn increase_heap(bytes: usize, flags: MemoryFlags) -> core::result::Result<MemoryRange, ()> {
|
||||||
let res = crate::arch::syscall(SysCall::IncreaseHeap(bytes, flags));
|
let res = crate::arch::syscall(SysCall::IncreaseHeap(bytes, flags));
|
||||||
if let Ok(Result::MemoryRange(range)) = res
|
if let Ok(Result::MemoryRange(range)) = res {
|
||||||
{
|
|
||||||
return Ok(range);
|
return Ok(range);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -2103,9 +1823,7 @@ pub fn increase_heap(bytes: usize, flags: MemoryFlags) -> core::result::Result<M
|
||||||
|
|
||||||
/// Perform a raw syscall and return the result. This will transform
|
/// Perform a raw syscall and return the result. This will transform
|
||||||
/// `xous::Result::Error(e)` into an `Err(e)`.
|
/// `xous::Result::Error(e)` into an `Err(e)`.
|
||||||
pub fn rsyscall(call: SysCall) -> SysCallResult {
|
pub fn rsyscall(call: SysCall) -> SysCallResult { crate::arch::syscall(call) }
|
||||||
crate::arch::syscall(call)
|
|
||||||
}
|
|
||||||
|
|
||||||
// /// This is dangerous, but fast.
|
// /// This is dangerous, but fast.
|
||||||
// pub unsafe fn dangerous_syscall(call: SysCall) -> SyscallResult {
|
// pub unsafe fn dangerous_syscall(call: SysCall) -> SyscallResult {
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue