fix(libkernel): return EINVAL for null mutexattr output pointers #11085

Closed
slopgobblercobbler wants to merge 1 commit from upstream-pr/11085 into main
slopgobblercobbler commented 2026-10-25 17:19:18 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by slopgobblercobbler on 2026-10-25T17:19:18Z.


What

Align pthread_mutexattr_getprotocol, pthread_mutexattr_getprioceiling, pthread_mutexattr_gettype, and pthread_mutexattr_getpshared in core/libs/prx/libkernel/Pthread/Posix/Mutex.cpp:

  • Return POSIX_EINVAL (22) / PosixThread::GUEST_EINVAL (22) when passed a null output pointer (!protocol, !prioceiling, !type, !pshared), instead of throwing std::runtime_error.
  • For SCE wrappers (scePthreadMutexattrGet*), this maps via PosixThread::ToSce(POSIX_EINVAL) to SCE_KERNEL_ERROR_EINVAL (0x80020016).
  • Updates core/libs/tests/GuestPthreadMutexattr.cpp to verify that passing null output pointers returns GUEST_EINVAL / SCE_KERNEL_ERROR_EINVAL without throwing.
  • Updates docs/dev/debt/libkernel.md technical debt entry (< 1,000 characters) stating unmeasured console behavior first.

Tested

  • Ran python tools/check_conventions.py --base upstream/main --head HEAD (0 findings) and python core/libs/tests/test_public_headers.py --audit-only (passed).
  • Verified on Windows 11 with GCC 15.2 (guest_pthread_mutexattr passes 3/3; baseline from main aborts with null type check).

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: #10725 (merge order only; no functional dependency)
  • Fixes: none
  • Unblocks: none
  • GPUs tested: n/a
  • AI-assisted: yes
<!-- greyfinch-sync:boykopovar/AnyPS5:issue:5006918973 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/11085). Originally posted by [slopgobblercobbler](https://github.com/slopgobblercobbler) on 2026-10-25T17:19:18Z. --- ### What Align pthread_mutexattr_getprotocol, pthread_mutexattr_getprioceiling, pthread_mutexattr_gettype, and pthread_mutexattr_getpshared in core/libs/prx/libkernel/Pthread/Posix/Mutex.cpp: - Return POSIX_EINVAL (22) / PosixThread::GUEST_EINVAL (22) when passed a null output pointer (!protocol, !prioceiling, !type, !pshared), instead of throwing std::runtime_error. - For SCE wrappers (scePthreadMutexattrGet*), this maps via PosixThread::ToSce(POSIX_EINVAL) to SCE_KERNEL_ERROR_EINVAL (0x80020016). - Updates core/libs/tests/GuestPthreadMutexattr.cpp to verify that passing null output pointers returns GUEST_EINVAL / SCE_KERNEL_ERROR_EINVAL without throwing. - Updates docs/dev/debt/libkernel.md technical debt entry (< 1,000 characters) stating unmeasured console behavior first. ### Tested - Ran `python tools/check_conventions.py --base upstream/main --head HEAD` (0 findings) and `python core/libs/tests/test_public_headers.py --audit-only` (passed). - Verified on Windows 11 with GCC 15.2 (`guest_pthread_mutexattr` passes 3/3; baseline from main aborts with null type check). ### Checklist - [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: #10725 (merge order only; no functional dependency) - [x] Fixes: none - [x] Unblocks: none - [x] GPUs tested: n/a - [x] AI-assisted: yes
MarcZX10 commented 2026-10-25 17:21:08 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-25T17:21:08Z.

Review: CHANGES_REQUESTED


The new GuestPthreadMutexattr.cpp assertions are the relevant functional tests, but the Tested section lists only the conventions check and test_public_headers.py --audit-only; that audit does not run the mutex-attribute test binary. The hosted feature test jobs are also skipped. Please run and report the focused GuestPthreadMutexattr test (OS/toolchain and exact command), or state clearly that it was not run before opening the PR. I found no separate behavioral issue in the null-check ordering on this static pass.

<!-- greyfinch-sync:boykopovar/AnyPS5:review:5644325986 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/11085#pullrequestreview-5644325986). Originally posted by [MarcZX10](https://github.com/MarcZX10) on 2026-10-25T17:21:08Z. **Review:** CHANGES_REQUESTED --- The new `GuestPthreadMutexattr.cpp` assertions are the relevant functional tests, but the `Tested` section lists only the conventions check and `test_public_headers.py --audit-only`; that audit does not run the mutex-attribute test binary. The hosted feature test jobs are also skipped. Please run and report the focused `GuestPthreadMutexattr` test (OS/toolchain and exact command), or state clearly that it was not run before opening the PR. I found no separate behavioral issue in the null-check ordering on this static pass.
adriadam10 commented 2026-10-27 01:47:58 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by adriadam10 on 2026-10-27T01:47:58Z.

Review: CHANGES_REQUESTED


Thanks for the update. Findings:

  • core/libs/prx/libkernel/Pthread/Posix/Mutex.cpp:118,139,152,163: the null output pointer now returns EINVAL, but no source says that is the result. FreeBSD 11.4 thr_mutexattr.c checks only attr/*attr and then writes through the pointer, so a null output faults there; no console measurement shows EINVAL either. An unknown result must throw (as main does), not return a made-up error. Please drop the behaviour change, or add a measurement of the console returning EINVAL and cite it.
  • docs/dev/debt/libkernel.md:10: the new entry says the null-output EINVAL is "as in FreeBSD 11.4 libthr", which is false for that case. It also duplicates the existing pthread_mutexattr_setprotocol, ... entry at line 8 instead of amending it. If a choice is kept, say it is a choice and edit the existing entry.
  • The PR conflicts with #10725, which rewrites the same pthread_mutexattr_gettype guard; rebase after it lands and keep both checks.

Feel free to push again once these are addressed.

<!-- greyfinch-sync:boykopovar/AnyPS5:review:5661321228 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/11085#pullrequestreview-5661321228). Originally posted by [adriadam10](https://github.com/adriadam10) on 2026-10-27T01:47:58Z. **Review:** CHANGES_REQUESTED --- Thanks for the update. Findings: - `core/libs/prx/libkernel/Pthread/Posix/Mutex.cpp:118,139,152,163`: the null output pointer now returns `EINVAL`, but no source says that is the result. FreeBSD 11.4 `thr_mutexattr.c` checks only `attr`/`*attr` and then writes through the pointer, so a null output faults there; no console measurement shows `EINVAL` either. An unknown result must throw (as `main` does), not return a made-up error. Please drop the behaviour change, or add a measurement of the console returning `EINVAL` and cite it. - `docs/dev/debt/libkernel.md:10`: the new entry says the null-output `EINVAL` is "as in FreeBSD 11.4 libthr", which is false for that case. It also duplicates the existing `pthread_mutexattr_setprotocol, ...` entry at line 8 instead of amending it. If a choice is kept, say it is a choice and edit the existing entry. - The PR conflicts with #10725, which rewrites the same `pthread_mutexattr_gettype` guard; rebase after it lands and keep both checks. Feel free to push again once these are addressed.

Pull request closed

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!11085
No description provided.