From d45adade1d4606bfa76d2bcd9ed7597c65c3036c Mon Sep 17 00:00:00 2001
From: 4lDO2 <4lDO2@protonmail.com>
Date: Fri, 21 Jun 2024 13:26:26 +0200
Subject: [PATCH] Remove obsolete proc usage, now reaches init.

---
 redox-rt/src/proc.rs   | 31 +------------------------------
 redox-rt/src/signal.rs | 17 ++++++++++-------
 2 files changed, 11 insertions(+), 37 deletions(-)

diff --git a/redox-rt/src/proc.rs b/redox-rt/src/proc.rs
index 608aaa68..9b7dbfc3 100644
--- a/redox-rt/src/proc.rs
+++ b/redox-rt/src/proc.rs
@@ -425,18 +425,6 @@ where
         deactivate_tcb(*open_via_dup)?;
     }
 
-    {
-        let current_sigaction_fd = FdGuard::new(syscall::dup(*open_via_dup, b"sigactions")?);
-        let empty_sigaction_fd = FdGuard::new(syscall::dup(*current_sigaction_fd, b"empty")?);
-        let sigaction_selection_fd =
-            FdGuard::new(syscall::dup(*open_via_dup, b"current-sigactions")?);
-
-        let _ = syscall::write(
-            *sigaction_selection_fd,
-            &usize::to_ne_bytes(*empty_sigaction_fd),
-        )?;
-    }
-
     // TODO: Restore old name if exec failed?
     if let Ok(name_fd) = syscall::dup(*open_via_dup, b"name").map(FdGuard::new) {
         let _ = syscall::write(*name_fd, interp_override.as_ref().map_or(path, |o| &o.name));
@@ -727,27 +715,10 @@ pub fn fork_inner(initial_rsp: *mut usize) -> Result<usize> {
 
         // Reuse the same sigaltstack and signal entry (all memory will be re-mapped CoW later).
         {
-            let cur_sighandler_fd = FdGuard::new(syscall::dup(*cur_pid_fd, b"sighandler")?);
             let new_sighandler_fd = FdGuard::new(syscall::dup(*new_pid_fd, b"sighandler")?);
-
-            let mut sighandler_buf = SetSighandlerData::default();
-
-            let _ = syscall::read(*cur_sighandler_fd, &mut sighandler_buf)?;
-            let _ = syscall::write(*new_sighandler_fd, &sighandler_buf)?;
+            let _ = syscall::write(*new_sighandler_fd, &crate::signal::current_setsighandler_struct())?;
         }
 
-        // Reuse the same sigactions (by value).
-        {
-            let cur_sigaction_fd = FdGuard::new(syscall::dup(*cur_pid_fd, b"sigactions")?);
-            let new_sigaction_fd = FdGuard::new(syscall::dup(*cur_sigaction_fd, b"copy")?);
-            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(*new_sigaction_fd),
-            )?;
-        }
         copy_str(*cur_pid_fd, *new_pid_fd, "name")?;
 
         // Copy existing files into new file table, but do not reuse the same file table (i.e. new
diff --git a/redox-rt/src/signal.rs b/redox-rt/src/signal.rs
index f1dbf58b..24ff85f5 100644
--- a/redox-rt/src/signal.rs
+++ b/redox-rt/src/signal.rs
@@ -2,7 +2,7 @@ use core::cell::Cell;
 use core::ffi::c_int;
 use core::sync::atomic::{AtomicU64, Ordering};
 
-use syscall::{Error, IntRegisters, Result, SigProcControl, Sigcontrol, EINVAL, SIGCHLD, SIGCONT, SIGKILL, SIGSTOP, SIGTSTP, SIGTTIN, SIGTTOU, SIGURG, SIGW0_TSTP_IS_STOP_BIT, SIGW0_TTIN_IS_STOP_BIT, SIGW0_TTOU_IS_STOP_BIT, SIGWINCH};
+use syscall::{Error, IntRegisters, Result, SetSighandlerData, SigProcControl, Sigcontrol, EINVAL, SIGCHLD, SIGCONT, SIGKILL, SIGSTOP, SIGTSTP, SIGTTIN, SIGTTOU, SIGURG, SIGW0_TSTP_IS_STOP_BIT, SIGW0_TTIN_IS_STOP_BIT, SIGW0_TTOU_IS_STOP_BIT, SIGWINCH};
 
 use crate::{arch::*, Tcb};
 use crate::sync::Mutex;
@@ -260,12 +260,7 @@ pub fn setup_sighandler(control: &Sigcontrol) {
         CPUID_EAX1_ECX.store(cpuid_eax1_ecx, core::sync::atomic::Ordering::Relaxed);
     }
 
-    let data = syscall::SetSighandlerData {
-        user_handler: sighandler_function(),
-        excp_handler: 0, // TODO
-        thread_control_addr: control as *const Sigcontrol as usize,
-        proc_control_addr: &PROC_CONTROL_STRUCT as *const SigProcControl as usize,
-    };
+    let data = current_setsighandler_struct();
 
     let fd = syscall::open(
         "thisproc:current/sighandler",
@@ -280,3 +275,11 @@ pub struct RtSigarea {
     pub control: Sigcontrol,
     pub arch: crate::arch::SigArea,
 }
+pub fn current_setsighandler_struct() -> SetSighandlerData {
+    SetSighandlerData {
+        user_handler: sighandler_function(),
+        excp_handler: 0, // TODO
+        thread_control_addr: core::ptr::addr_of!(unsafe { Tcb::current() }.unwrap().os_specific.control) as usize,
+        proc_control_addr: &PROC_CONTROL_STRUCT as *const SigProcControl as usize,
+    }
+}
-- 
GitLab