Reach init fork

This commit is contained in:
4lDO2
2024-12-27 16:32:19 +01:00
parent 26399569de
commit ad5efd0f11
11 changed files with 111 additions and 60 deletions
+4 -1
View File
@@ -692,7 +692,10 @@ impl Linker {
tcb.append_masters(tcb_masters);
// Copy the master data into the static TLS block.
tcb.copy_masters().map_err(|_| DlError::Malformed)?;
tcb.activate();
tcb.activate(
#[cfg(target_os = "redox")]
todo!(),
);
#[cfg(target_os = "redox")]
{
+21 -14
View File
@@ -41,7 +41,10 @@ static mut STATIC_TCB_MASTER: Master = Master {
};
#[inline(never)]
pub fn static_init(sp: &'static Stack) {
pub fn static_init(
sp: &'static Stack,
#[cfg(target_os = "redox")] thr_fd: redox_rt::proc::FdGuard,
) {
const SIZEOF_PHDR64: usize = mem::size_of::<ProgramHeader64<Endianness>>();
const SIZEOF_PHDR32: usize = mem::size_of::<ProgramHeader32<Endianness>>();
@@ -120,7 +123,10 @@ pub fn static_init(sp: &'static Stack) {
tcb.masters_len = mem::size_of::<Master>();
tcb.copy_masters()
.expect_notls("failed to copy TLS master data");
tcb.activate();
tcb.activate(
#[cfg(target_os = "redox")]
thr_fd,
);
}
//TODO: Warning on multiple TLS sections?
@@ -130,7 +136,10 @@ pub fn static_init(sp: &'static Stack) {
}
#[cfg(any(target_os = "linux", target_os = "redox"))]
pub unsafe fn init(sp: &'static Stack) {
pub unsafe fn init(
sp: &'static Stack,
#[cfg(target_os = "redox")] thr_fd: redox_rt::proc::FdGuard,
) {
let tp: usize;
#[cfg(target_os = "linux")]
@@ -151,11 +160,8 @@ pub unsafe fn init(sp: &'static Stack) {
{
let mut env = syscall::EnvRegisters::default();
let file = syscall::open(
"/scheme/thisproc/current/regs/env",
syscall::O_CLOEXEC | syscall::O_RDONLY,
)
.expect_notls("failed to open handle for process registers");
let file = syscall::dup(*thr_fd, b"regs/env")
.expect_notls("failed to open handle for process registers");
let _ = syscall::read(file, &mut env).expect_notls("failed to read gsbase");
@@ -167,11 +173,8 @@ pub unsafe fn init(sp: &'static Stack) {
{
let mut env = syscall::EnvRegisters::default();
let file = syscall::open(
"/scheme/thisproc/current/regs/env",
syscall::O_CLOEXEC | syscall::O_RDONLY,
)
.expect_notls("failed to open handle for process registers");
let file = syscall::dup(*thr_fd, b"regs/env")
.expect_notls("failed to open handle for process registers");
let _ = syscall::read(file, &mut env).expect_notls("failed to read fsbase");
@@ -188,7 +191,11 @@ pub unsafe fn init(sp: &'static Stack) {
}
if tp == 0 {
static_init(sp);
static_init(
sp,
#[cfg(target_os = "redox")]
thr_fd,
);
}
}
+15 -3
View File
@@ -202,8 +202,14 @@ impl Tcb {
}
/// Activate TLS
pub unsafe fn activate(&mut self) {
Self::os_arch_activate(&self.os_specific, self.tls_end as usize, self.tls_len);
pub unsafe fn activate(&mut self, #[cfg(target_os = "redox")] thr_fd: redox_rt::proc::FdGuard) {
Self::os_arch_activate(
&self.os_specific,
self.tls_end as usize,
self.tls_len,
#[cfg(target_os = "redox")]
thr_fd,
);
}
pub fn setup_dtv(&mut self, n: usize) {
@@ -327,7 +333,13 @@ impl Tcb {
}
#[cfg(target_os = "redox")]
unsafe fn os_arch_activate(os: &OsSpecific, tls_end: usize, tls_len: usize) {
unsafe fn os_arch_activate(
os: &OsSpecific,
tls_end: usize,
tls_len: usize,
thr_fd: redox_rt::proc::FdGuard,
) {
os.thr_fd.get().write(Some(thr_fd));
redox_rt::tcb_activate(os, tls_end, tls_len)
}
}