From 93e88b0ce8db2d818d4e4f218671b17beaa1f108 Mon Sep 17 00:00:00 2001 From: 4lDO2 <4lDO2@protonmail.com> Date: Thu, 3 Apr 2025 11:30:16 +0200 Subject: [PATCH] Reacquire thread fd as procmgr-owned in make_init. --- redox-rt/src/proc.rs | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/redox-rt/src/proc.rs b/redox-rt/src/proc.rs index 216f282e5b..a58c9bf064 100644 --- a/redox-rt/src/proc.rs +++ b/redox-rt/src/proc.rs @@ -918,7 +918,7 @@ pub fn copy_str(cur_pid_fd: usize, new_proc_fd: usize, key: &str) -> Result<()> Ok(()) } -pub unsafe fn make_init() -> &'static FdGuard { +pub unsafe fn make_init() -> [&'static FdGuard; 2] { let proc_fd = FdGuard::new( syscall::open("/scheme/proc/init", syscall::O_CLOEXEC).expect("failed to create init"), ); @@ -930,6 +930,12 @@ pub unsafe fn make_init() -> &'static FdGuard { ) .expect("failed to assign current thread to init process"); + let managed_thr_fd = FdGuard::new( + syscall::dup(*proc_fd, b"thread-0").expect("failed to get managed thread for init"), + ); + + let managed_thr_fd = (*RtTcb::current().thr_fd.get()).insert(managed_thr_fd); + STATIC_PROC_INFO.get().write(crate::StaticProcInfo { pid: 1, ppid: 1, @@ -944,5 +950,8 @@ pub unsafe fn make_init() -> &'static FdGuard { egid: 0, sgid: 0, }; - (*STATIC_PROC_INFO.get()).proc_fd.as_ref().unwrap() + [ + (*STATIC_PROC_INFO.get()).proc_fd.as_ref().unwrap(), + managed_thr_fd, + ] }