Move pthread::Errno to separate module.

This commit is contained in:
4lDO2
2024-09-07 12:46:16 +02:00
parent e73b891e77
commit 4bd0d2a1ef
21 changed files with 77 additions and 80 deletions
+1 -33
View File
@@ -10,6 +10,7 @@ use core::{
use alloc::{boxed::Box, collections::BTreeMap};
use crate::{
error::Errno,
header::{errno::*, pthread as header, sched::sched_param, sys_mman},
ld_so::{
linker::Linker,
@@ -82,39 +83,6 @@ pub struct OsTid {
unsafe impl Send for Pthread {}
unsafe impl Sync for Pthread {}
/// Positive error codes (EINVAL, not -EINVAL).
#[derive(Debug, Eq, PartialEq)]
// TODO: Move to a more generic place.
pub struct Errno(pub c_int);
#[cfg(target_os = "redox")]
impl From<syscall::Error> for Errno {
fn from(value: syscall::Error) -> Self {
Errno(value.errno)
}
}
#[cfg(target_os = "redox")]
impl From<Errno> for syscall::Error {
fn from(value: Errno) -> Self {
syscall::Error::new(value.0)
}
}
pub trait ResultExt<T> {
fn or_minus_one_errno(self) -> T;
}
impl<T: From<i8>> ResultExt<T> for Result<T, Errno> {
fn or_minus_one_errno(self) -> T {
match self {
Self::Ok(v) => v,
Self::Err(Errno(errno)) => unsafe {
crate::platform::ERRNO.set(errno);
T::from(-1)
},
}
}
}
#[derive(Clone, Copy, Debug)]
pub struct Retval(pub *mut c_void);