From a6e1b269afc82de429ac17043e31babccb6cb94a Mon Sep 17 00:00:00 2001 From: R Aadarsh Date: Thu, 28 May 2026 12:51:05 +0530 Subject: [PATCH] * Make dup2 work * Use `CloseCloExec` for closing O_CLOEXEC files --- Cargo.lock | 8 ++++---- redox-rt/src/proc.rs | 2 +- src/platform/redox/mod.rs | 25 ++++++++++++++++--------- 3 files changed, 21 insertions(+), 14 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 02f8606189..abedbb6342 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -461,12 +461,12 @@ dependencies = [ [[package]] name = "redox_event" -version = "0.4.6" -source = "git+https://gitlab.redox-os.org/EuclidDivisionLemma/event?branch=spawn#17c4e4c5f0aaf83a2a8057b78ad75364e1f2242a" +version = "0.4.7" +source = "git+https://gitlab.redox-os.org/EuclidDivisionLemma/event?branch=spawn#48847ea51f9d06c8e2fc7ba3441343d12944e482" dependencies = [ "bitflags", "libredox", - "redox_syscall 0.8.0", + "redox_syscall 0.9.0", ] [[package]] @@ -481,7 +481,7 @@ dependencies = [ [[package]] name = "redox_syscall" version = "0.9.0" -source = "git+https://gitlab.redox-os.org/EuclidDivisionLemma/syscall/?branch=spawn#4a768587a071f8c87e915c6b0836d272bed1d56c" +source = "git+https://gitlab.redox-os.org/EuclidDivisionLemma/syscall/?branch=spawn#d28cf36f5a6684fcbf8be449af55e12d0024d503" dependencies = [ "bitflags", ] diff --git a/redox-rt/src/proc.rs b/redox-rt/src/proc.rs index 7ae7c7502a..f11cf5a4c1 100644 --- a/redox-rt/src/proc.rs +++ b/redox-rt/src/proc.rs @@ -464,7 +464,7 @@ pub fn fexec_impl( )); // Close all O_CLOEXEC file descriptors. TODO: close_range? - { + if extrainfo.same_process { // NOTE: This approach of implementing O_CLOEXEC will not work in multithreaded // scenarios. While execve() is undefined according to POSIX if there exist sibling // threads, it could still be allowed by keeping certain file descriptors and instead diff --git a/src/platform/redox/mod.rs b/src/platform/redox/mod.rs index 715e1df2f7..09b84dd611 100644 --- a/src/platform/redox/mod.rs +++ b/src/platform/redox/mod.rs @@ -1282,6 +1282,7 @@ impl Pal for Sys { 0, u64::try_from(fd).map_err(|_| Errno(EBADFD))?, )?; + Sys::close(src_fd as i32)?; } crate::header::spawn::Operation::Close(fd) => { new_file_table.call_wo( @@ -1293,18 +1294,24 @@ impl Pal for Sys { crate::header::spawn::Operation::Chdir(_) => todo!(), crate::header::spawn::Operation::FChdir(_) => todo!(), crate::header::spawn::Operation::Dup2(old, new) => { - // new_file_table.call_wo( - // [(old as usize).to_ne_bytes(), (new as usize).to_ne_bytes()] - // .into_iter() - // .flatten() - // .collect::>() - // .as_slice(), - // syscall::CallFlags::empty(), - // &[syscall::flag::FileTableVerb::Dup2 as u64], - // )?; + new_file_table.call_wo( + [(old as usize).to_ne_bytes(), (new as usize).to_ne_bytes()] + .into_iter() + .flatten() + .collect::>() + .as_slice(), + syscall::CallFlags::empty(), + &[syscall::flag::FileTableVerb::Dup2 as u64], + )?; } } } + + new_file_table.call_wo( + &[], + syscall::CallFlags::empty(), + &[syscall::flag::FileTableVerb::CloseCloExec as u64], + )?; } if let Some(attr) = fat {