kernel: implement CreateServer

This implements CreateServer, which creates a server with a random name.

Signed-off-by: Sean Cross <sean@xobs.io>
This commit is contained in:
Sean Cross 2020-12-04 20:55:09 +08:00
parent f165130931
commit 85b6357d26
6 changed files with 50 additions and 4 deletions

View file

@ -1,6 +1,7 @@
pub mod irq;
pub mod mem;
pub mod process;
pub mod rand;
pub mod syscall;
use std::cell::RefCell;
@ -548,14 +549,15 @@ pub fn idle() -> bool {
"Unable to send response to process: {:?} -- terminating",
_e
);
crate::syscall::handle(pid, thread_id, false, SysCall::TerminateProcess).ok();
crate::syscall::handle(pid, thread_id, false, SysCall::TerminateProcess)
.ok();
});
// println!("KERNEL: Done sending");
}
// Handle the syscall within the Xous kernel
let response =
crate::syscall::handle(pid, thread_id, false, call).unwrap_or_else(Result::Error);
let response = crate::syscall::handle(pid, thread_id, false, call)
.unwrap_or_else(Result::Error);
// println!("KERNEL({}): Syscall response {:?}", pid, response);
// There's a response if it wasn't a blocked process and we're not terminating.
@ -584,7 +586,8 @@ pub fn idle() -> bool {
"KERNEL({}): Unable to send response to process: {:?} -- terminating",
pid, _e
);
crate::syscall::handle(pid, thread_id, false, SysCall::TerminateProcess).ok();
crate::syscall::handle(pid, thread_id, false, SysCall::TerminateProcess)
.ok();
});
crate::arch::process::set_current_pid(existing_pid);
}

View file

@ -0,0 +1,3 @@
pub fn get_u32() -> u32 {
::rand::random()
}

View file

@ -5,6 +5,7 @@ pub mod exception;
pub mod irq;
pub mod mem;
pub mod process;
pub mod rand;
pub mod syscall;
pub use process::Thread;

View file

@ -0,0 +1,16 @@
static mut LFSR: u32 = 0xace1u32;
fn move_lfsr(mut lfsr: u32) -> u32 {
lfsr ^= lfsr >> 7;
lfsr ^= lfsr << 9;
lfsr ^= lfsr >> 13;
lfsr
}
pub fn get_u32() -> u32 {
// The kernel is currently single-threaded, so this is a valid operation.
unsafe {
LFSR = move_lfsr(LFSR);
LFSR
}
}

View file

@ -1348,6 +1348,25 @@ impl SystemServices {
Err(xous_kernel::Error::ServerNotFound)
}
/// Generate a new server ID for this process and then create a new server.
/// If the
/// server table is full, or if there is not enough memory to map the server queue,
/// return an error.
///
/// # Errors
///
/// * **OutOfMemory**: A new page could not be assigned to store the server
/// queue.
/// * **ServerNotFound**: The server queue was full and a free slot could not
/// be found.
pub fn create_server(
&mut self,
pid: PID,
) -> Result<(SID, CID), xous_kernel::Error> {
let sid = SID::from_u32(arch::rand::get_u32(), arch::rand::get_u32(), arch::rand::get_u32(), arch::rand::get_u32());
self.create_server_with_address(pid, sid)
}
/// Allocate a new server ID for this process and return the address. If the
/// server table is full, return an error.
pub fn connect_to_server(&mut self, sid: SID) -> Result<CID, xous_kernel::Error> {

View file

@ -751,6 +751,10 @@ pub fn handle_inner(pid: PID, tid: TID, in_irq: bool, call: SysCall) -> SysCallR
ss.create_server_with_address(pid, name)
.map(|(sid, cid)| xous_kernel::Result::NewServerID(sid, cid))
}),
SysCall::CreateServer => SystemServices::with_mut(|ss| {
ss.create_server(pid)
.map(|(sid, cid)| xous_kernel::Result::NewServerID(sid, cid))
}),
SysCall::TryConnect(sid) => SystemServices::with_mut(|ss| {
ss.connect_to_server(sid)
.map(xous_kernel::Result::ConnectionID)