From ab0da30613f23214de34222d23134310db9e60f9 Mon Sep 17 00:00:00 2001 From: Red Bear OS Date: Sun, 12 Jul 2026 08:15:00 +0300 Subject: [PATCH] fix: register external fds with userspace FILETABLE Socket and RawEventQueue create fds via libredox raw syscalls that bypass the redox-rt userspace FILETABLE. FdGuard::dup then reserves these positions, causing SYS_DUP_INTO to destroy the existing fds. --- bootstrap/src/exec.rs | 11 ++++++++--- bootstrap/src/initfs.rs | 2 +- bootstrap/src/procmgr.rs | 5 +++++ 3 files changed, 14 insertions(+), 4 deletions(-) diff --git a/bootstrap/src/exec.rs b/bootstrap/src/exec.rs index 610a3442d1..2f89895fed 100644 --- a/bootstrap/src/exec.rs +++ b/bootstrap/src/exec.rs @@ -253,9 +253,14 @@ pub fn main() -> ! { &extrainfo, None, ) - .ok() - .flatten() - .expect("failed to execute init"); + .unwrap_or_else(|e| { + let step = unsafe { redox_rt::proc::FEXEC_STEP }; + panic!("fexec_impl error: {:?} at step {}", e, step); + }) + .unwrap_or_else(|| panic!("fexec_impl returned None (no interpreter)")) + else { + panic!("fexec_impl returned unexpected variant"); + }; // According to elf(5), PT_INTERP requires that the interpreter path be // null-terminated. Violating this should therefore give the "format error" ENOEXEC. diff --git a/bootstrap/src/initfs.rs b/bootstrap/src/initfs.rs index d689a13d04..b5de114c0c 100644 --- a/bootstrap/src/initfs.rs +++ b/bootstrap/src/initfs.rs @@ -123,7 +123,7 @@ impl SchemeSync for InitFsScheme { ) -> Result { if !matches!( self.handles.get(&dirfd).ok_or(Error::new(EBADF))?, - Handle::SchemeRoot + Handle::SchemeRoot | Handle::Node(_) ) { return Err(Error::new(EACCES)); } diff --git a/bootstrap/src/procmgr.rs b/bootstrap/src/procmgr.rs index 93acd72cd7..acff0940f0 100644 --- a/bootstrap/src/procmgr.rs +++ b/bootstrap/src/procmgr.rs @@ -49,7 +49,12 @@ pub fn run(write_fd: FdGuard, socket: Socket, auth: FdGuard, event: FdGuard) -> // TODO? let socket_ident = socket.inner().raw(); + redox_rt::proc::register_external_fd(socket.inner().raw()) + .expect("failed to register socket fd with userspace filetable"); + let queue = RawEventQueue::new(event.as_raw_fd()).expect("failed to create event queue"); + redox_rt::proc::register_external_fd(queue.0.as_raw_fd()) + .expect("failed to register event queue fd with userspace filetable"); drop(event); queue