fix(libkernel): fail sigprocmask with EINVAL for an unknown how #7365

Merged
milescoviello merged 1 commit from upstream-pr/7365 into main 2026-10-18 03:22:16 +00:00
milescoviello commented 2026-10-18 02:38:41 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by milescoviello on 2026-10-18T02:38:41Z.


What

sigprocmask and _sigprocmask threw std::invalid_argument("_sigprocmask: invalid how") when how was not SIG_BLOCK (1), SIG_UNBLOCK (2) or SIG_SETMASK (3), which ends the title. FreeBSD's sys_sigprocmask handles it differently:

  • it returns -1 with EINVAL;
  • it copies the old mask out only on success;
  • it ignores how when set is null.

pthread_sigmask here already returns EINVAL this way. _sigprocmask now checks how first, before it writes the previous mask, and the unreachable default throw is gone.

Tested

Ubuntu 24.04, GCC 13.3, Release.

  • guest_signal_sets gains CheckInvalidHow. For how 0, 4, -1 and 1000 with a set, both _sigprocmask and sigprocmask must return -1 with errno 22, leave the previous-mask buffer untouched and leave the blocked mask unchanged. With a null set, the call must return 0 and report the current mask.
    • On main b39d90bf14 the test aborts on the first call (uncaught std::invalid_argument).
    • With this PR it passes 3 of 3.
  • The other signal tests pass (10/10): guest_signals, guest_sigtimedwait, guest_itimer*, guest_user_context*, guest_sigaltstack.
  • tools/check_conventions.py --base upstream/main passes.

#3986 rewrites this switch for per-thread masks and keeps the throw. Whichever lands second needs a small rebase there.

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 (Claude Code)

🤖 Generated with Claude Code

<!-- greyfinch-sync:boykopovar/AnyPS5:issue:4905819937 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/7365). Originally posted by [milescoviello](https://github.com/milescoviello) on 2026-10-18T02:38:41Z. --- ### What `sigprocmask` and `_sigprocmask` threw `std::invalid_argument("_sigprocmask: invalid how")` when `how` was not `SIG_BLOCK` (1), `SIG_UNBLOCK` (2) or `SIG_SETMASK` (3), which ends the title. FreeBSD's [`sys_sigprocmask`](https://github.com/freebsd/freebsd-src/blob/8c639945a44588f6cfdddfb057bb1fdc07a8b9bd/sys/kern/kern_sig.c) handles it differently: - it returns -1 with `EINVAL`; - it copies the old mask out only on success; - it ignores `how` when `set` is null. `pthread_sigmask` here already returns `EINVAL` this way. `_sigprocmask` now checks `how` first, before it writes the previous mask, and the unreachable `default` throw is gone. ### Tested Ubuntu 24.04, GCC 13.3, Release. - `guest_signal_sets` gains `CheckInvalidHow`. For `how` 0, 4, -1 and 1000 with a set, both `_sigprocmask` and `sigprocmask` must return -1 with errno 22, leave the previous-mask buffer untouched and leave the blocked mask unchanged. With a null set, the call must return 0 and report the current mask. - On `main` b39d90bf14 the test aborts on the first call (uncaught `std::invalid_argument`). - With this PR it passes 3 of 3. - The other signal tests pass (10/10): `guest_signals`, `guest_sigtimedwait`, `guest_itimer*`, `guest_user_context*`, `guest_sigaltstack`. - `tools/check_conventions.py --base upstream/main` passes. #3986 rewrites this switch for per-thread masks and keeps the throw. Whichever lands second needs a small rebase there. ### Checklist <!-- Rules behind each item: https://github.com/boykopovar/AnyPS5/blob/main/CONTRIBUTING.md --> - [x] Based on current `main`; no other open PR implements the same functions - [x] One topic per PR; follow-ups go in a new PR - [x] No comments in code except [technical debt](https://github.com/boykopovar/AnyPS5/blob/main/docs/dev/CONVENTIONS.md) - [x] Unimplemented paths throw (`NotImplemented_nid_no_patch`); silent stubs are listed under Silent stubs in their library's [technical debt](https://github.com/boykopovar/AnyPS5/tree/main/docs/dev/debt) file - [x] No notes, investigation `.md` files or images added to the repository (attach them to this PR) - [x] New third-party code is a submodule built from source - [x] Generic behaviour, not specific to one title - [x] Depends on: none - [x] Fixes: none - [x] Unblocks: none - [x] GPUs tested: n/a - [x] AI-assisted: yes (Claude Code) 🤖 Generated with [Claude Code](https://claude.com/claude-code)
github-actions[bot] commented 2026-10-18 03:02:37 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by github-actions[bot] on 2026-10-18T03:02:37Z.


Some comparisons could not be completed because a pull request conflicts with the base branch. Review these shared files manually before concluding that there is no overlap.

Pull request Shared files not compared
PR 3986 core/libs/prx/libkernel/System/src/Signals.cpp
PR 6044 core/libs/tests/GuestSignalSets.cpp
PR 7201 core/libs/prx/libkernel/System/src/Signals.cpp
<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6244989855 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/7365#issuecomment-6244989855). Originally posted by [github-actions[bot]](https://github.com/apps/github-actions) on 2026-10-18T03:02:37Z. --- <!-- pr-overlap --> Some comparisons could not be completed because a pull request conflicts with the base branch. Review these shared files manually before concluding that there is no overlap. | Pull request | Shared files not compared | |---|---| | [PR 3986](https://www.github.com/boykopovar/AnyPS5/pull/3986) | `core/libs/prx/libkernel/System/src/Signals.cpp` | | [PR 6044](https://www.github.com/boykopovar/AnyPS5/pull/6044) | `core/libs/tests/GuestSignalSets.cpp` | | [PR 7201](https://www.github.com/boykopovar/AnyPS5/pull/7201) | `core/libs/prx/libkernel/System/src/Signals.cpp` |
Sign in to join this conversation.
No reviewers
No labels
No milestone
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Reference
boykopovar/AnyPS5!7365
No description provided.