The previous backport rewrote the whole dup2 (duplicate-first, remove/insert)
which perturbed ordinary dup2 used by process-spawn stdio setup and could
break exec (ENOENT). Restrict the new behavior to the self-dup-with-buffer
case (dup2(ft, ft, 'refresh')); the normal fd!=new_fd path is byte-for-byte
the original.
Backport of upstream kernel 37ffa2e2. The proc scheme's filetable dup2
only accepted 'copy'; a 'refresh' buffer now re-materializes the
filetable's descriptor list in place. dup2() no longer short-circuits a
self-dup (fd==new_fd) when a buffer is supplied, and duplicates before
replacing the target descriptor. Together with relibc's
FdTbl::from_binary_fd issuing dup2(ft, ft, 'refresh'), an exec'd process
(e.g. a login shell) rebuilds its fd table from the CURRENT parent state
instead of a stale snapshot -- fixing interactive shells whose pty-slave
stdin returned nothing while writes to fd 1/2 worked. fs.rs dup2 adapted
to the local duplicate_file(cloexec) signature.
The debug scheme's fevent always returned empty, relying solely on the
edge-triggered debug_notify(). A reader that registers with an event queue after
input has already arrived (fbcond's serial console) would miss it. Report
readable when the input queue is non-empty.
The event scheme (scheme:event, Redox's epoll backend) implemented
open/read/write/fpath/fevent but NOT dup, so dup() of an event-queue fd
fell through to the default kdup and returned EINVAL. tokio/mio's I/O
reactor construction does exactly this: Poll::new() opens the queue, then
registry.try_clone() dups it (registrations go through the clone, polling
through the original). The EINVAL made every tokio Runtime::build() with an
I/O driver fail — killing all zbus daemons (sessiond/polkit/udisks/upower)
and the brush login shell ("failed to create tokio runtime: Invalid
argument"), which is why text login never worked.
Implement kdup: duping an event-queue fd returns a second handle to the
SAME queue (shared registrations + delivered events, as epoll requires),
reference-counted on EventQueue so the queue survives until the last fd
closes. eventfd counters are not dup-able (unused: mio's Redox waker uses a
pipe). Verified: cargo check --target x86_64-unknown-kernel passes.
The MSR R/W scheme lets root request an arbitrary wrmsr/rdmsr on any CPU
(used by cpufreqd/thermald). A bad MSR number or reserved-bit value raises
#GP; on the raw wrmsr/rdmsr that is a kernel-mode fault that panics the
whole machine at exit_this_context (unreachable!) — i.e. root userspace can
crash the kernel. Observed on KVM: cpufreqd writing a legacy P-state MSR
(#GP in the msr IPI handler) halted the boot right before the console/login.
Add wrmsr_safe/rdmsr_safe (arch/x86_64): the faulting instruction sits in a
__wrmsr_safe_start/end (resp. rdmsr) region, and the #GP handler recognises a
fault inside those bounds and returns an error via recover_and_efault — the
same fault-recovery mechanism already used for usercopy page faults. The MSR
scheme (local path) and the cross-CPU msr IPI handler now use these and
surface EIO to the caller (IPI failures propagated via a new MsrMailbox
faulted flag) instead of panicking. 32-bit x86 keeps the raw path (untested).
Two fixes on the clean base (all boot-investigation diagnostics removed):
1. ProcScheme::kcall now accepts FileTableVerb::Resize on filetable
handles as a no-op instead of returning EBADF. After the upstream
'move fd allocation into userspace' relibc refactor, FILETABLE
pre-syncs its size via a Resize call before growing; the kernel
already grows posix_fdtbl on insert. Returning EBADF broke add_posix
once a process's fd table grew (notably the bootstrap process manager
proxying child thread ops), making the child's regs/env dup fail and
its ld.so panic, crashing initfs daemons (randd) at boot.
2. ProcUptime uses integer arithmetic instead of f64 (the kernel is
built with +soft-float; f64 in format!() breaks the build).
* Remove lots of unsafe code by initialising in the closure passed to
`call_once`
* Remove `NUMBER_OF_DOMAINS` as size can always be inferred from the
hashmap's len
* `syscall::sendfd`, now, when called with a `ContextHandle::FileTable` adds the fd to the filetable removing it from the calling process's filetable
* Files can now be added to, removed from another process, and can be duplicated using `ProcScheme::kcall`
* Files of another process with the flag O_CLOEXEC can now be closed by using `kcall`