xous-rs: implement create_server call

This call isn't properly handled by the kernel, but it's now available
in the standard library.

Signed-off-by: Sean Cross <sean@xobs.io>
This commit is contained in:
Sean Cross 2020-03-16 19:03:51 +08:00
parent 85522602ea
commit 1b8f97a5a3
2 changed files with 18 additions and 6 deletions

View file

@ -10,3 +10,13 @@ pub mod syscall;
pub use definitions::*;
pub use syscall::*;
/// Convert a four-letter string into a 32-bit int.
#[macro_export]
macro_rules! make_name {
($fcc:expr) => {{
let mut c: [u8; 4] = Default::default();
c.copy_from_slice($fcc.as_bytes());
usize::from_le_bytes(c)
}};
}

View file

@ -222,7 +222,9 @@ pub enum SysCall {
/// Create a new Server
///
/// This will return a 128-bit Server ID that can be used to send messages
/// to this server.
/// to this server. This ID will be unique per process. You may specify
/// an additional `usize` value to make the ID unique. This value will be
/// mixed in with the random value.
///
/// # Returns
///
@ -233,7 +235,7 @@ pub enum SysCall {
///
/// * **OutOfMemory**: The server table was full and a new server couldn't
/// be created.
CreateServer,
CreateServer(usize /* server name */),
/// This syscall does not exist
Invalid(usize, usize, usize, usize, usize, usize, usize),
@ -353,7 +355,7 @@ impl SysCall {
0,
],
SysCall::CreateServer => [SysCallNumber::CreateServer as usize, 0, 0, 0, 0, 0, 0, 0],
SysCall::CreateServer(a1) => [SysCallNumber::CreateServer as usize, a1, 0, 0, 0, 0, 0, 0],
SysCall::Invalid(a1, a2, a3, a4, a5, a6, a7) => {
[SysCallNumber::Invalid as usize, a1, a2, a3, a4, a5, a6, a7]
}
@ -397,7 +399,7 @@ impl SysCall {
Some(SysCallNumber::SetMemRegion) => {
SysCall::SetMemRegion(a1 as PID, MemoryType::from(a2), a3 as *mut usize, a4)
}
Some(SysCallNumber::CreateServer) => SysCall::CreateServer,
Some(SysCallNumber::CreateServer) => SysCall::CreateServer(a1),
Some(SysCallNumber::Invalid) => SysCall::Invalid(a1, a2, a3, a4, a5, a6, a7),
None => return Err(InvalidSyscall {}),
})
@ -494,8 +496,8 @@ pub fn claim_interrupt(
}
/// Create a new server. Returns the new server address.
pub fn create_server() -> core::result::Result<SID, Error> {
let result = rsyscall(SysCall::CreateServer)?;
pub fn create_server(name: usize) -> core::result::Result<SID, Error> {
let result = rsyscall(SysCall::CreateServer(name))?;
if let Result::ServerID(sid) = result {
return Ok(sid);
}