Skip to content

feat(proc,tty,syscall): implement pgid/sessions, controlling tty ioctls, kill(-pgid), and job-control wait (N2.5, #66) - #147

Merged
YUZHEthefool merged 1 commit into
mainfrom
feat/n2-5-pgid-sessions-job-control
Nov 28, 2026
Merged

YUZHEthefool merged 1 commit into
mainfrom
feat/n2-5-pgid-sessions-job-control

Conversation

@YUZHEthefool

@YUZHEthefool YUZHEthefool commented Nov 28, 2026 •

Copy link
Copy Markdown
Member

Summary

Implements N2.5 from #66 (Process groups, sessions, controlling terminal, kill(-pgid), and WUNTRACED / WCONTINUED / P_PGID job-control wait):

  • Process Group, Session & Controlling-Terminal State (kernel/kernel_core/process.rs, fork.rs, syscall/exec.rs):
    • Added compact atomic job-control fields on ThreadGroup (pgid, sid, has_execed, has_ctty, job_wait_state — ~24 B inline so PCB memory budget stays safe for KCOV/fuzzing).
    • Inherited pgid/sid/has_ctty across fork(), set has_execed on exec(), initialized PID 1 as root session/fg-pgid owner of CONSOLE_TTY, and released console controlling-terminal ownership on session-leader exit.
  • Process Group & Session Syscalls (kernel/seccomp/syscall_table.rs, kernel/kernel_core/syscall/mod.rs, syscall/proc.rs):
    • Registered and dispatched setpgid(109), getpgrp(111), setsid(112), getpgid(121), getsid(124) with POSIX validation rules (session leader / cross-session / post-exec EACCES / existing-PGID EPERM) and PID-namespace translation.
  • Controlling Terminal Ioctls & Group Signal Delivery (kernel/kernel_core/syscall/fs.rs, kernel/kernel_core/syscall/signal.rs, kernel/kernel_core/signal.rs):
    • Added TIOCSCTTY (0x540E), TIOCGPGRP (0x540F), TIOCSPGRP (0x5410), TIOCNOTTY (0x5422) (sending SIGHUP + SIGCONT to the former foreground PGID), and TIOCGSID (0x5429) on console descriptors.
    • Extended kill(62) to handle pid == 0 (caller PGID), pid < -1 (target PGID -pid), and pid == -1 (broadcast excluding init and self), delivering to non-self targets before self.
    • Recorded stop/continue transitions in ThreadGroup and notified parent waiters (honoring SA_NOCLDSTOP).
  • Job-Control Wait (wait4 / waitid) (kernel/kernel_core/syscall/proc.rs):
    • Extended wait4(61) with pid == 0 / pid < -1 PGID selectors, WUNTRACED, and WCONTINUED (encoding (sig << 8) | 0x7f and 0xffff).
    • Extended waitid(247) with P_PGID, WSTOPPED/WUNTRACED, WCONTINUED, CLD_STOPPED (5), and CLD_CONTINUED (6).
  • Tests & Gates:
    • Added 4 hosted kernel-core unit tests (231 -> 235 in scripts/tools/hosted_subcrate_tests.sh).
    • Updated the pre-N2.5 waitid argument-contract check and added a pinned Ring-3 N2.5 oracle leg in userspace/src/syscall_test.rs and scripts/gates/boot/ring3_mm_oracle.sh.

Verification

  • make fmt-check: PASS
  • make abi-check: PASS
  • make lint: PASS
  • bash scripts/tools/hosted_subcrate_tests.sh: PASS (kernel-core 235/235, all suites green)
  • make clippy: PASS
  • make build: PASS
  • ZERO_OS_STRICT_TESTS=1 bash scripts/gates/boot/boot_check.sh: PASS (50/50)
  • ZERO_OS_STRICT_TESTS=1 SMP_CORES=4 bash scripts/gates/boot/kernel_test.sh: PASS (50/50)
  • make test-ring3-mm: PASS (72/72 legs including new N2.5 Ring-3 oracle leg)
  • make test-kcov: PASS (KCOV-E2E PASS)

Refs #66

…ls, kill(-pgid), and job-control wait (N2.5, #66)

- Add process group, session, exec-barrier, controlling-terminal ownership, and atomic job-control wait-event tracking on ThreadGroup (~24 B inline, keeping PCB allocation budget safe for KCOV/fuzzing), plus CONSOLE_TTY session/fg-pgid management initialized for PID 1 and released on session-leader exit.
- Wire POSIX job-control syscalls in syscall_table.rs and syscall dispatch: setpgid(109), getpgrp(111), setsid(112), getpgid(121), getsid(124), enforcing POSIX session/exec/leader constraints and PID-namespace translation.
- Extend kill(62) to support pid == 0 (caller PGID), pid < -1 (target PGID -pid), and pid == -1 (broadcast excluding init/self), delivering to non-self targets before self; add controlling-terminal ioctls TIOCSCTTY, TIOCGPGRP, TIOCSPGRP, TIOCNOTTY (with SIGHUP+SIGCONT to former fg PGID), and TIOCGSID.
- Extend wait4(61) and waitid(247) to support PGID selectors (wait4 pid == 0 / pid < -1 and waitid P_PGID), WUNTRACED/WSTOPPED, WCONTINUED, and CLD_STOPPED/CLD_CONTINUED reporting, with parent SIGCHLD/waiter notification on stop/continue transitions honoring SA_NOCLDSTOP.
- Add 4 hosted kernel_core unit tests (235/235), update the pre-N2.5 waitid argument-validation oracle, and add a pinned Ring-3 N2.5 end-to-end oracle leg in syscall_test.rs and ring3_mm_oracle.sh.
@github-actions github-actions Bot added area: process/ABI Processes, syscalls, usercopy, signals, ELF, and Linux ABI area: security Capabilities, LSM, seccomp, audit, hardening, crypto, and livepatch area: userspace Ring-3 programs, libc compatibility, and userspace support area: tests Unit, hosted, runtime, QEMU, SMP, stress, and conformance tests area: tooling/CI Build system, scripts, hooks, automation, and repository tooling size: XL At least 1000 review lines, excluding generated/binary artifacts enhancement New feature or request labels Nov 28, 2026
@YUZHEthefool
YUZHEthefool merged commit bfd05ab into main Nov 28, 2026
19 checks passed
@YUZHEthefool
YUZHEthefool deleted the feat/n2-5-pgid-sessions-job-control branch November 28, 2026 06:21
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area: process/ABI Processes, syscalls, usercopy, signals, ELF, and Linux ABI area: security Capabilities, LSM, seccomp, audit, hardening, crypto, and livepatch area: tests Unit, hosted, runtime, QEMU, SMP, stress, and conformance tests area: tooling/CI Build system, scripts, hooks, automation, and repository tooling area: userspace Ring-3 programs, libc compatibility, and userspace support enhancement New feature or request size: XL At least 1000 review lines, excluding generated/binary artifacts

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant