Implement pread and pwrite using the syscalls.

This commit is contained in:
4lDO2
2024-06-13 17:08:32 +02:00
parent ac08f016cd
commit 4c11b607de
12 changed files with 188 additions and 126 deletions
+27 -2
View File
@@ -12,7 +12,8 @@ use crate::{
header::{errno::*, pthread as header, sched::sched_param, sys_mman},
ld_so::{
linker::Linker,
tcb::{Master, Tcb}, ExpectTlsFree,
tcb::{Master, Tcb},
ExpectTlsFree,
},
platform::{types::*, Pal, Sys},
};
@@ -23,7 +24,9 @@ const MAIN_PTHREAD_ID: usize = 1;
/// Called only by the main thread, as part of relibc_start.
pub unsafe fn init() {
Tcb::current().expect_notls("no TCB present for main thread").pthread = Pthread {
Tcb::current()
.expect_notls("no TCB present for main thread")
.pthread = Pthread {
waitval: Waitval::new(),
has_enabled_cancelation: AtomicBool::new(false),
has_queued_cancelation: AtomicBool::new(false),
@@ -83,6 +86,28 @@ unsafe impl Sync for Pthread {}
// 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)
}
}
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);