Skip to content

test(libkernel_sys): expect the macOS kernel's EINVAL for wait4 with pid INT_MIN - #19924

Merged
oneandonlydean merged 1 commit into
boykopovar:mainfrom
XIIYAZ:test/wait4-int-min-macos
Nov 14, 2026
Merged

oneandonlydean merged 1 commit into
boykopovar:mainfrom
XIIYAZ:test/wait4-int-min-macos

Conversation

@XIIYAZ

@XIIYAZ XIIYAZ commented Nov 14, 2026

Copy link
Copy Markdown
Contributor

What

guest_kernel_sys_wait already expects the host kernel's error for wait4/_wait4 with pid == INT_MIN on Linux (ESRCH, 3), since WaitProcess_nid_no_patch passes the host ::wait4 errno through and the FreeBSD answer (ECHILD, 10) comes from FreeBSD's own process-group lookup. macOS was not listed: its kernel rejects pid == INT_MIN with EINVAL (22), so the four wait4 variants fail there on the first valid option:

pid=-2147483648 options=0 result=-1 errno=22 expected=10
Kernel sys API check failed at line 91

This adds the macOS expectation beside the Linux one, under the same condition. Only the test changes; Linux, Windows and the other pid/option combinations are unchanged.

Tested

macOS 26.7.3, Apple M4, Apple clang 21.0.0, full build (-DCMAKE_BUILD_TYPE=Release -DBUILD_TESTING=ON -DCMAKE_OSX_ARCHITECTURES=x86_64, tests under Rosetta) on main with #17425, #11049, #11437, #19903 and #19920 merged locally:

  • Before: guest_kernel_sys_wait_wait4, _wait4_patched, __wait4 and __wait4_patched fail with the output above.
  • After: all six guest_kernel_sys_wait_* tests pass, which also runs every other pid/option pair the first failure used to stop.

python3 tools/check_conventions.py --base origin/main passes.

Checklist

  • Based on current main; no other open PR implements the same functions
  • One topic per PR; follow-ups go in a new PR
  • No comments in code except technical debt
  • Unimplemented paths throw (NotImplemented_nid_no_patch); silent stubs are listed under Silent stubs in their library's technical debt file
  • No notes, investigation .md files or images added to the repository (attach them to this PR)
  • New third-party code is a submodule built from source
  • Generic behaviour, not specific to one title
  • Depends on: none
  • Fixes: none
  • Unblocks: none
  • GPUs tested: n/a
  • AI-assisted: yes

@PrivacyOnion PrivacyOnion left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Verified on Linux (Ubuntu 24.04, GCC 13.3, Ninja, Release) against 514966ffda:

  • Conventions: tools/check_conventions.py passed; git diff --check clean.
  • Build: guest_kernel_sys_wait_tests built cleanly.
  • CTest (guest_kernel_sys_wait_wait3, guest_kernel_sys_wait_wait3_patched, guest_kernel_sys_wait_wait4, guest_kernel_sys_wait_wait4_patched, guest_kernel_sys_wait__wait4, guest_kernel_sys_wait__wait4_patched):
    1/6 Test #832: guest_kernel_sys_wait_wait3 ............   Passed    0.05 sec
    2/6 Test #833: guest_kernel_sys_wait_wait3_patched ....   Passed    0.05 sec
    3/6 Test #834: guest_kernel_sys_wait_wait4 ............   Passed    0.04 sec
    4/6 Test #835: guest_kernel_sys_wait_wait4_patched ....   Passed    0.04 sec
    5/6 Test #836: guest_kernel_sys_wait__wait4 ...........   Passed    0.04 sec
    6/6 Test #837: guest_kernel_sys_wait__wait4_patched ...   Passed    0.05 sec
    100% tests passed, 0 tests failed out of 6
    
  • Code reading:
    • Verified in core/libs/tests/GuestKernelSysWait.cpp that the macOS expectation of EINVAL (22) under defined(APPLE) accurately matches the Darwin/XNU kernel sys_wait4 implementation, which explicitly rejects pid == INT_MIN with EINVAL to prevent signed negation overflow in -pid.
    • Verified in core/libs/tests/GuestKernelSysWait.cpp that the condition (options & ~0x8000003fu) == 0 && test != "wait3" && pid == std::numeric_limits::min() properly excludes wait3 (which does not receive a pid argument and expects ECHILD 10) and preserves EINVAL (22) when invalid option bits are passed.
    • Verified in core/libs/tests/GuestKernelSysWait.cpp that expectations on Linux (ESRCH 3) and Windows (ECHILD 10) remain completely unchanged across all iterations of pid and options.
    • Verified that no comments were added to core/libs/tests/GuestKernelSysWait.cpp, adhering strictly to the AGENTS.md rule prohibiting code comments outside #endif and namespace closures.
    • Verified type safety and signedness in comparisons between pid and std::numeric_limits::min() as well as unsigned option bitmasking, ensuring clean compilation across GCC, Clang, and MSVC without warnings.
  • Note: the AI-assisted checkbox can stay.

Looks Good To Me

@JJenkx

JJenkx commented Nov 14, 2026

Copy link
Copy Markdown
Contributor

Windows check of head 514966ffda, merged onto main 37a57152ce (f0c8f5e0e8, clean merge).

Setup: Windows 11 Enterprise 22621, WinLibs GCC 15.2 UCRT, Release. The hosted Windows check does not run these tests on pull requests.

  • guest_kernel_sys_wait__wait4, guest_kernel_sys_wait__wait4_patched, guest_kernel_sys_wait_wait3, guest_kernel_sys_wait_wait3_patched, guest_kernel_sys_wait_wait4, guest_kernel_sys_wait_wait4_patched pass in 3 of 3 runs, none skipped.

AI-assisted: yes.

@XIIYAZ XIIYAZ mentioned this pull request Nov 14, 2026
@oneandonlydean
oneandonlydean merged commit 3ad3a06 into boykopovar:main Nov 14, 2026
13 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants