Track the implicit state machines in `src/` and the defects they hide
Maintainers usually reply within 2 days
Nobody has claimed this yet.
Assessment
- Difficulty
- 5/5
- Estimated time
- Over a week
- Newbie friendliness
- 25/100
- Issue type
- Refactor
- Clarity
- Mostly clear
- Activity status
- Active
- Tech stack
- c
- Domain
- operating-systems
Research direction
Start by reading the cited lifecycle and defect locations in src/runtime/thread.c, src/runtime/forkipc.c, src/syscall/signal.c, src/core/guest.c, src/syscall/inotify.c, src/syscall/usbdev.c, and src/debug/gdbstub.c. The issue says the survey was not built or run, so verify a cited defect with a focused probe or test before filing it as a separate issue and linking it here. Done means the defects are individually tracked and the proposed lifecycle changes have a defined scope.
Written by the indexing model from the issue text.
Description
Problem
Most object lifecycles in elfuse have no named state. The state lives in a combination of bools, a sentinel value (-1, 0, NULL), a refcount plus a flag, an atomic changed by CAS, the position inside a protocol, or the X7/X8/X9-X11 registers on the HVC return path. Each transition is a write at its own call site, so nothing checks that a transition is legal from the current state, and a missing or skipped transition shows up only as a bug.
A read of src/ at 0c499d7 found 101 such lifecycles with three or more states, or two states and an ordering rule. Nothing was built or run for this survey; the defects below were found by reading the cited lines.
Only five enums in src/ name a lifecycle, and their transitions are still spread out:
exec_handoff_state_t(src/syscall/exec.c): one setter,exec_handoff_set_state, with no from-state check; a successful exec writes EMPTY twice.urb_state_t(src/syscall/usbdev.c): three flags (discarding,orphaned,handback) carry the rest of the lifecycle, so COMPLETED also covers records IOKit still owns.posix_timer_notification_t(src/syscall/signal.c): written at 6 sites in 5 functions; armed (expiry_ns != 0) and SIGEV_NONE (signum == 0) stay implicit.tlbi_kind_t(src/core/guest.h): a one-way widening accumulator changed in 3 functions.- the anonymous
hist_modeenum (src/debug/syscall-hist.c).
| Area | Count | Examples |
|---|---|---|
Signals, timers, SysV IPC, memory (signal.c, time.c, sysvipc.c, asyncio.c, sys.c, mem.c) |
25 | shared-set signal claims, SROP cookie stack, on_altstack, pending_fault, itimers, shmat table, RLIMIT_CPU sampler, MAP_FIXED replace transaction, brk tracker |
Path and network (path.c, casefold-walk.c, chown-overlay.c, net*.c, netlink.c) |
15 | path_translate_at pipeline, RESOLVE_NO_XDEV walker, chown overlay entry, SCM_RIGHTS install and rollback, abstract AF_UNIX entry, netlink reply buffer and dump framing |
Core (guest.c, shim.S, bootstrap.c, rosetta.c, vdso.c, shim-globals.c) |
11 | W^X page flip (HVC #9), post-HVC X8 protocol, stage-1 descriptor lifecycle, region tracker stale latch, attention bitmask and its vvar mirror, Rosetta placement and re-entry |
Fork, exec, process, GDB (forkipc.c, fork-state.c, exec.c, proc*.c, gdbstub*.c) |
11 | fork IPC handshake, proc_entry_t, lifecycle registry row, ptrace tracee, pidfd entry, execve point of no return, GDB stop and continue, RSP parser |
FUSE, PTY, procfs, fs.c |
11 | FUSE session, request, mount and file slots; PTY keepalive row and hangup accounting; union directory stream; memfd seals |
fd table, special fds, poll, I/O (fdtable.c, fd.c, poll.c, inotify.c, io.c) |
10 | fd slot, fd_lifetime pin, timerfd, eventfd dup binding, signalfd byte count, epoll registration, io_xfer loop |
USB (usbdev.c, usbdev-fixture.c, usb-sysfs.c) |
10 | endpoint start gate, disconnect state, ready_token, device handle ladder, interface claim |
Threads and futexes (thread.c, futex.c, the run loop in proc.c) |
8 | thread slot, fork quiesce barrier, stop predicate, futex waiter, PI futex word |
Four shapes repeat across these areas:
- Side tables keyed by the guest fd number: eventfd, timerfd, signalfd, inotify, netlink, abstract sockets, the socket-option cache. The state belongs to the open file description, so
dup, close-then-reuse and fork break the lookup. #411 and #412 cover the cleanup and dup halves. - A pipe byte that stands for a level: inotify, eventfd, signalfd, netlink,
ready_tokenin usbdev, the wakeup pipe. Every transition site keeps "pipe readable iff X" by hand. - Flags that some exit path never clears:
on_altstack,noreserve,backing_drained,rlimit_cpu_killing. - Slot lifecycles built from several bools, where the deactivate paths each clean up differently. Three code paths set
thread_entry_t.active = 0, and onlythread_deactivatealso releases signal claims and the fork-barrier count.
Defects caused by a missing transition (found by reading the cited lines, not yet filed):
- Pattern 4.
thread_quiesce_siblings(src/runtime/thread.c) counts every active slot. A vm-clone child that exited but was not reaped stays active and never reaches the barrier. Its exit path invm_clone_thread_run(src/runtime/forkipc.c) skips the step that hands the count back, which the bring-up failure path does take. Every fork therefore waits the full 100 ms timeout while such a child exists. - Pattern 3. Only
rt_sigreturnand exec clearon_altstack(src/syscall/signal.c). When a handler on the alternate stack leaves throughsiglongjmp, nothing clears the flag, andsigaltstack()returns EPERM for the rest of the thread's life. - Pattern 3.
guest_region_t.noreserve(src/core/guest.c) is set at map time and never cleared afterguest_materialize_lazyhas filled the block, so a later translation fault in the same block runs the materialization, and its zero fill, again. - Pattern 2. The host fd behind an inotify fd is the read end of its self-pipe, and only
inotify_readwrites to that pipe (src/syscall/inotify.c). The kqueue event never raises the pipe level, sopollandepoll_waitnever report a file event before the first read.tests/test-inotify.cpasses whenpolltimes out. - The disconnect state in
src/syscall/usbdev.cis set at each completion site.usbdev_async_cbmarks the device disconnected when the main transfer result says the device is gone, but when the zero-length-packet write after it returnskIOReturnNoDevice, that result goes throughusbdev_urb_statusonly and the transition is skipped. - The GDB stop state is held in one flag.
gdb_stub_handle_stop(src/debug/gdbstub.c) clearsstop_requestedbeforethread_interrupt_allkicks the siblings, and the run loop's only stop check (gdb_stub_stop_requestedinsrc/syscall/proc.c) reads that flag alone, so the kicked threads resume guest code during a GDB stop.
Proposal
- File each defect above as its own issue, with a probe, and link it here.
- For the lifecycles that already caused a defect (fd-number side tables, the FUSE request and session, the thread slot, the inotify and signalfd readiness pipes), give the state a named enum and one transition function that checks the from-state, so a skipped transition fails loudly instead of leaving a stale flag.
- Key the fd side tables by open file description or by generation, as usbdev and the pidfd sweep already do (#411).
Alternatives
Fix each defect where it is, with no change to how the state is held. That is smaller per change, but it leaves the next missing transition to be found the same way.
Origin
Related: #411, #412, #511, #479, #384.
- Dominant language
- C
- Stars
- 287
- Forks
- 33
- Avg merge
- 2d 17h
- Merged PRs (30d)
- 18
Getting set up
- No Dockerfile or Docker Compose file
- No pull request template
- Read the contributing guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from sysprog21/elfuse
-
Difficulty 2/5 1-3 hours Newbie friendliness 64/100
Maintainers usually reply within 2 days
-
Difficulty 1/5 Under an hour Newbie friendliness 80/100
Maintainers usually reply within 2 days
-
bug
Difficulty 2/5 1-3 hours Newbie friendliness 86/100
Maintainers usually reply within 2 days
-
bug
Difficulty 2/5 1-3 hours Newbie friendliness 72/100
Maintainers usually reply within 2 days
-
bug
Difficulty 2/5 1-3 hours Newbie friendliness 75/100
Maintainers usually reply within 2 days
All issues in sysprog21/elfuse
Similar issues
-
Difficulty 2/5 1-3 hours Newbie friendliness 70/100
libreswan/libreswan#3185 · 1 comment ·
Maintainers usually reply within 1 day
-
Difficulty 2/5 1-3 hours Newbie friendliness 70/100
-
category:port-update
Difficulty 2/5 1-3 hours Newbie friendliness 72/100
Maintainers usually reply within 2 days
-
llvm:instcombine
Difficulty 2/5 1-3 hours Newbie friendliness 64/100
llvm/llvm-project#246503 · 1 comment ·
Maintainers usually reply within 1 day
-
Difficulty 2/5 1-3 hours Newbie friendliness 85/100
Maintainers usually reply within 1 day