Skip to content

Commit 9b20ec3

Browse files
committed
chore(safa-os): update safa-api
1 parent a6762d1 commit 9b20ec3

File tree

4 files changed

+32
-36
lines changed

4 files changed

+32
-36
lines changed

library/std/src/sys/pal/safaos/common.rs

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -28,10 +28,9 @@ pub fn decode_error_kind(code: i32) -> crate::io::ErrorKind {
2828
return crate::io::ErrorKind::Uncategorized;
2929
}
3030

31-
match SysResult::try_from(code as u16) {
32-
Ok(SysResult::Success) => unreachable!(),
33-
Ok(SysResult::Error(err)) => crate::os::safaos::into_io_error_kind(err),
34-
Err(_) => crate::io::ErrorKind::Uncategorized,
31+
match SysResult::from_isize(code as isize).into_result() {
32+
Ok(_) => unreachable!(),
33+
Err(err) => crate::os::safaos::into_io_error_kind(err),
3534
}
3635
}
3736

library/std/src/sys/pal/safaos/futex.rs

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -14,17 +14,22 @@ pub type SmallPrimitive = u32;
1414
pub fn futex_wait(futex: &Atomic<u32>, expected: u32, timeout: Option<Duration>) -> bool {
1515
// FIXME: Infinite timeout is just the max for now
1616
let timeout_duration = timeout.unwrap_or(Duration::MAX);
17-
let results = safa_api::syscalls::futex::futex_wait(futex, expected, timeout_duration)
18-
.expect("FATAL System error while waiting for Futex");
19-
results
17+
let results = safa_api::syscalls::futex::futex_wait(futex, expected, timeout_duration);
18+
let timedout = results == Err(safa_api::errors::ErrorStatus::Timeout);
19+
if let Err(err) = results {
20+
panic!("FATAL System error while waiting for Futex: {}", err.as_str());
21+
}
22+
!timedout
2023
}
2124

2225
#[inline]
2326
pub fn futex_wake(futex: &Atomic<u32>) -> bool {
24-
let results = safa_api::syscalls::futex::futex_wake(futex, 1)
25-
.expect("FATAL System error while waking 1 Futex")
26-
> 0;
27-
results
27+
let results = safa_api::syscalls::futex::futex_wake(futex, 1);
28+
let timedout = results == Err(safa_api::errors::ErrorStatus::Timeout);
29+
if let Err(err) = results {
30+
panic!("FATAL System error while waking Futex: {}", err.as_str());
31+
}
32+
!timedout
2833
}
2934

3035
#[inline]

library/std/src/sys/pal/safaos/resources.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ pub(crate) use path_to_str;
1616

1717
#[stable(feature = "rust1", since = "1.0.0")]
1818
/// Reprsents an ID over a resource
19-
pub type ResourceID = usize;
19+
pub type ResourceID = u32;
2020
const _: () = assert!(size_of::<ResourceID>() == size_of::<safa_api::syscalls::types::Ri>());
2121

2222
#[derive(Debug, PartialEq, Eq)]
@@ -121,19 +121,19 @@ impl FileDesc {
121121

122122
/// converts a raw resource id into a FileDesc
123123
/// this is unsafe because the resource id is not checked for validity
124-
pub unsafe fn from_raw(ri: usize) -> Self {
124+
pub unsafe fn from_raw(ri: ResourceID) -> Self {
125125
Self { fd: FileResource(ri), seek_at: UnsafeCell::new(0) }
126126
}
127127

128128
/// duplicates a raw resource id into a FileDesc
129129
/// this is unsafe because the resource id is not checked for validity
130130
/// the returned FileDesc is a duplicate of the original with a different resource id and therefore doesn't take ownership of the resource
131-
pub unsafe fn from_raw_dup(ri: usize) -> Self {
131+
pub unsafe fn from_raw_dup(ri: ResourceID) -> Self {
132132
let fd = unsafe { ManuallyDrop::new(Self::from_raw(ri)) };
133133
ManuallyDrop::into_inner(fd.clone())
134134
}
135135

136-
pub(crate) fn fd(&self) -> usize {
136+
pub(crate) fn fd(&self) -> ResourceID {
137137
self.fd.0
138138
}
139139

library/std/src/sys/process/safaos.rs

Lines changed: 13 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ use super::env::{CommandEnv, CommandEnvs};
22
pub use crate::ffi::OsString as EnvKey;
33
use crate::ffi::{OsStr, OsString};
44
use crate::num::NonZero;
5+
use crate::os::safaos::ResourceID;
56
use crate::os::safaos::api::errors::ErrorStatus;
67
use crate::os::safaos::api::syscalls;
78
use crate::path::Path;
@@ -51,7 +52,7 @@ pub enum Stdio {
5152

5253
impl Stdio {
5354
// `&self` because Self::InheritFile has to live as long as the results
54-
fn into_raw(&self) -> Option<usize> {
55+
fn into_raw(&self) -> Option<ResourceID> {
5556
match self {
5657
Stdio::Inherit => None,
5758
Stdio::InheritStdout => Some(sysget_stdout()),
@@ -292,14 +293,13 @@ impl fmt::Debug for Command {
292293

293294
#[derive(PartialEq, Eq, Clone, Copy, Debug, Default)]
294295
#[non_exhaustive]
295-
pub struct ExitStatus(u32);
296+
pub struct ExitStatus(isize);
296297

297298
impl ExitStatus {
298299
pub fn exit_ok(&self) -> Result<(), ExitStatusError> {
299-
match SysResult::try_from(self.0 as u16) {
300-
Ok(SysResult::Success) => Ok(()),
301-
Ok(SysResult::Error(e)) => Err(ExitStatusError::ErrorStatus(e)),
302-
Err(_) => Err(ExitStatusError::Unknown(self.0 as u32)),
300+
match SysResult::from_isize(self.0).into_result() {
301+
Ok(_) => Ok(()),
302+
Err(e) => Err(ExitStatusError(e)),
303303
}
304304
}
305305

@@ -311,24 +311,19 @@ impl ExitStatus {
311311
impl fmt::Display for ExitStatus {
312312
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
313313
match self.exit_ok() {
314-
Ok(()) => write!(f, "{}", "Success"),
314+
Ok(()) => write!(f, "Success"),
315315
Err(err) => write!(f, "{}", err),
316316
}
317317
}
318318
}
319319

320320
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
321-
pub enum ExitStatusError {
322-
ErrorStatus(ErrorStatus),
323-
Unknown(u32),
324-
}
321+
#[repr(transparent)]
322+
pub struct ExitStatusError(ErrorStatus);
325323

326324
impl core::fmt::Display for ExitStatusError {
327325
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
328-
match self {
329-
Self::ErrorStatus(err) => write!(f, "{}", err.as_str()),
330-
Self::Unknown(code) => write!(f, "<unknown exit status {}>", code),
331-
}
326+
write!(f, "{}", self.0.as_str())
332327
}
333328
}
334329

@@ -341,10 +336,7 @@ impl ExitStatusError {
341336

342337
impl Into<ExitStatus> for ExitStatusError {
343338
fn into(self) -> ExitStatus {
344-
match self {
345-
Self::ErrorStatus(err) => ExitStatus(err as u32),
346-
Self::Unknown(code) => ExitStatus(code),
347-
}
339+
ExitStatus(-(self.0 as isize))
348340
}
349341
}
350342

@@ -385,12 +377,12 @@ impl Process {
385377

386378
pub fn wait(&mut self) -> io::Result<ExitStatus> {
387379
let exit_code = syscalls::process::wait(self.0)?;
388-
Ok(ExitStatus(exit_code as u32))
380+
Ok(ExitStatus(exit_code as isize))
389381
}
390382

391383
pub fn try_wait(&mut self) -> io::Result<Option<ExitStatus>> {
392384
let exit_code = syscalls::process::try_cleanup(self.0)?;
393-
Ok(exit_code.map(|code| ExitStatus(code as u32)))
385+
Ok(exit_code.map(|code| ExitStatus(code as isize)))
394386
}
395387
}
396388

0 commit comments

Comments
 (0)