|
|
|
@ -107,23 +107,20 @@ pub fn spawn(
|
|
|
|
|
_needs_stdin: bool,
|
|
|
|
|
) -> io::Result<(Process, StdioPipes)> {
|
|
|
|
|
let stdin = match self.stdin.take() {
|
|
|
|
|
None => None,
|
|
|
|
|
Some(Stdio::Null) => None,
|
|
|
|
|
Some(Stdio::Inherit) => *STDIN_FD.get().unwrap(),
|
|
|
|
|
None | Some(Stdio::Inherit) => *STDIN_FD.get().unwrap(),
|
|
|
|
|
Some(Stdio::MakePipe) => todo!(),
|
|
|
|
|
Some(Stdio::InheritFile(file)) => Some((file.fs_pid, file.fd)),
|
|
|
|
|
};
|
|
|
|
|
let stdout = match self.stdout.take() {
|
|
|
|
|
None => None,
|
|
|
|
|
Some(Stdio::Null) => None,
|
|
|
|
|
Some(Stdio::Inherit) => *STDOUT_FD.get().unwrap(),
|
|
|
|
|
None | Some(Stdio::Inherit) => *STDOUT_FD.get().unwrap(),
|
|
|
|
|
Some(Stdio::MakePipe) => todo!(),
|
|
|
|
|
Some(Stdio::InheritFile(file)) => Some((file.fs_pid, file.fd)),
|
|
|
|
|
};
|
|
|
|
|
let stderr = match self.stderr.take() {
|
|
|
|
|
None => None,
|
|
|
|
|
Some(Stdio::Null) => None,
|
|
|
|
|
Some(Stdio::Inherit) => *STDERR_FD.get().unwrap(),
|
|
|
|
|
None | Some(Stdio::Inherit) => *STDERR_FD.get().unwrap(),
|
|
|
|
|
Some(Stdio::MakePipe) => todo!(),
|
|
|
|
|
Some(Stdio::InheritFile(file)) => Some((file.fs_pid, file.fd)),
|
|
|
|
|
};
|
|
|
|
@ -147,7 +144,7 @@ pub fn spawn(
|
|
|
|
|
res?;
|
|
|
|
|
};
|
|
|
|
|
syscalls::wake_new(pid).unwrap();
|
|
|
|
|
Ok((Process { dummy: () }, StdioPipes { stdin: None, stdout: None, stderr: None }))
|
|
|
|
|
Ok((Process { pid }, StdioPipes { stdin: None, stdout: None, stderr: None }))
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
pub fn output(&mut self) -> io::Result<(ExitStatus, Vec<u8>, Vec<u8>)> {
|
|
|
|
@ -245,15 +242,19 @@ fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
|
|
|
|
|
|
|
|
|
|
#[derive(PartialEq, Eq, Clone, Copy, Debug, Default)]
|
|
|
|
|
#[non_exhaustive]
|
|
|
|
|
pub struct ExitStatus();
|
|
|
|
|
pub struct ExitStatus(u8);
|
|
|
|
|
|
|
|
|
|
impl ExitStatus {
|
|
|
|
|
pub fn exit_ok(&self) -> Result<(), ExitStatusError> {
|
|
|
|
|
Ok(())
|
|
|
|
|
if self.0 == 0 {
|
|
|
|
|
Ok(())
|
|
|
|
|
} else {
|
|
|
|
|
Err(ExitStatusError(self.0))
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
pub fn code(&self) -> Option<i32> {
|
|
|
|
|
Some(0)
|
|
|
|
|
Some(self.0 as i32)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
@ -263,39 +264,18 @@ fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
pub struct ExitStatusError(!);
|
|
|
|
|
|
|
|
|
|
impl Clone for ExitStatusError {
|
|
|
|
|
fn clone(&self) -> ExitStatusError {
|
|
|
|
|
self.0
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
impl Copy for ExitStatusError {}
|
|
|
|
|
|
|
|
|
|
impl PartialEq for ExitStatusError {
|
|
|
|
|
fn eq(&self, _other: &ExitStatusError) -> bool {
|
|
|
|
|
self.0
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
impl Eq for ExitStatusError {}
|
|
|
|
|
|
|
|
|
|
impl fmt::Debug for ExitStatusError {
|
|
|
|
|
fn fmt(&self, _f: &mut fmt::Formatter<'_>) -> fmt::Result {
|
|
|
|
|
self.0
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
#[derive(Clone, Copy, PartialEq, Eq, Debug)]
|
|
|
|
|
pub struct ExitStatusError(u8);
|
|
|
|
|
|
|
|
|
|
impl Into<ExitStatus> for ExitStatusError {
|
|
|
|
|
fn into(self) -> ExitStatus {
|
|
|
|
|
self.0
|
|
|
|
|
ExitStatus(self.0)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
impl ExitStatusError {
|
|
|
|
|
pub fn code(self) -> Option<NonZero<i32>> {
|
|
|
|
|
self.0
|
|
|
|
|
Some(NonZero::new(self.0 as i32).unwrap())
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
@ -321,24 +301,44 @@ fn from(code: u8) -> Self {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
pub struct Process {
|
|
|
|
|
dummy: (),
|
|
|
|
|
pid: u64,
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
impl Process {
|
|
|
|
|
pub fn id(&self) -> u32 {
|
|
|
|
|
todo!()
|
|
|
|
|
self.pid.try_into().unwrap()
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
pub fn kill(&mut self) -> io::Result<()> {
|
|
|
|
|
todo!()
|
|
|
|
|
unsupported()
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
pub fn wait(&mut self) -> io::Result<ExitStatus> {
|
|
|
|
|
todo!()
|
|
|
|
|
let Some(proc_man_pid) = syscalls::try_get_registered(3) else {
|
|
|
|
|
return unsupported();
|
|
|
|
|
};
|
|
|
|
|
let wait_res: Result<(u64, u8), Errno> = postcard::from_bytes(
|
|
|
|
|
&rpc::send_call(proc_man_pid, 8, 5, &postcard::to_allocvec(&(self.pid, true)).unwrap()).get_return(),
|
|
|
|
|
)
|
|
|
|
|
.unwrap();
|
|
|
|
|
let (_wait_pid, code) = wait_res?;
|
|
|
|
|
Ok(ExitStatus(code))
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
pub fn try_wait(&mut self) -> io::Result<Option<ExitStatus>> {
|
|
|
|
|
todo!()
|
|
|
|
|
let Some(proc_man_pid) = syscalls::try_get_registered(3) else {
|
|
|
|
|
return unsupported();
|
|
|
|
|
};
|
|
|
|
|
let wait_res: Result<(u64, u8), Errno> = postcard::from_bytes(
|
|
|
|
|
&rpc::send_call(proc_man_pid, 8, 5, &postcard::to_allocvec(&(self.pid, true)).unwrap()).get_return(),
|
|
|
|
|
)
|
|
|
|
|
.unwrap();
|
|
|
|
|
let (_wait_pid, code) = match wait_res {
|
|
|
|
|
Ok(val) => val,
|
|
|
|
|
Err(Errno::EAGAIN) => return Ok(None),
|
|
|
|
|
Err(e) => return Err(e.into()),
|
|
|
|
|
};
|
|
|
|
|
Ok(Some(ExitStatus(code)))
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|