Compare commits

..

No commits in common. "c36b14314fc6ad0d121f17bce1a4bf7c8780f064" and "7a029c4a0a45bfe30714499c94e0089b0bbf360f" have entirely different histories.

3 changed files with 43 additions and 43 deletions

View File

@ -254,7 +254,7 @@ pub fn home_dir() -> Option<PathBuf> {
pub fn exit(code: i32) -> ! { pub fn exit(code: i32) -> ! {
if let Some(proc_man_pid) = syscalls::try_get_registered(3) { if let Some(proc_man_pid) = syscalls::try_get_registered(3) {
rpc::send_call(proc_man_pid, 8, 4, &postcard::to_allocvec(&(code as u8)).unwrap()) rpc::send_call(proc_man_pid, 2, 4, &postcard::to_allocvec(&(code as u8)).unwrap())
.get_return(); .get_return();
}; };
unsafe { unsafe {

View File

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

View File

@ -12,7 +12,7 @@ pub extern "C" fn _start() {
let argv; let argv;
unsafe { unsafe {
asm!("int 0x80", in("rax") 19, lateout("rax") argv, lateout("rcx") argc); asm!("int 0x80", in("rax") 19, lateout("rax") argv, lateout("rcx") argc);
let code = main(argc, argv); main(argc, argv);
crate::sys::os::exit(code as u8); asm!("int 0x80", in("rax") 1);
}; };
} }