bootstrap: fix FD allocation to match upstream userspace fd model
The bootstrap's start.rs used libredox::call::openat which resolved to the bootstrap's own redox_openat_v1 in initfs.rs, calling syscall::openat (SYS_OPENAT). This let the kernel allocate POSIX FDs 0,1,2 for stdin/stdout/stderr, but the userspace FILETABLE was never updated. Later, exec.rs called auth.dup(b'cur-context') via redox_rt::sys::dup, which asked the empty FILETABLE for a free slot (returning 0), then passed it to SYS_DUP_INTO. The kernel rejected it with EEXIST because posix_fdtbl[0] was already occupied by stdin. Fix: use syscall::openat_into to directly specify FD slots 0,1,2 in start.rs, and use syscall::dup_into with a computed FD index for cur-context in exec.rs. Both bypass the FILETABLE, which is only populated later by redox_rt::initialize_freestanding.
This commit is contained in:
@@ -53,6 +53,8 @@ pub fn main() -> ! {
|
||||
FdGuard::new(*(base_ptr as *const usize))
|
||||
};
|
||||
|
||||
let cur_context_idx = scheme_creation_cap.as_raw_fd() + 1;
|
||||
|
||||
let mut kernel_schemes = KernelSchemeMap::new(kernel_scheme_infos);
|
||||
|
||||
let auth = kernel_schemes
|
||||
@@ -60,8 +62,8 @@ pub fn main() -> ! {
|
||||
.remove(&GlobalSchemes::Proc)
|
||||
.expect("failed to get proc fd");
|
||||
|
||||
let this_thr_fd = auth
|
||||
.dup(b"cur-context")
|
||||
let this_thr_fd = syscall::dup_into(auth.as_raw_fd(), cur_context_idx, b"cur-context")
|
||||
.map(FdGuard::new)
|
||||
.expect("failed to open open_via_dup")
|
||||
.to_upper()
|
||||
.unwrap();
|
||||
|
||||
Reference in New Issue
Block a user