From 20284eb2b276a8d5327bc4bcc46ab0064a896253 Mon Sep 17 00:00:00 2001
From: 4lDO2 <4lDO2@protonmail.com>
Date: Sun, 23 Jun 2024 11:15:16 +0200
Subject: [PATCH] Fix rlct_clone.

---
 redox-rt/src/arch/x86_64.rs |  2 +-
 redox-rt/src/thread.rs      | 36 ++++++------------------------------
 2 files changed, 7 insertions(+), 31 deletions(-)

diff --git a/redox-rt/src/arch/x86_64.rs b/redox-rt/src/arch/x86_64.rs
index 6c12a964..71ca1ce2 100644
--- a/redox-rt/src/arch/x86_64.rs
+++ b/redox-rt/src/arch/x86_64.rs
@@ -106,7 +106,7 @@ asmfunction!(__relibc_internal_fork_ret: ["
     pop rbp
     ret
 "] <= []);
-asmfunction!(__relibc_internal_rlct_clone_ret -> usize: ["
+asmfunction!(__relibc_internal_rlct_clone_ret: ["
     # Load registers
     pop rax
     pop rdi
diff --git a/redox-rt/src/thread.rs b/redox-rt/src/thread.rs
index 60201c38..9b348a62 100644
--- a/redox-rt/src/thread.rs
+++ b/redox-rt/src/thread.rs
@@ -19,13 +19,13 @@ pub unsafe fn rlct_clone_impl(stack: *mut usize) -> Result<usize> {
 
         let buf = create_set_addr_space_buf(
             *cur_addr_space_fd,
-            __relibc_internal_rlct_clone_ret() as usize,
+            __relibc_internal_rlct_clone_ret as usize,
             stack as usize,
         );
         let _ = syscall::write(*new_addr_space_sel_fd, &buf)?;
     }
 
-    // Inherit file table
+    // Inherit reference to file table
     {
         let cur_filetable_fd = FdGuard::new(syscall::dup(*cur_pid_fd, b"filetable")?);
         let new_filetable_sel_fd = FdGuard::new(syscall::dup(*new_pid_fd, b"current-filetable")?);
@@ -36,34 +36,10 @@ pub unsafe fn rlct_clone_impl(stack: *mut usize) -> Result<usize> {
         )?;
     }
 
-    // Inherit sigactions (on Linux, CLONE_THREAD requires CLONE_SIGHAND which implies the sigactions
-    // table is reused).
-    {
-        let cur_sigaction_fd = FdGuard::new(syscall::dup(*cur_pid_fd, b"sigactions")?);
-        let new_sigaction_sel_fd = FdGuard::new(syscall::dup(*new_pid_fd, b"current-sigactions")?);
-
-        let _ = syscall::write(
-            *new_sigaction_sel_fd,
-            &usize::to_ne_bytes(*cur_sigaction_fd),
-        )?;
-    }
-    // Inherit sighandler, but not the sigaltstack.
-    {
-        let new_sighandler_fd = FdGuard::new(syscall::dup(*new_pid_fd, b"sighandler")?);
-        let data = SetSighandlerData {
-            user_handler: sighandler_function(),
-            excp_handler: 0,
-            thread_control_addr: 0, // TODO
-            proc_control_addr: 0, // TODO
-        };
-        let _ = syscall::write(*new_sighandler_fd, &data)?;
-    }
-
-    // Sigprocmask starts as "block all", and is initialized when the thread has actually returned
-    // from clone_ret.
-
-    // TODO: Should some of these registers be inherited?
-    //copy_env_regs(*cur_pid_fd, *new_pid_fd)?;
+    // Since the signal handler is not yet initialized, signals specifically targeting the thread
+    // (relibc is only required to implement thread-specific signals that already originate from
+    // the same process) will be discarded. Process-specific signals will ignore this new thread,
+    // until it has initialized its own signal handler.
 
     // Unblock context.
     let start_fd = FdGuard::new(syscall::dup(*new_pid_fd, b"start")?);
-- 
GitLab