Skip to content

fix(process): align wait and ptrace child semantics#1983

Merged
fslongjin merged 2 commits into
DragonOS-Community:masterfrom
fslongjin:codex/wait-ptrace-linux-compat
Jun 22, 2026
Merged

fix(process): align wait and ptrace child semantics#1983
fslongjin merged 2 commits into
DragonOS-Community:masterfrom
fslongjin:codex/wait-ptrace-linux-compat

Conversation

@fslongjin

@fslongjin fslongjin commented Jun 22, 2026

Copy link
Copy Markdown
Member

Summary

This PR refactors wait child selection and ptrace child handling to better match Linux wait semantics.

  • Move wait-specific PID selection out of the kill-only converter and add a wait selector for wait4/waitid.
  • Split natural-child and ptrace-child wait relations so P_PID uses TGID for natural waits and PID for ptrace waits.
  • Add a minimal ptrace relation module for PTRACE_TRACEME ownership, cleanup, and wait-side checks.
  • Fix zombie/event reporting ownership, stopped/continued one-shot consumption, __WNOTHREAD filtering, and delayed thread-group leader reaping.
  • Extend wait-focused dunitest coverage for ptrace, clone/wall/nothread, delayed leader, TID, waitid, and P_PIDFD errno boundaries.

Validation

  • make fmt
  • make kernel
  • host Linux wait_rusage_test: 15/15 passed
  • DragonOS guest dunitest normal/wait_rusage: passed
  • DragonOS guest gVisor wait_test: passed
  • git diff --check

Notes

P_PIDFD support remains an explicit future compatibility boundary beyond the currently covered errno validation. Full ptrace attach/detach and traced-stop semantics are also outside this minimal TRACEME relation change.

Related to: #1850

Refactor wait child selection away from the kill-only PID converter and introduce a wait-specific selector that models wait4 and waitid rules directly. This keeps P_ALL, P_PID, P_PGID and the current P_PIDFD boundary in the wait layer instead of leaking waitid semantics into sys_kill.

Split natural-child and ptrace-child handling into explicit wait relations. Natural P_PID waits now resolve through the thread-group leader while ptrace waits resolve by task PID, matching Linux's TGID/PID split. The scan path also handles __WCLONE, __WALL and __WNOTHREAD without relying on test-specific shortcuts.

Add a small ptrace relation module for PTRACE_TRACEME, tracee ownership, relation cleanup and wait-side checks. The relation is protected by a shared lock so wait cannot observe half-published ptrace state, and TRACEME uses the actual fork parent when a worker thread creates the child.

Tighten event reporting and reaping. Zombie ownership is acquired before user-visible return data is filled, stopped and continued notifications are consumed with a single sighand lock operation, and zombie group leaders with live subthreads stay waitable without being reaped early.

Extend wait_rusage dunitests to cover ptrace TRACEME, repeated TRACEME denial, __WNOTHREAD behavior, delayed group leader reaping, natural TID wait rejection, waitid option filtering and the current negative P_PIDFD errno boundary.

Signed-off-by: longjin <longjin@dragonos.org>
@github-actions github-actions Bot added Bug fix A bug is fixed in this pull request test Unitest/User space test labels Jun 22, 2026
Remove blocklist entries now covered by wait/ptrace compatibility fixes.

Signed-off-by: longjin <longjin@dragonos.org>
Co-authored-by: Cursor <cursoragent@cursor.com>
@fslongjin fslongjin marked this pull request as ready for review June 22, 2026 16:47
@fslongjin

Copy link
Copy Markdown
Member Author

@codex review

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. Delightful!

Reviewed commit: a93cb5b119

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

@fslongjin fslongjin merged commit e733181 into DragonOS-Community:master Jun 22, 2026
13 of 14 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Bug fix A bug is fixed in this pull request test Unitest/User space test

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant