From b71c34dd2df652edaeca5ee9bd8022b04ea6d6d1 Mon Sep 17 00:00:00 2001 From: 4lDO2 <4lDO2@protonmail.com> Date: Sat, 20 Jul 2024 14:42:51 +0200 Subject: [PATCH] Fix i686 fork. --- redox-rt/src/arch/i686.rs | 7 ++++++- redox-rt/src/arch/x86_64.rs | 2 +- redox-rt/src/signal.rs | 2 +- 3 files changed, 8 insertions(+), 3 deletions(-) diff --git a/redox-rt/src/arch/i686.rs b/redox-rt/src/arch/i686.rs index 681f1a9e..be0d9240 100644 --- a/redox-rt/src/arch/i686.rs +++ b/redox-rt/src/arch/i686.rs @@ -5,6 +5,7 @@ use syscall::*; use crate::{ proc::{fork_inner, FdGuard}, signal::{inner_fastcall, RtSigarea, SigStack, PROC_CONTROL_STRUCT}, + RtTcb, }; // Setup a stack starting from the very end of the address space, and then growing downwards. @@ -80,7 +81,11 @@ unsafe extern "cdecl" fn fork_impl(initial_rsp: *mut usize) -> usize { unsafe extern "cdecl" fn child_hook(cur_filetable_fd: usize, new_pid_fd: usize) { let _ = syscall::close(cur_filetable_fd); - let _ = syscall::close(new_pid_fd); + // TODO: Currently pidfd == threadfd, but this will not be the case later. + RtTcb::current() + .thr_fd + .get() + .write(Some(FdGuard::new(new_pid_fd))); } asmfunction!(__relibc_internal_fork_wrapper -> usize: [" diff --git a/redox-rt/src/arch/x86_64.rs b/redox-rt/src/arch/x86_64.rs index 07af5254..d0d0f9bf 100644 --- a/redox-rt/src/arch/x86_64.rs +++ b/redox-rt/src/arch/x86_64.rs @@ -91,7 +91,7 @@ unsafe extern "sysv64" fn fork_impl(initial_rsp: *mut usize) -> usize { unsafe extern "sysv64" fn child_hook(cur_filetable_fd: usize, new_pid_fd: usize) { let _ = syscall::close(cur_filetable_fd); - // TODO: Currently equivalent, but this will not be the case later. + // TODO: Currently pidfd == threadfd, but this will not be the case later. RtTcb::current() .thr_fd .get() diff --git a/redox-rt/src/signal.rs b/redox-rt/src/signal.rs index dcc0592a..00bd3474 100644 --- a/redox-rt/src/signal.rs +++ b/redox-rt/src/signal.rs @@ -481,7 +481,7 @@ pub fn setup_sighandler(tcb: &RtTcb) { arch.altstack_top = usize::MAX; arch.altstack_bottom = 0; // TODO - #[cfg(any(target_arch = "i686", target_arch = "aarch64"))] + #[cfg(any(target_arch = "x86", target_arch = "aarch64"))] { arch.pctl = core::ptr::addr_of!(PROC_CONTROL_STRUCT) as usize; } -- GitLab