fix(libkernel): return SCE_KERNEL_ERROR_EINVAL for null key in scePthreadKeyCreate #14128

Closed
slopgobblercobbler wants to merge 1 commit from upstream-pr/14128 into main
slopgobblercobbler commented 2026-10-31 19:57:15 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by slopgobblercobbler on 2026-10-31T19:57:15Z.


What

  • In core/libs/prx/libkernel/Pthread/src/Tsd.cpp, return SCE_KERNEL_ERROR_EINVAL (0x80020016) instead of throwing host std::runtime_error when scePthreadKeyCreate is called with a null key pointer.
  • Added parameter boundary test cases in core/libs/tests/GuestPthreadKey.cpp verifying scePthreadKeyCreate(nullptr, ...) returns SCE_KERNEL_ERROR_EINVAL, pthread_key_create_nid_postfix(nullptr, ...) returns POSIX_EINVAL, and deleting invalid / already-deleted keys returns SCE_KERNEL_ERROR_EINVAL / POSIX_EINVAL.
  • Added technical debt entry for scePthreadKeyCreate in docs/dev/debt/libkernel.md.

Tested

  • Windows 11, compilation verified with python -m ziglang c++ -std=c++20.
  • Conventions checked via python tools/check_conventions.py --base upstream/main --head HEAD (0 findings).

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
<!-- greyfinch-sync:boykopovar/AnyPS5:issue:5101037419 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/14128). Originally posted by [slopgobblercobbler](https://github.com/slopgobblercobbler) on 2026-10-31T19:57:15Z. --- ### What - In `core/libs/prx/libkernel/Pthread/src/Tsd.cpp`, return `SCE_KERNEL_ERROR_EINVAL` (`0x80020016`) instead of throwing host `std::runtime_error` when `scePthreadKeyCreate` is called with a null `key` pointer. - Added parameter boundary test cases in `core/libs/tests/GuestPthreadKey.cpp` verifying `scePthreadKeyCreate(nullptr, ...)` returns `SCE_KERNEL_ERROR_EINVAL`, `pthread_key_create_nid_postfix(nullptr, ...)` returns `POSIX_EINVAL`, and deleting invalid / already-deleted keys returns `SCE_KERNEL_ERROR_EINVAL` / `POSIX_EINVAL`. - Added technical debt entry for `scePthreadKeyCreate` in `docs/dev/debt/libkernel.md`. ### Tested - Windows 11, compilation verified with `python -m ziglang c++ -std=c++20`. - Conventions checked via `python tools/check_conventions.py --base upstream/main --head HEAD` (0 findings). ### 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
MarcZX10 commented 2026-10-31 20:06:21 +00:00 (Migrated from github.com)

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 c32b3c83285716e5f591a09cb9d7b163a4984c1a against base 500d37a747c2b958e8696aa16213a0ee78d47505; the fresh merge preview against current main (0836dfdf4fecb1e0326100c490476e15d3a74da5) was clean. Environment: Linux x86_64, Python 3.11.2, GCC 12.2.0. No build or C++ test was run.

python3 tools/pr_precheck.py --repo boykopovar/AnyPS5 --pr 14128

Results

Check Result
git diff --check Passed
Conventions and PR template Failed: four required checklist items are unchecked
Dependency and merge preview Passed; no declared dependency and clean against refreshed main
Hosted eligibility, intake, portability, report Passed
Hosted Windows In progress at last refresh
Hosted Linux and specialized jobs Skipped
Local build and GuestPthreadKey runtime test Not run; they require a build
ABI and test-quality helper checks Could not run: the isolated checkout does not contain these local-only helper scripts
Unedited conventions-check output
(pull request): error: [pr-template] Fill in the pull request template: unchecked: Depends on: none
(pull request): error: [pr-template] Fill in the pull request template: unchecked: Fixes: none
(pull request): error: [pr-template] Fill in the pull request template: unchecked: Unblocks: none
(pull request): error: [pr-template] Fill in the pull request template: unchecked: GPUs tested: n/a
4 findings, 4 errors; GitHub shows at most 10 error annotations, the job summary lists all

Findings

Blocking

  1. scePthreadKeyCreate(nullptr, ...) now returns SCE_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.
  2. The PR template leaves Depends on: none, Fixes: none, Unblocks: none, and GPUs tested: n/a unchecked. 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.

<!-- greyfinch-sync:boykopovar/AnyPS5:review:5724726699 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/14128#pullrequestreview-5724726699). Originally posted by [MarcZX10](https://github.com/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 `c32b3c83285716e5f591a09cb9d7b163a4984c1a` against base `500d37a747c2b958e8696aa16213a0ee78d47505`; the fresh merge preview against current `main` (`0836dfdf4fecb1e0326100c490476e15d3a74da5`) was clean. Environment: Linux x86_64, Python 3.11.2, GCC 12.2.0. No build or C++ test was run. ```sh python3 tools/pr_precheck.py --repo boykopovar/AnyPS5 --pr 14128 ``` ## Results | Check | Result | |---|---| | `git diff --check` | Passed | | Conventions and PR template | Failed: four required checklist items are unchecked | | Dependency and merge preview | Passed; no declared dependency and clean against refreshed `main` | | Hosted eligibility, intake, portability, report | Passed | | Hosted Windows | In progress at last refresh | | Hosted Linux and specialized jobs | Skipped | | Local build and `GuestPthreadKey` runtime test | Not run; they require a build | | ABI and test-quality helper checks | Could not run: the isolated checkout does not contain these local-only helper scripts | <details><summary>Unedited conventions-check output</summary> ```text (pull request): error: [pr-template] Fill in the pull request template: unchecked: Depends on: none (pull request): error: [pr-template] Fill in the pull request template: unchecked: Fixes: none (pull request): error: [pr-template] Fill in the pull request template: unchecked: Unblocks: none (pull request): error: [pr-template] Fill in the pull request template: unchecked: GPUs tested: n/a 4 findings, 4 errors; GitHub shows at most 10 error annotations, the job summary lists all ``` </details> ## Findings ### Blocking 1. `scePthreadKeyCreate(nullptr, ...)` now returns `SCE_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. 2. The PR template leaves `Depends on: none`, `Fixes: none`, `Unblocks: none`, and `GPUs tested: n/a` unchecked. Tick these required entries so the conventions check passes. ### Non-blocking None found in this source-level pass. ## Sources - [Null-key implementation at the reviewed head](https://github.com/boykopovar/AnyPS5/blob/c32b3c83285716e5f591a09cb9d7b163a4984c1a/core/libs/prx/libkernel/Pthread/src/Tsd.cpp) - [Debt entry documenting unmeasured console behavior at the reviewed head](https://github.com/boykopovar/AnyPS5/blob/c32b3c83285716e5f591a09cb9d7b163a4984c1a/docs/dev/debt/libkernel.md) - [Repository agent guidance at the reviewed base](https://github.com/boykopovar/AnyPS5/blob/500d37a747c2b958e8696aa16213a0ee78d47505/AGENTS.md) ## 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.
adriadam10 commented 2026-11-06 15:29:01 +00:00 (Migrated from github.com)

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: returning SCE_KERNEL_ERROR_EINVAL for a null key replaces 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 + 1 and 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 the Tsd.cpp change and the nullptr test lines, or show where the console returns EINVAL (a reference or a hardware measurement).

  • core/libs/tests/GuestPthreadKey.cpp:100-102: the KeyDelete(9999) and pthread_key_delete_nid_postfix checks already pass on main, 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.md line goes too.

<!-- greyfinch-sync:boykopovar/AnyPS5:review:5802459491 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/14128#pullrequestreview-5802459491). Originally posted by [adriadam10](https://github.com/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`: returning `SCE_KERNEL_ERROR_EINVAL` for a null `key` replaces 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 + 1` and 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 the `Tsd.cpp` change and the `nullptr` test lines, or show where the console returns EINVAL (a reference or a hardware measurement). - `core/libs/tests/GuestPthreadKey.cpp:100-102`: the `KeyDelete(9999)` and `pthread_key_delete_nid_postfix` checks already pass on `main`, 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.md` line goes too.
MarcZX10 commented 2026-11-14 05:34:55 +00:00 (Migrated from github.com)

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_EINVAL for a null key, and the POSIX wrapper maps that result to POSIX_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

Check Result Note
Source review passed All changed files read
Build and conventions not run Reported by author only

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.

<!-- greyfinch-sync:boykopovar/AnyPS5:review:5901935365 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/14128#pullrequestreview-5901935365). Originally posted by [MarcZX10](https://github.com/MarcZX10) on 2026-11-14T05:34:55Z. **Review:** COMMENTED --- # Reviewed — no blocking findings The changed implementation returns `SCE_KERNEL_ERROR_EINVAL` for a null key, and the POSIX wrapper maps that result to `POSIX_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 | Check | Result | Note | |---|---|---| | Source review | passed | All changed files read | | Build and conventions | not run | Reported by author only | ## 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.
MarcZX10 commented 2026-11-17 00:04:58 +00:00 (Migrated from github.com)

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. Read review/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, and core/libs/tests/GuestPthreadKey.cpp. review/files.json was not available. All three changed files were included in the manifest; the changed documentation file was not read.

Results

Check Result Note
Code review passed Inspected changed implementation and tests
Tests not run No test commands run
Documentation review not run Changed debt entry not read

Findings

Blocking

None.

Non-blocking

None.

Not verified

The docs/dev/debt/libkernel.md change 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.

<!-- greyfinch-sync:boykopovar/AnyPS5:review:5930210489 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/14128#pullrequestreview-5930210489). Originally posted by [MarcZX10](https://github.com/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. Read `review/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`, and `core/libs/tests/GuestPthreadKey.cpp`. `review/files.json` was not available. All three changed files were included in the manifest; the changed documentation file was not read. ## Results | Check | Result | Note | |---|---|---| | Code review | passed | Inspected changed implementation and tests | | Tests | not run | No test commands run | | Documentation review | not run | Changed debt entry not read | ## Findings ### Blocking None. ### Non-blocking None. ## Not verified The `docs/dev/debt/libkernel.md` change 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.
MarcZX10 commented 2026-11-17 22:32:05 +00:00 (Migrated from github.com)

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

  • Head SHA: 9bdaf33e8b (base: main)
  • No build or test run in this review. Read-only checks through the repository reader:
    • repo_read.py search KeySlot and repo_read.py search pthread_key_delete_nid_postfix
    • repo_read.py cat on the changed ranges of Tsd.cpp, GuestPthreadKey.cpp, libkernel.md, and Posix/Tsd.cpp

Results

Check Result Note
Build and tests not run Author reports a zig compile on Windows 11 only
Null key path, code read passed Returns SCE_KERNEL_ERROR_EINVAL before any write
Delete bounds, code read passed KeySlot rejects keys outside 1 to 512, so 9999 is safe
POSIX null-key path not applicable Returns before scePthreadKeyCreate; see Findings

Findings

Blocking

None.

Non-blocking

  • core/libs/prx/libkernel/Pthread/src/Tsd.cpp:91: the only throw in the file was removed. A search found no remaining throw, so #include <stdexcept> (line 11) may now be unused. Check for other std::runtime_error uses before removing it.
  • core/libs/tests/GuestPthreadKey.cpp:82: pthread_key_create_nid_postfix(nullptr, nullptr) returns GUEST_EINVAL at core/libs/prx/libkernel/Pthread/Posix/Tsd.cpp:19 before it reaches scePthreadKeyCreate. That assertion passes without this change. The direct call on line 81 is the one that exercises the fix.

Not verified

  • Build and runtime tests: not run here. The author's zig compile on Windows 11 is author-reported, and no test run is reported.
  • POSIX_EINVAL equals GUEST_EINVAL: not checked.
  • Console behaviour for a null key pointer: unmeasured, as the debt entry states.
  • 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:

  • Drop #include <stdexcept> from Tsd.cpp if nothing else in the file needs it.
  • Add a direct scePthreadKeyCreate(nullptr, ...) assertion, or move the POSIX assertion so it checks something this change alters.
<!-- greyfinch-sync:boykopovar/AnyPS5:review:5947738668 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/14128#pullrequestreview-5947738668). Originally posted by [MarcZX10](https://github.com/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 - Head SHA: 9bdaf33e8b248286ccc46edcd1f2930073660d5e (base: main) - No build or test run in this review. Read-only checks through the repository reader: - `repo_read.py search KeySlot` and `repo_read.py search pthread_key_delete_nid_postfix` - `repo_read.py cat` on the changed ranges of Tsd.cpp, GuestPthreadKey.cpp, libkernel.md, and Posix/Tsd.cpp ## Results | Check | Result | Note | |---|---|---| | Build and tests | not run | Author reports a zig compile on Windows 11 only | | Null key path, code read | passed | Returns `SCE_KERNEL_ERROR_EINVAL` before any write | | Delete bounds, code read | passed | `KeySlot` rejects keys outside 1 to 512, so 9999 is safe | | POSIX null-key path | not applicable | Returns before `scePthreadKeyCreate`; see Findings | ## Findings ### Blocking None. ### Non-blocking - `core/libs/prx/libkernel/Pthread/src/Tsd.cpp:91`: the only `throw` in the file was removed. A search found no remaining `throw`, so `#include <stdexcept>` (line 11) may now be unused. Check for other `std::runtime_error` uses before removing it. - `core/libs/tests/GuestPthreadKey.cpp:82`: `pthread_key_create_nid_postfix(nullptr, nullptr)` returns `GUEST_EINVAL` at `core/libs/prx/libkernel/Pthread/Posix/Tsd.cpp:19` before it reaches `scePthreadKeyCreate`. That assertion passes without this change. The direct call on line 81 is the one that exercises the fix. ## Not verified - Build and runtime tests: not run here. The author's zig compile on Windows 11 is author-reported, and no test run is reported. - `POSIX_EINVAL` equals `GUEST_EINVAL`: not checked. - Console behaviour for a null key pointer: unmeasured, as the debt entry states. - `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: - Drop `#include <stdexcept>` from Tsd.cpp if nothing else in the file needs it. - Add a direct `scePthreadKeyCreate(nullptr, ...)` assertion, or move the POSIX assertion so it checks something this change alters.

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