Fix ld.so access function on Redox.

This commit is contained in:
4lDO2
2022-08-12 14:55:05 +02:00
parent 36775eeb1b
commit 5e74d173ab
4 changed files with 34 additions and 3 deletions
+2 -1
View File
@@ -29,7 +29,7 @@ unsafe fn access(path: *const c_char, mode: c_int) -> c_int {
Ok(ok) => ok,
Err(_) => return -1,
};
let fd = match syscall::open(path, syscall::O_CLOEXEC) {
let fd = match crate::platform::sys::path::open(path, syscall::O_CLOEXEC) {
Ok(fd) => fd,
_ => return -1,
};
@@ -40,6 +40,7 @@ unsafe fn access(path: *const c_char, mode: c_int) -> c_int {
if syscall::fstat(fd, &mut stat).is_err() {
return -1;
}
let _ = syscall::close(fd);
let uid = match syscall::getuid() {
Ok(uid) => uid,
Err(_) => return -1,
+3
View File
@@ -181,6 +181,9 @@ pub extern "C" fn relibc_ld_so_start(sp: &'static mut Stack, ld_entry: usize) ->
_r_debug.r_ldbase = ld_entry;
}
// TODO: Fix memory leak, although minimal.
crate::platform::init(auxv.clone());
// Some variables that will be overridden by environment and auxiliary vectors
let ld_library_path = envs.get("LD_LIBRARY_PATH").map(|s| s.to_owned());
+2 -2
View File
@@ -21,11 +21,11 @@ pub use self::sys::{e, Sys};
#[cfg(all(not(feature = "no_std"), target_os = "linux"))]
#[path = "linux/mod.rs"]
mod sys;
pub(crate) mod sys;
#[cfg(all(not(feature = "no_std"), target_os = "redox"))]
#[path = "redox/mod.rs"]
mod sys;
pub(crate) mod sys;
#[cfg(test)]
mod test;
+27
View File
@@ -0,0 +1,27 @@
use super::{AtomicLock, AttemptStatus};
const WAITING_BIT: u32 = 1 << 31;
const UNLOCKED: u32 = 0;
// We now have 2^32 - 1 possible thread ID values
pub struct ReentrantMutex<T> {
lock: AtomicLock,
content: UnsafeCell<T>,
}
unsafe impl<T: Send> Send for ReentrantMutex {}
unsafe impl<T: Send> Sync for ReentrantMutex {}
impl<T> ReentrantMutex<T> {
pub const fn new(context: T) -> Self {
Self {
lock: AtomicLock::new(UNLOCKED),
content: UnsafeCell::new(content),
}
}
}
pub struct ReentrantMutexGuard<'a, T: 'a> {
mutex: &'a ReentrantMutex<T>,
content: &'a T,
}
impl<'a, T> Deref for MutexGuard {
}