feat(libSceNpCommon): implement the npid platform-tag exports #12829

Merged
hypermoist merged 6 commits from upstream-pr/12829 into main 2026-11-08 16:17:19 +00:00
hypermoist commented 2026-10-29 11:48:45 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by hypermoist on 2026-10-29T11:48:45Z.


What

Implements five npid platform-tag exports in place of their NotImplemented stubs: sceNpSetPlatformType, sceNpIntGetPlatformType, sceNpIntSetPlatformType, sceNpUtilCanonicalizeNpIdForPs4 and sceNpUtilCanonicalizeNpIdForPsp2. The signatures and behaviour are read from libSceNpCommon.sprx of firmware 13.60 (disassembly, not measured on a console).

This is stacked on #12825. Only the last commit (feat(libSceNpCommon): implement the npid platform-tag exports) is new. Both PRs edit the same debt-file entry, so this one is based on #12825 to avoid a conflict.

The platform tag is the 4 bytes at opt[4..7] of an NpIdFull. Types 0 to 3 are: no tag (opt[4] == 0), ps3\0, psp2 and ps4\0. The existing sceNpGetPlatformType now shares that lookup, with unchanged behaviour.

  • sceNpSetPlatformType(NpIdFull*, uint32_t type): writes the tag for types 0 to 3. Returns 0x80550003 for a null npid and 0x80550004 for any other type.
  • sceNpIntGetPlatformType(const NpIdFull*): like sceNpGetPlatformType, but also reports the comp tag as type 4. sceNpGetPlatformType still returns 0x80550004 for comp, as the module does.
  • sceNpIntSetPlatformType(NpIdFull*, uint32_t type): writes comp for type 4 and otherwise behaves like sceNpSetPlatformType.
  • sceNpUtilCanonicalizeNpIdForPs4 / ForPsp2(NpIdFull*, int32_t replace):
    • 0x80550601 for a null npid.
    • A non-zero replace first clears the tag.
    • An npid whose reserved[0] is not 1 then returns 0x80550605, which has no name in any source, keeping the cleared tag.
    • Otherwise an empty tag is set to ps4\0 or psp2.

The debt file replaces the five "signature unknown" entries with one entry that states the source and the quirks. The entry that said these functions throw now lists only sceNpGetNavSdkVersion.

Tested

Linux (CachyOS, GCC, Release): ctest --test-dir build -R 'np_common|public_headers' --output-on-failure, 70/70 passed. GuestNpCommon.cpp covers:

  • each type through Get, IntGet, Set and IntSet, including comp and the out-of-range types;
  • canonicalize with and without replace, and with reserved[0] not 1;
  • the null arguments.

Comparison against the firmware code: I relinked the 13.60 module with this repo's relinker and ran all six functions (including the existing sceNpGetPlatformType) under unicorn (x86-64 emulation on a PC, not a console).

  • Corpus: 9,012 cases. For each function: the null npid, and 1,500 random npids that combine random online ids, random opt bytes, ten tags (the five real ones and near misses such as ps5\0, \0ps4 and comq), and reserved[0] drawn from 0, 1, 2 and 255. Arguments were drawn from 0 to 6, 0x100, 0x80000000, 0xFFFFFFFF and random values.
  • What was recorded: the result and all 36 bytes of the npid plus 4 bytes past it (prefilled 0xCC).
  • Result: replaying the same cases through this implementation gives 0 mismatches. Corrupting 15 expectations gives 15 mismatches.

Windows not built. Not run on a console.

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: #12825
  • Fixes: none
  • Unblocks: none
  • GPUs tested: n/a
  • AI-assisted: yes

Assisted With AI: Yes. All tests were run locally on computer hardware (AMD Ryzen 5 5600G, 32 GB RAM, NVIDIA GeForce RTX 3060, CachyOS Linux 7.3, GCC 16.2), not on an actual console.

🤖 Generated with Claude Code

<!-- greyfinch-sync:boykopovar/AnyPS5:issue:5067431763 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/12829). Originally posted by [hypermoist](https://github.com/hypermoist) on 2026-10-29T11:48:45Z. --- ### What Implements five npid platform-tag exports in place of their `NotImplemented` stubs: `sceNpSetPlatformType`, `sceNpIntGetPlatformType`, `sceNpIntSetPlatformType`, `sceNpUtilCanonicalizeNpIdForPs4` and `sceNpUtilCanonicalizeNpIdForPsp2`. The signatures and behaviour are read from `libSceNpCommon.sprx` of firmware 13.60 (disassembly, not measured on a console). **This is stacked on #12825.** Only the last commit (`feat(libSceNpCommon): implement the npid platform-tag exports`) is new. Both PRs edit the same debt-file entry, so this one is based on #12825 to avoid a conflict. The platform tag is the 4 bytes at `opt[4..7]` of an `NpIdFull`. Types 0 to 3 are: no tag (`opt[4] == 0`), `ps3\0`, `psp2` and `ps4\0`. The existing `sceNpGetPlatformType` now shares that lookup, with unchanged behaviour. - **`sceNpSetPlatformType(NpIdFull*, uint32_t type)`:** writes the tag for types 0 to 3. Returns `0x80550003` for a null npid and `0x80550004` for any other type. - **`sceNpIntGetPlatformType(const NpIdFull*)`:** like `sceNpGetPlatformType`, but also reports the `comp` tag as type 4. `sceNpGetPlatformType` still returns `0x80550004` for `comp`, as the module does. - **`sceNpIntSetPlatformType(NpIdFull*, uint32_t type)`:** writes `comp` for type 4 and otherwise behaves like `sceNpSetPlatformType`. - **`sceNpUtilCanonicalizeNpIdForPs4` / `ForPsp2(NpIdFull*, int32_t replace)`:** - `0x80550601` for a null npid. - A non-zero `replace` first clears the tag. - An npid whose `reserved[0]` is not 1 then returns `0x80550605`, which has no name in any source, keeping the cleared tag. - Otherwise an empty tag is set to `ps4\0` or `psp2`. The debt file replaces the five "signature unknown" entries with one entry that states the source and the quirks. The entry that said these functions throw now lists only `sceNpGetNavSdkVersion`. ### Tested Linux (CachyOS, GCC, Release): `ctest --test-dir build -R 'np_common|public_headers' --output-on-failure`, 70/70 passed. `GuestNpCommon.cpp` covers: - each type through Get, IntGet, Set and IntSet, including `comp` and the out-of-range types; - canonicalize with and without `replace`, and with `reserved[0]` not 1; - the null arguments. **Comparison against the firmware code:** I relinked the 13.60 module with this repo's relinker and ran all six functions (including the existing `sceNpGetPlatformType`) under unicorn (x86-64 emulation on a PC, not a console). - **Corpus:** 9,012 cases. For each function: the null npid, and 1,500 random npids that combine random online ids, random `opt` bytes, ten tags (the five real ones and near misses such as `ps5\0`, `\0ps4` and `comq`), and `reserved[0]` drawn from 0, 1, 2 and 255. Arguments were drawn from 0 to 6, `0x100`, `0x80000000`, `0xFFFFFFFF` and random values. - **What was recorded:** the result and all 36 bytes of the npid plus 4 bytes past it (prefilled 0xCC). - **Result:** replaying the same cases through this implementation gives **0 mismatches**. Corrupting 15 expectations gives 15 mismatches. Windows not built. Not run on a console. ### 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: #12825 - [x] Fixes: none - [x] Unblocks: none - [x] GPUs tested: n/a - [x] AI-assisted: yes Assisted With AI: Yes. All tests were run locally on computer hardware (AMD Ryzen 5 5600G, 32 GB RAM, NVIDIA GeForce RTX 3060, CachyOS Linux 7.3, GCC 16.2), not on an actual console. 🤖 Generated with [Claude Code](https://claude.com/claude-code)
rooklz commented 2026-10-29 12:01:07 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by rooklz on 2026-10-29T12:01:07Z.

Review: COMMENTED


I reviewed only the new commit, 846ca893ac (git diff 9b48ab5214 846ca893ac). My setup was macOS arm64 with Apple clang, ASan and UBSan, and -fno-sanitize-recover=all. I built a standalone harness from the six platform-tag functions, copied verbatim from Export.cpp, plus the new testIds rows from GuestNpCommon.cpp. I didn't run the full CMake lane.

Result: the new rows pass with no sanitizer reports. check_conventions (base main), git diff --check and git merge-tree against main are all clean. pr_overlap probed 1390 PRs. It reports only #12830, which is stacked on this commit and declares Depends on. The removed PendingExports.cpp stubs line up one-to-one with the new definitions, and the Api.hpp signatures match.

Mutation check: I applied 17 single-line mutants to platformTypeOf, canonicalizeNpId, setPlatformTag and the four new exports.

  • Killed (6): dropping the opt[4] == 0 shortcut, >= changed to > in the setter, filling the tag unconditionally, tagging a refused npid before the reserved[0] check, IntSet writing comp for every type ≥ 4, and the wrong null error in IntGet.
  • Equivalent (1): checking comp after platformTypeOf instead of before. comp never matches a PLATFORM_TAGS entry, and its opt[4] is not 0, so the result is the same.
  • Survived (10, non-equivalent): each of these changes the result for some input and still passes the test:
    1. platformTypeOf checks the whole tag for 0 instead of opt[4], so 00 70 73 34 would be invalid instead of type 0.
    2. The canonicalize fill checks the whole tag instead of opt[4].
    3. IntGet matches comp on its first byte only.
    4. replace != 0 changed to replace == 1.
    5. replace != 0 changed to (replace & 0xff) != 0.
    6. replace != 0 changed to replace > 0.
    7. reserved[0] != 1 changed to reserved[0] == 0.
    8. replace clears all of opt instead of opt[4..7].
    9. setPlatformTag also zeroes opt[0..3].
    10. A refused type in sceNpSetPlatformType clears the tag.

Your unicorn differential probably already pins these, since its corpus has the comq-style near misses, reserved[0] drawn from 0/1/2/255 and a full 40-byte compare. The in-repo test only covers reserved[0] values 0 and 1, replace values 0 and 1, and checks the tag rather than the whole npid. The rows below kill all 10. They go at the end of the new block in testIds, after the null canonicalize row, and reuse tags, UTIL_INVALID_NP_ID and npIdWithTag. Please confirm the expected values against your differential before taking them; I derived them from your implementation, not from the module.

    NpIdFull loose = npIdWithTag("heron-4", 0x34737000);
    ok &= expect(sceNpGetPlatformType(&loose) == 0 && sceNpIntGetPlatformType(&loose) == 0, "a tag with opt[4] zero is not platform 0");
    const NpIdFull nearCompanion = npIdWithTag("heron-4", 0x716D6F63);
    ok &= expect(sceNpIntGetPlatformType(&nearCompanion) == INVALID_PLATFORM_TYPE, "comq was taken for comp");
    loose.reserved[0] = 1;
    ok &= expect(sceNpUtilCanonicalizeNpIdForPs4(&loose, 0) == 0 && std::memcmp(loose.opt + 4, &tags[3], 4) == 0, "a tag with opt[4] zero was not replaced");
    const std::int32_t replaceValues[] = {2, 0x100, -1};
    for (const std::int32_t replace : replaceValues) {
        NpIdFull replaced = npIdWithTag("heron-4", 0x00337370);
        replaced.reserved[0] = 1;
        replaced.opt[0] = 0x5A;
        ok &= expect(sceNpUtilCanonicalizeNpIdForPsp2(&replaced, replace) == 0 && sceNpGetPlatformType(&replaced) == 2 && replaced.opt[0] == 0x5A,
            "a non-zero replace did not clear only the tag");
    }
    NpIdFull refused = npIdWithTag("heron-4", 0);
    refused.reserved[0] = 2;
    ok &= expect(sceNpUtilCanonicalizeNpIdForPs4(&refused, 0) == UTIL_INVALID_NP_ID && sceNpGetPlatformType(&refused) == 0, "reserved[0] 2 was accepted");
    NpIdFull kept = npIdWithTag("heron-4", 0x00337370);
    std::memset(kept.opt, 0xA5, 4);
    kept.reserved[0] = 7;
    const NpIdFull before = kept;
    ok &= expect(sceNpSetPlatformType(&kept, 4) == INVALID_PLATFORM_TYPE && std::memcmp(&kept, &before, sizeof(kept)) == 0, "a refused type changed the NpId");
    ok &= expect(sceNpSetPlatformType(&kept, 3) == 0 && std::memcmp(kept.opt, before.opt, 4) == 0 && std::memcmp(kept.reserved, before.reserved, 8) == 0 && std::memcmp(&kept.handle, &before.handle, sizeof(kept.handle)) == 0,
        "setting a platform type changed bytes outside the tag");

With these rows the harness passes, and the 10 survivors are killed. The equivalent mutant still survives, as expected.

Nit (same as on #12825): the line "Assisted With AI: Yes But all test done locally on actual hardware" conflicts with "Not run on a console" in Tested. It would help to say which hardware was meant.

<!-- greyfinch-sync:boykopovar/AnyPS5:review:5697320016 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/12829#pullrequestreview-5697320016). Originally posted by [rooklz](https://github.com/rooklz) on 2026-10-29T12:01:07Z. **Review:** COMMENTED --- I reviewed only the new commit, 846ca893ac (`git diff 9b48ab5214 846ca893ac`). My setup was macOS arm64 with Apple clang, ASan and UBSan, and `-fno-sanitize-recover=all`. I built a standalone harness from the six platform-tag functions, copied verbatim from `Export.cpp`, plus the new `testIds` rows from `GuestNpCommon.cpp`. I didn't run the full CMake lane. **Result:** the new rows pass with no sanitizer reports. `check_conventions` (base main), `git diff --check` and `git merge-tree` against main are all clean. `pr_overlap` probed 1390 PRs. It reports only #12830, which is stacked on this commit and declares `Depends on`. The removed `PendingExports.cpp` stubs line up one-to-one with the new definitions, and the `Api.hpp` signatures match. **Mutation check:** I applied 17 single-line mutants to `platformTypeOf`, `canonicalizeNpId`, `setPlatformTag` and the four new exports. - **Killed (6):** dropping the `opt[4] == 0` shortcut, `>=` changed to `>` in the setter, filling the tag unconditionally, tagging a refused npid before the `reserved[0]` check, `IntSet` writing `comp` for every type ≥ 4, and the wrong null error in `IntGet`. - **Equivalent (1):** checking `comp` after `platformTypeOf` instead of before. `comp` never matches a `PLATFORM_TAGS` entry, and its `opt[4]` is not 0, so the result is the same. - **Survived (10, non-equivalent):** each of these changes the result for some input and still passes the test: 1. `platformTypeOf` checks the whole tag for 0 instead of `opt[4]`, so `00 70 73 34` would be invalid instead of type 0. 2. The canonicalize fill checks the whole tag instead of `opt[4]`. 3. `IntGet` matches `comp` on its first byte only. 4. `replace != 0` changed to `replace == 1`. 5. `replace != 0` changed to `(replace & 0xff) != 0`. 6. `replace != 0` changed to `replace > 0`. 7. `reserved[0] != 1` changed to `reserved[0] == 0`. 8. `replace` clears all of `opt` instead of `opt[4..7]`. 9. `setPlatformTag` also zeroes `opt[0..3]`. 10. A refused type in `sceNpSetPlatformType` clears the tag. Your unicorn differential probably already pins these, since its corpus has the `comq`-style near misses, `reserved[0]` drawn from 0/1/2/255 and a full 40-byte compare. The in-repo test only covers `reserved[0]` values 0 and 1, `replace` values 0 and 1, and checks the tag rather than the whole npid. The rows below kill all 10. They go at the end of the new block in `testIds`, after the null canonicalize row, and reuse `tags`, `UTIL_INVALID_NP_ID` and `npIdWithTag`. Please confirm the expected values against your differential before taking them; I derived them from your implementation, not from the module. ```cpp NpIdFull loose = npIdWithTag("heron-4", 0x34737000); ok &= expect(sceNpGetPlatformType(&loose) == 0 && sceNpIntGetPlatformType(&loose) == 0, "a tag with opt[4] zero is not platform 0"); const NpIdFull nearCompanion = npIdWithTag("heron-4", 0x716D6F63); ok &= expect(sceNpIntGetPlatformType(&nearCompanion) == INVALID_PLATFORM_TYPE, "comq was taken for comp"); loose.reserved[0] = 1; ok &= expect(sceNpUtilCanonicalizeNpIdForPs4(&loose, 0) == 0 && std::memcmp(loose.opt + 4, &tags[3], 4) == 0, "a tag with opt[4] zero was not replaced"); const std::int32_t replaceValues[] = {2, 0x100, -1}; for (const std::int32_t replace : replaceValues) { NpIdFull replaced = npIdWithTag("heron-4", 0x00337370); replaced.reserved[0] = 1; replaced.opt[0] = 0x5A; ok &= expect(sceNpUtilCanonicalizeNpIdForPsp2(&replaced, replace) == 0 && sceNpGetPlatformType(&replaced) == 2 && replaced.opt[0] == 0x5A, "a non-zero replace did not clear only the tag"); } NpIdFull refused = npIdWithTag("heron-4", 0); refused.reserved[0] = 2; ok &= expect(sceNpUtilCanonicalizeNpIdForPs4(&refused, 0) == UTIL_INVALID_NP_ID && sceNpGetPlatformType(&refused) == 0, "reserved[0] 2 was accepted"); NpIdFull kept = npIdWithTag("heron-4", 0x00337370); std::memset(kept.opt, 0xA5, 4); kept.reserved[0] = 7; const NpIdFull before = kept; ok &= expect(sceNpSetPlatformType(&kept, 4) == INVALID_PLATFORM_TYPE && std::memcmp(&kept, &before, sizeof(kept)) == 0, "a refused type changed the NpId"); ok &= expect(sceNpSetPlatformType(&kept, 3) == 0 && std::memcmp(kept.opt, before.opt, 4) == 0 && std::memcmp(kept.reserved, before.reserved, 8) == 0 && std::memcmp(&kept.handle, &before.handle, sizeof(kept.handle)) == 0, "setting a platform type changed bytes outside the tag"); ``` With these rows the harness passes, and the 10 survivors are killed. The equivalent mutant still survives, as expected. **Nit (same as on #12825):** the line "Assisted With AI: Yes But all test done locally on actual hardware" conflicts with "Not run on a console" in Tested. It would help to say which hardware was meant.
rooklz commented 2026-10-29 12:38:52 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by rooklz on 2026-10-29T12:38:52Z.

Review: APPROVED


I re-reviewed the PR at 2f6f0e13a9. Since the commit I reviewed (846ca893ac), the only changes are tests: the merge of #12825's test commit (GuestNpCommonRuntime.cpp) and the new rows in GuestNpCommon.cpp. Export.cpp, Api.hpp and the debt file are the same as before.

Setup: the same standalone harness as last time. The six platform-tag functions are copied verbatim from Export.cpp at this head, along with the whole platform part of testIds, including the new rows. I built it with Apple clang on macOS arm64 using ASan, UBSan and -fno-sanitize-recover=all.

Results:

  • The harness passes with no sanitizer reports.
  • I re-applied all 10 mutants that survived last time. All 10 are now killed: whole-tag zero checks ×2, comp first byte, replace == 1 / & 0xff / > 0, reserved[0] == 0, replace clearing all of opt, the setter zeroing opt[0..3], and a refused type clearing the tag.
  • The equivalent mutant (checking comp after platformTypeOf) still survives, as expected.
  • check_conventions (base main), git diff --check and git merge-tree against main 5454cd2e45 are all clean.

Thanks for checking each row against 13.60 under unicorn. The AI line is resolved too.

Approving. The order with #12825 is unchanged: this lands after it.

<!-- greyfinch-sync:boykopovar/AnyPS5:review:5697805997 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/12829#pullrequestreview-5697805997). Originally posted by [rooklz](https://github.com/rooklz) on 2026-10-29T12:38:52Z. **Review:** APPROVED --- I re-reviewed the PR at `2f6f0e13a9`. Since the commit I reviewed (846ca893ac), the only changes are tests: the merge of #12825's test commit (`GuestNpCommonRuntime.cpp`) and the new rows in `GuestNpCommon.cpp`. `Export.cpp`, `Api.hpp` and the debt file are the same as before. **Setup:** the same standalone harness as last time. The six platform-tag functions are copied verbatim from `Export.cpp` at this head, along with the whole platform part of `testIds`, including the new rows. I built it with Apple clang on macOS arm64 using ASan, UBSan and `-fno-sanitize-recover=all`. **Results:** - The harness passes with no sanitizer reports. - I re-applied all 10 mutants that survived last time. All 10 are now killed: whole-tag zero checks ×2, `comp` first byte, `replace == 1` / `& 0xff` / `> 0`, `reserved[0] == 0`, replace clearing all of `opt`, the setter zeroing `opt[0..3]`, and a refused type clearing the tag. - The equivalent mutant (checking `comp` after `platformTypeOf`) still survives, as expected. - `check_conventions` (base main), `git diff --check` and `git merge-tree` against main 5454cd2e45 are all clean. Thanks for checking each row against 13.60 under unicorn. The AI line is resolved too. Approving. The order with #12825 is unchanged: this lands after it.
CnRJay commented 2026-11-01 19:54:06 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by CnRJay on 2026-11-01T19:54:06Z.

Review: COMMENTED


Withdrawn. This review applied a title-ID/log requirement that is not in CONTRIBUTING (Unblocks: none is allowed), and it contained no code review.

<!-- greyfinch-sync:boykopovar/AnyPS5:review:5729937294 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/12829#pullrequestreview-5729937294). Originally posted by [CnRJay](https://github.com/CnRJay) on 2026-11-01T19:54:06Z. **Review:** COMMENTED --- Withdrawn. This review applied a title-ID/log requirement that is not in CONTRIBUTING (`Unblocks: none` is allowed), and it contained no code review.
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!12829
No description provided.