mirror of
https://github.com/saymrwulf/xous-core.git
synced 2026-11-13 07:48:30 +00:00
process: finish implementing ProcessStartup as return
We now us `ProcessStartup` as the return type. This builds in tset mode, hosted mode, and RISC-V mode. Process Startup is still not implemented for RISC-V mode. Signed-off-by: Sean Cross <sean@xobs.io>
This commit is contained in:
parent
0378fcf7aa
commit
e68e52d89c
10 changed files with 64 additions and 31 deletions
|
|
@ -485,9 +485,9 @@ pub fn idle() -> bool {
|
|||
let pid1_init = ProcessInit {
|
||||
key: ProcessKey::new(pid1_key),
|
||||
};
|
||||
let pid1 = SystemServices::with_mut(|ss| ss.create_process(pid1_init)).unwrap();
|
||||
assert_eq!(pid1.get(), 1);
|
||||
let _tid1 = SystemServices::with_mut(|ss| ss.create_thread(pid1, ThreadInit {})).unwrap();
|
||||
let process_1 = SystemServices::with_mut(|ss| ss.create_process(pid1_init)).unwrap();
|
||||
assert_eq!(process_1.pid().get(), 1);
|
||||
let _tid1 = SystemServices::with_mut(|ss| ss.create_thread(process_1.pid(), ThreadInit {})).unwrap();
|
||||
|
||||
let listen_addr = env::var("XOUS_LISTEN_ADDR")
|
||||
.map(|s| {
|
||||
|
|
@ -524,7 +524,7 @@ pub fn idle() -> bool {
|
|||
|
||||
// Set the current PID to 1, which was created above. This ensures all init processes
|
||||
// are owned by PID1.
|
||||
crate::arch::process::set_current_pid(pid1);
|
||||
crate::arch::process::set_current_pid(process_1.pid());
|
||||
|
||||
// Go through each arg and spawn it as a new process. Failures here will
|
||||
// halt the entire system.
|
||||
|
|
@ -535,10 +535,10 @@ pub fn idle() -> bool {
|
|||
let init = xous_kernel::ProcessInit {
|
||||
key: ProcessKey::new(process_key),
|
||||
};
|
||||
let new_pid = SystemServices::with_mut(|ss| ss.create_process(init)).unwrap();
|
||||
println!(" {:^5} | {}", new_pid, arg);
|
||||
let new_process = SystemServices::with_mut(|ss| ss.create_process(init)).unwrap();
|
||||
println!(" {:^5} | {}", new_process, arg);
|
||||
let process_args = xous_kernel::ProcessArgs::new("program", arg);
|
||||
xous_kernel::arch::create_process_post(process_args, init, new_pid)
|
||||
xous_kernel::arch::create_process_post(process_args, init, new_process)
|
||||
.expect("couldn't spawn");
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -7,7 +7,7 @@ use core::cell::RefCell;
|
|||
use std::io::Write;
|
||||
use std::net::TcpStream;
|
||||
use std::thread_local;
|
||||
use xous_kernel::{ProcessInit, ProcessKey, ThreadInit, PID, TID};
|
||||
use xous_kernel::{ProcessInit, ProcessKey, ProcessStartup, ThreadInit, PID, TID};
|
||||
|
||||
pub const INITIAL_TID: usize = 2;
|
||||
pub const EXCEPTION_TID: usize = 1;
|
||||
|
|
@ -337,7 +337,7 @@ impl Process {
|
|||
/// Initialize this process with the given memory space. THIS DOES NOT
|
||||
/// INITIALIZE A MAIN THREAD. You must call `setup_thread()` in order to
|
||||
/// select a main thread.
|
||||
pub fn create(pid: PID, init_data: ProcessInit) -> PID {
|
||||
pub fn create(pid: PID, init_data: ProcessInit) -> ProcessStartup {
|
||||
PROCESS_TABLE.with(|process_table| {
|
||||
let mut process_table = process_table.borrow_mut();
|
||||
let pid_idx = (pid.get() - 1) as usize;
|
||||
|
|
@ -359,7 +359,7 @@ impl Process {
|
|||
} else {
|
||||
panic!("pid already allocated!");
|
||||
}
|
||||
pid
|
||||
ProcessStartup::new(pid)
|
||||
})
|
||||
}
|
||||
|
||||
|
|
@ -376,7 +376,7 @@ impl Process {
|
|||
.as_mut()
|
||||
.unwrap()
|
||||
.shutdown(std::net::Shutdown::Both)
|
||||
.unwrap();
|
||||
.ok();
|
||||
process_table.table[pid_idx] = None;
|
||||
process_table.total -= 1;
|
||||
Ok(())
|
||||
|
|
|
|||
|
|
@ -9,7 +9,7 @@ pub const INITIAL_TID: TID = 2;
|
|||
pub const IRQ_TID: TID = 0;
|
||||
use crate::arch::mem::PAGE_SIZE;
|
||||
use crate::services::ProcessInner;
|
||||
use xous_kernel::{ProcessInit, ThreadInit, PID, TID};
|
||||
use xous_kernel::{ProcessInit, ThreadInit, PID, TID, ProcessStartup};
|
||||
|
||||
// use crate::args::KernelArguments;
|
||||
pub const DEFAULT_STACK_SIZE: usize = 131072;
|
||||
|
|
@ -497,7 +497,7 @@ impl Process {
|
|||
);
|
||||
}
|
||||
|
||||
pub fn create(_pid: PID, _init_data: ProcessInit) -> PID {
|
||||
pub fn create(_pid: PID, _init_data: ProcessInit) -> ProcessStartup {
|
||||
todo!();
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -6,6 +6,7 @@ use crate::arch::mem::MemoryMapping;
|
|||
pub use crate::arch::process::Process as ArchProcess;
|
||||
pub use crate::arch::process::Thread;
|
||||
use xous_kernel::MemoryRange;
|
||||
use xous_kernel::arch::ProcessStartup;
|
||||
|
||||
use core::num::NonZeroU8;
|
||||
|
||||
|
|
@ -389,19 +390,19 @@ impl SystemServices {
|
|||
|
||||
/// Add a new entry to the process table. This results in a new address space
|
||||
/// and a new PID, though the process is in the state `Setup()`.
|
||||
pub fn create_process(&mut self, init_process: ProcessInit) -> Result<PID, xous_kernel::Error> {
|
||||
pub fn create_process(&mut self, init_process: ProcessInit) -> Result<ProcessStartup, xous_kernel::Error> {
|
||||
for (idx, mut entry) in self.processes.iter_mut().enumerate() {
|
||||
if entry.state != ProcessState::Free {
|
||||
continue;
|
||||
}
|
||||
let new_pid = pid_from_usize(idx + 1)?;
|
||||
arch::process::Process::create(new_pid, init_process);
|
||||
let startup = arch::process::Process::create(new_pid, init_process);
|
||||
let ppid = crate::arch::process::current_pid();
|
||||
// println!("Creating new process for PID {} with PPID {}", new_pid, ppid);
|
||||
entry.state = ProcessState::Allocated;
|
||||
entry.ppid = ppid;
|
||||
entry.pid = new_pid;
|
||||
return Ok(new_pid);
|
||||
return Ok(startup);
|
||||
}
|
||||
Err(xous_kernel::Error::ProcessNotFound)
|
||||
}
|
||||
|
|
|
|||
|
|
@ -803,7 +803,7 @@ pub fn handle_inner(pid: PID, tid: TID, in_irq: bool, call: SysCall) -> SysCallR
|
|||
}),
|
||||
SysCall::CreateProcess(process_init) => SystemServices::with_mut(|ss| {
|
||||
ss.create_process(process_init)
|
||||
.map(xous_kernel::Result::ProcessID)
|
||||
.map(xous_kernel::Result::NewProcess)
|
||||
}),
|
||||
SysCall::CreateServerWithAddress(name) => SystemServices::with_mut(|ss| {
|
||||
ss.create_server_with_address(pid, name)
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
use super::{CHILD_PROCESS_ADDRESS};
|
||||
use super::CHILD_PROCESS_ADDRESS;
|
||||
pub use crate::PID;
|
||||
use core::convert::{TryFrom, TryInto};
|
||||
|
||||
|
|
@ -69,6 +69,22 @@ pub struct ProcessStartup {
|
|||
pid: crate::PID,
|
||||
}
|
||||
|
||||
impl ProcessStartup {
|
||||
pub fn new(pid: crate::PID) -> Self {
|
||||
ProcessStartup { pid }
|
||||
}
|
||||
|
||||
pub fn pid(&self) -> crate::PID {
|
||||
self.pid
|
||||
}
|
||||
}
|
||||
|
||||
impl core::fmt::Display for ProcessStartup {
|
||||
fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
|
||||
write!(f, "{}", self.pid)
|
||||
}
|
||||
}
|
||||
|
||||
impl From<&[usize; 7]> for ProcessStartup {
|
||||
fn from(src: &[usize; 7]) -> ProcessStartup {
|
||||
ProcessStartup {
|
||||
|
|
@ -103,11 +119,11 @@ pub fn create_process_pre(_args: &ProcessArgs) -> core::result::Result<ProcessIn
|
|||
pub fn create_process_post(
|
||||
args: ProcessArgs,
|
||||
init: ProcessInit,
|
||||
pid: PID,
|
||||
startup: ProcessStartup,
|
||||
) -> core::result::Result<ProcessHandle, crate::Error> {
|
||||
use std::process::Command;
|
||||
let server_env = format!("{}", CHILD_PROCESS_ADDRESS.lock().unwrap());
|
||||
let pid_env = format!("{}", pid);
|
||||
let pid_env = format!("{}", startup.pid);
|
||||
let process_name_env = args.name.to_string();
|
||||
let process_key_env = hex::encode(&init.key.0);
|
||||
let (shell, args) = if cfg!(windows) {
|
||||
|
|
|
|||
|
|
@ -116,9 +116,9 @@ pub fn create_process_pre(_args: &ProcessArgs) -> core::result::Result<ProcessIn
|
|||
pub fn create_process_post(
|
||||
_args: ProcessArgs,
|
||||
_init: ProcessInit,
|
||||
pid: crate::PID,
|
||||
startup: ProcessStartup,
|
||||
) -> core::result::Result<ProcessHandle, crate::Error> {
|
||||
Ok(ProcessHandle(pid))
|
||||
Ok(ProcessHandle(startup.pid))
|
||||
}
|
||||
|
||||
/// Wait for a process to terminate.
|
||||
|
|
|
|||
|
|
@ -69,12 +69,13 @@ where
|
|||
pub fn create_process_post_as_thread<F>(
|
||||
args: ProcessArgsAsThread<F>,
|
||||
init: ProcessInit,
|
||||
pid: PID,
|
||||
startup: ProcessStartup,
|
||||
) -> core::result::Result<ProcessHandleAsThread, crate::Error>
|
||||
where
|
||||
F: FnOnce() + Send + 'static,
|
||||
{
|
||||
let server_address = xous_address();
|
||||
let pid = startup.pid;
|
||||
|
||||
let f = args.main;
|
||||
let thread_main = std::thread::Builder::new()
|
||||
|
|
@ -132,6 +133,22 @@ pub struct ProcessStartup {
|
|||
pid: crate::PID,
|
||||
}
|
||||
|
||||
impl ProcessStartup {
|
||||
pub fn new(pid: crate::PID) -> Self {
|
||||
ProcessStartup { pid }
|
||||
}
|
||||
|
||||
pub fn pid(&self) -> crate::PID {
|
||||
self.pid
|
||||
}
|
||||
}
|
||||
|
||||
impl core::fmt::Display for ProcessStartup {
|
||||
fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
|
||||
write!(f, "{}", self.pid)
|
||||
}
|
||||
}
|
||||
|
||||
impl From<&[usize; 7]> for ProcessStartup {
|
||||
fn from(src: &[usize; 7]) -> ProcessStartup {
|
||||
ProcessStartup {
|
||||
|
|
@ -153,7 +170,6 @@ impl Into<[usize; 7]> for &ProcessStartup {
|
|||
}
|
||||
}
|
||||
|
||||
|
||||
impl Into<[usize; 7]> for &ProcessInit {
|
||||
fn into(self) -> [usize; 7] {
|
||||
[
|
||||
|
|
@ -204,11 +220,11 @@ pub fn create_process_pre(_args: &ProcessArgs) -> core::result::Result<ProcessIn
|
|||
pub fn create_process_post(
|
||||
args: ProcessArgs,
|
||||
init: ProcessInit,
|
||||
pid: PID,
|
||||
startup: ProcessStartup,
|
||||
) -> core::result::Result<ProcessHandle, crate::Error> {
|
||||
use std::process::Command;
|
||||
let server_env = format!("{}", xous_address());
|
||||
let pid_env = format!("{}", pid);
|
||||
let pid_env = format!("{}", startup.pid);
|
||||
let process_name_env = args.name.to_string();
|
||||
let process_key_env = hex::encode(&init.key.0);
|
||||
let (shell, args) = if cfg!(windows) {
|
||||
|
|
|
|||
|
|
@ -19,7 +19,7 @@ pub mod string;
|
|||
pub mod stringbuffer;
|
||||
pub mod syscall;
|
||||
|
||||
pub use arch::{ProcessArgs, ProcessInit, ProcessKey, ThreadInit};
|
||||
pub use arch::{ProcessArgs, ProcessInit, ProcessKey, ProcessStartup, ThreadInit};
|
||||
pub use definitions::*;
|
||||
pub use string::*;
|
||||
pub use stringbuffer::*;
|
||||
|
|
|
|||
|
|
@ -1659,8 +1659,8 @@ where
|
|||
{
|
||||
let process_init = crate::arch::create_process_pre_as_thread(&args)?;
|
||||
rsyscall(SysCall::CreateProcess(process_init)).and_then(|result| {
|
||||
if let Result::ProcessID(pid) = result {
|
||||
crate::arch::create_process_post_as_thread(args, process_init, pid)
|
||||
if let Result::NewProcess(startup) = result {
|
||||
crate::arch::create_process_post_as_thread(args, process_init, startup)
|
||||
} else {
|
||||
Err(Error::InternalError)
|
||||
}
|
||||
|
|
@ -1678,8 +1678,8 @@ pub fn create_process(
|
|||
) -> core::result::Result<crate::arch::ProcessHandle, Error> {
|
||||
let process_init = crate::arch::create_process_pre(&args)?;
|
||||
rsyscall(SysCall::CreateProcess(process_init)).and_then(|result| {
|
||||
if let Result::ProcessID(pid) = result {
|
||||
crate::arch::create_process_post(args, process_init, pid)
|
||||
if let Result::NewProcess(startup) = result {
|
||||
crate::arch::create_process_post(args, process_init, startup)
|
||||
} else {
|
||||
Err(Error::InternalError)
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue