Fix thread+proc fd init in ld.so

This commit is contained in:
4lDO2
2025-03-31 15:17:11 +02:00
parent a4dc232a33
commit 59090a83f4
3 changed files with 31 additions and 9 deletions
+6 -3
View File
@@ -612,10 +612,13 @@ impl Linker {
unsafe {
if !dlopened {
#[cfg(target_os = "redox")]
let (tcb, old_tcb) = {
let (tcb, old_tcb, thr_fd) = {
use redox_rt::signal::tmp_disable_signals;
let old_tcb = Tcb::current().expect("failed to get bootstrap TCB");
let thr_fd = (&mut *old_tcb.os_specific.thr_fd.get())
.take()
.expect("no thread FD present");
let new_tcb = Tcb::new(self.tls_size)?; // This actually allocates TCB, TLS and ABI page.
// Stash
@@ -653,7 +656,7 @@ impl Linker {
new_tcb.generic.tcb_len = new_tcb_len;
drop(_guard);
(new_tcb, old_tcb as *mut Tcb as *mut c_void)
(new_tcb, old_tcb as *mut Tcb as *mut c_void, thr_fd)
};
#[cfg(not(target_os = "redox"))]
@@ -694,7 +697,7 @@ impl Linker {
tcb.copy_masters().map_err(|_| DlError::Malformed)?;
tcb.activate(
#[cfg(target_os = "redox")]
todo!(),
thr_fd,
);
#[cfg(target_os = "redox")]
+4
View File
@@ -196,6 +196,10 @@ pub unsafe fn init(
#[cfg(target_os = "redox")]
thr_fd,
);
} else {
// The thread fd must already be present in the already existing TCB. Don't close it.
#[cfg(target_os = "redox")]
core::mem::forget(thr_fd);
}
}
+21 -6
View File
@@ -145,16 +145,31 @@ fn resolve_path_name(
None
}
// TODO: Make unsafe
#[no_mangle]
pub extern "C" fn relibc_ld_so_start(sp: &'static mut Stack, ld_entry: usize) -> usize {
pub unsafe extern "C" fn relibc_ld_so_start(sp: &'static mut Stack, ld_entry: usize) -> usize {
// Setup TCB for ourselves.
unsafe {
let tcb = Tcb::new(0).expect_notls("ld.so: failed to allocate bootstrap TCB");
tcb.activate(todo!());
#[cfg(target_os = "redox")]
redox_rt::signal::setup_sighandler(&tcb.os_specific);
let thr_fd =
crate::platform::get_auxv_raw(sp.auxv().cast(), redox_rt::auxv_defs::AT_REDOX_THR_FD)
.expect_notls("no thread fd present");
let tcb = Tcb::new(0).expect_notls("ld.so: failed to allocate bootstrap TCB");
tcb.activate(
#[cfg(target_os = "redox")]
redox_rt::proc::FdGuard::new(thr_fd),
);
#[cfg(target_os = "redox")]
{
let proc_fd = crate::platform::get_auxv_raw(
sp.auxv().cast(),
redox_rt::auxv_defs::AT_REDOX_PROC_FD,
)
.expect_notls("no proc fd present");
redox_rt::initialize(redox_rt::proc::FdGuard::new(proc_fd));
redox_rt::signal::setup_sighandler(&tcb.os_specific);
}
}
// We get the arguments, the environment, and the auxilary vector