Skip to content

fix(libkernel): fail sigprocmask with EINVAL for an invalid how - #5463

Closed
xXPBSXx wants to merge 2 commits into
boykopovar:mainfrom
xXPBSXx:fix/sigprocmask-einval-v2
Closed

xXPBSXx wants to merge 2 commits into
boykopovar:mainfrom
xXPBSXx:fix/sigprocmask-einval-v2

Conversation

@xXPBSXx

@xXPBSXx xXPBSXx commented Oct 13, 2026 •

Copy link
Copy Markdown
Contributor

What

sigprocmask (and _sigprocmask) with a mask and a how other than SIG_BLOCK (1), SIG_UNBLOCK (2) or SIG_SETMASK (3) threw std::invalid_argument into the guest, which ends the title. FreeBSD 11.4's kern_sigprocmask runs the switch on how only when a new set was given, and its default: case sets error = EINVAL and leaves the mask unchanged. The system call sys_sigprocmask copies the old mask out to the caller only when kern_sigprocmask returned 0 (if (osetp && !error) copyout(...)), so a caller that passed an invalid how finds its output buffer unchanged.

The default: case of _sigprocmask_nid_postfix (core/libs/prx/libkernel/System/src/Signals.cpp) now sets errno to EINVAL (22) and returns -1 without writing the previous mask to the caller's buffer; on success the previous mask is written after the switch, as before. With no new set (set == NULL) the switch is skipped, so an invalid how is not an error there, as in FreeBSD. pthread_sigmask already rejected an invalid how with 22 and is not changed.

No title evidence. This is FreeBSD conformance.

Overlap (git merge-tree against main d1670009f, and against the heads of #5261, #5312, #5306, #5241, #5272 and #4383): no conflict. #3986 ("keep the signal mask per thread") conflicts with this change, and it already conflicts with main on its own.

Tested

  • python tools/check_conventions.py --base upstream/main --title ... --body ... passes for this text. The new checks are in core/libs/tests/GuestSignals.cpp (registered as guest_signals): how 0, 4 and -1 with a mask return -1 with EINVAL and leave the previous-mask buffer unchanged, and how 0 with no new set returns 0. The branch is two commits (the fix and the follow-up that stops writing the previous mask on EINVAL).
  • Re-run on 14 October 2026 (Windows 10 19045, MinGW-w64 GCC 15.2.0, Release, -j4), the head a7c6f606c merged onto main 7a0c838ca: guest_signals passes (2.00 s, ctest); with Signals.cpp taken back to main and the new test kept it fails ([libc] unhandled exception 'St16invalid_argument', exit code 0xc0000409). Second run, head merged onto main d1670009f, the targets of the group built as well: on main alone guest_filesystem, guest_file_vector, guest_memory, guest_kernel_sys, guest_signals and guest_directory_buffer pass (6 of 6); with the head and its test 6 of 6 pass, 0 failed. This replaces the earlier combined-build figures. Not run: the socket tests, Linux, a console, a title. With only the follow-up commit reverted (the previous mask written before the switch) the corrected test fails as well (exit code 0xc0000409; measured earlier on main 8d98e8851, not repeated in this run).
  • Not tested: Linux (one source for both hosts), a console, a title run.

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); no silent stub added
  • No notes, investigation .md files or images added to the repository
  • New third-party code is a submodule built from source (none added)
  • Generic behaviour, not specific to one title
  • Depends on: none
  • Unblocks: none
  • GPUs tested: n/a (not an AGC, shader or VideoOut change)
  • AI-assisted: yes

AI-assisted (Claude Code).

sigprocmask with a mask and a how other than SIG_BLOCK, SIG_UNBLOCK or
SIG_SETMASK threw std::invalid_argument into the guest. FreeBSD 11.4
kern_sigprocmask copies the old mask out first and then returns EINVAL from the
default case of the switch on how; the call now returns -1 with errno EINVAL in
the same order. pthread_sigmask already rejected the value.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
…fails with EINVAL

FreeBSD 11.4 sys_sigprocmask copies the old mask out only when kern_sigprocmask returns 0 (if (osetp && !error) copyout), so a guest sees its output buffer unchanged after an invalid how. _sigprocmask now writes the previous mask after the how switch.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
@oneandonlydean

Copy link
Copy Markdown
Collaborator

Closing: no title is known to reach this. With the queue at 700+ open PRs, please hold off on new PRs that don't name a title needing the change until it's down. If a title stops on this on current main, reopen with the title ID and the log line.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants