fix(libkernel): return SCE_KERNEL_ERROR_EINVAL for null key in scePthreadKeyCreate #14128
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/14128"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Imported from boykopovar/AnyPS5. Originally posted by slopgobblercobbler on 2026-10-31T19:57:15Z.
What
core/libs/prx/libkernel/Pthread/src/Tsd.cpp, returnSCE_KERNEL_ERROR_EINVAL(0x80020016) instead of throwing hoststd::runtime_errorwhenscePthreadKeyCreateis called with a nullkeypointer.core/libs/tests/GuestPthreadKey.cppverifyingscePthreadKeyCreate(nullptr, ...)returnsSCE_KERNEL_ERROR_EINVAL,pthread_key_create_nid_postfix(nullptr, ...)returnsPOSIX_EINVAL, and deleting invalid / already-deleted keys returnsSCE_KERNEL_ERROR_EINVAL/POSIX_EINVAL.scePthreadKeyCreateindocs/dev/debt/libkernel.md.Tested
python -m ziglang c++ -std=c++20.python tools/check_conventions.py --base upstream/main --head HEAD(0 findings).Checklist
main; no other open PR implements the same functionsNotImplemented_nid_no_patch); silent stubs are listed under Silent stubs in their library's technical debt file.mdfiles or images added to the repository (attach them to this PR)Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-31T20:06:21Z.
Review: CHANGES_REQUESTED
Reviewed — changes requested
The null-key result is explicitly documented as unmeasured on console, and four required PR-template items remain unchecked; the conventions check confirms the latter.
What I ran
Reviewed PR head
c32b3c83285716e5f591a09cb9d7b163a4984c1aagainst base500d37a747c2b958e8696aa16213a0ee78d47505; the fresh merge preview against currentmain(0836dfdf4fecb1e0326100c490476e15d3a74da5) was clean. Environment: Linux x86_64, Python 3.11.2, GCC 12.2.0. No build or C++ test was run.Results
git diff --checkmainGuestPthreadKeyruntime testUnedited conventions-check output
Findings
Blocking
scePthreadKeyCreate(nullptr, ...)now returnsSCE_KERNEL_ERROR_EINVAL, but the new debt entry says console fault handling is unmeasured. The repository guidance requires unknown behavior to keep throwing and record the gap. Please provide console evidence for this return value, or restore the throw behavior while it remains unknown.Depends on: none,Fixes: none,Unblocks: none, andGPUs tested: n/aunchecked. Tick these required entries so the conventions check passes.Non-blocking
None found in this source-level pass.
Sources
Not verified
The Windows job had not completed; Linux and specialized hosted jobs were skipped. I did not build or run the C++ test, and did not measure null-pointer behavior on a PS5 console.
To get this to a good state
Please resolve the unmeasured behavior according to the repository rule and tick all four checklist items. I will rerun the same precheck on the updated head.
Imported from boykopovar/AnyPS5. Originally posted by adriadam10 on 2026-11-06T15:29:01Z.
Review: CHANGES_REQUESTED
Thanks for the PR. One blocking point:
core/libs/prx/libkernel/Pthread/src/Tsd.cpp:89: returningSCE_KERNEL_ERROR_EINVALfor a nullkeyreplaces a throw with a plausible-looking result that nothing supports. FreeBSD's libthr (_thr_key_create,lib/libthr/thread/thr_spec.c) has no null check: it writes*key = i + 1and faults on a null pointer, it does not return EINVAL. The debt entry itself says the console behaviour is unmeasured. Without a source or a measurement, an unverified case should keep throwing (the exact-or-throw rule). Either drop theTsd.cppchange and thenullptrtest lines, or show where the console returns EINVAL (a reference or a hardware measurement).core/libs/tests/GuestPthreadKey.cpp:100-102: theKeyDelete(9999)andpthread_key_delete_nid_postfixchecks already pass onmain, so they test nothing this PR changes. Keep them only as a separate test-only change if you want the coverage.If the null-key change is dropped, the
docs/dev/debt/libkernel.mdline goes too.Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-11-14T05:34:55Z.
Review: COMMENTED
Reviewed — no blocking findings
The changed implementation returns
SCE_KERNEL_ERROR_EINVALfor a null key, and the POSIX wrapper maps that result toPOSIX_EINVAL; I did not run the reported build or convention check.What I ran
Read the prepared diff and all three changed files at head
4cd962f4ca01fbfbe836d61b7a6952844aa54abe. No commands or tests were run.Results
Findings
Blocking
None.
Non-blocking
None.
Not verified
The reported Windows 11 compilation and convention check were not run during this review. No files were excluded from the changed-file review.
To get this to a good state
Nothing is required.
Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-11-17T00:04:58Z.
Review: APPROVED
Reviewed — looks good
Nothing in the reviewed changes blocks merging; the null-key handling and POSIX error conversion are consistent with the wrappers, and the added tests cover the new behavior.
What I ran
Reviewed head
add53fa0579a99f566c59d02d56c791f5b87a3c1. No commands or tests were run. Readreview/description.md,review/commits.md,review/manifest.json,review/diff.patch,core/libs/prx/libkernel/Pthread/src/Tsd.cpp,core/libs/prx/libkernel/Posix/Tsd.cpp, andcore/libs/tests/GuestPthreadKey.cpp.review/files.jsonwas not available. All three changed files were included in the manifest; the changed documentation file was not read.Results
Findings
Blocking
None.
Non-blocking
None.
Not verified
The
docs/dev/debt/libkernel.mdchange was not read. Tests and the author-reported Windows compilation and conventions check were not run independently. Console behavior is unmeasured, as the debt entry states.To get this to a good state
Nothing is required.
Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-11-17T22:32:05Z.
Review: COMMENTED
Reviewed — no blocking findings
The change is sound and matches its description; I am withholding approval only because one reviewed file was not read in full.
What I ran
9bdaf33e8b(base: main)repo_read.py search KeySlotandrepo_read.py search pthread_key_delete_nid_postfixrepo_read.py caton the changed ranges of Tsd.cpp, GuestPthreadKey.cpp, libkernel.md, and Posix/Tsd.cppResults
SCE_KERNEL_ERROR_EINVALbefore any writeKeySlotrejects keys outside 1 to 512, so 9999 is safescePthreadKeyCreate; see FindingsFindings
Blocking
None.
Non-blocking
core/libs/prx/libkernel/Pthread/src/Tsd.cpp:91: the onlythrowin the file was removed. A search found no remainingthrow, so#include <stdexcept>(line 11) may now be unused. Check for otherstd::runtime_erroruses before removing it.core/libs/tests/GuestPthreadKey.cpp:82:pthread_key_create_nid_postfix(nullptr, nullptr)returnsGUEST_EINVALatcore/libs/prx/libkernel/Pthread/Posix/Tsd.cpp:19before it reachesscePthreadKeyCreate. That assertion passes without this change. The direct call on line 81 is the one that exercises the fix.Not verified
POSIX_EINVALequalsGUEST_EINVAL: not checked.docs/dev/debt/libkernel.md: lines 1 to 233 and 440 to 449 were read. Lines 234 to 439 were not read, which is why approval is withheld.Files read:
core/libs/prx/libkernel/Pthread/src/Tsd.cpp(all 134 lines),core/libs/tests/GuestPthreadKey.cpp(all 137 lines),docs/dev/debt/libkernel.md(partly, see above). Files excluded by rule: none.To get this to a good state
Nothing is required.
Optional:
#include <stdexcept>from Tsd.cpp if nothing else in the file needs it.scePthreadKeyCreate(nullptr, ...)assertion, or move the POSIX assertion so it checks something this change alters.Pull request closed