fix(libkernel): preserve C linkage for the host instance lock release #17140

Closed
PrivacyOnion wants to merge 1 commit from upstream-pr/17140 into main
PrivacyOnion commented 2026-11-08 11:04:55 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by PrivacyOnion on 2026-11-08T11:04:55Z.


What

Closed as obsolete after #17150 was merged in eb41c5465d: main removed the title instance lock, InstanceLockHost.hpp, and the SystemService release call. There is no remaining helper declaration/import to repair. On main eb41c5465d, a fresh GCC 15.2.0 build and patched_libraries run also passes: 407 patched libraries loaded, 0 failed. The original reproduction and validation below are preserved for reference.

Give ReleaseHostInstanceLock_nid_no_patch C linkage in its shared declaration. The definition and SystemService caller inherit it from this header.

After #17076, MinGW still emits _Z36ReleaseHostInstanceLock_nid_no_patchv. Its trailing v prevents the NID patcher from recognizing the _nid_no_patch suffix, so the patched kernel export no longer matches the SystemService import. Windows reports error 127 loading SystemService and its dependent libraries. C linkage preserves the intended host helper name through patching.

This changes linkage only. Lock acquisition, release and guest export behavior are unchanged. No performance gain is claimed.

Tested

Windows 11 10.0.26200, MinGW GCC, Release build. Reproduced with the unmodified header from main 49f36536321fa3941deb9408d556597dab1e4e28, rebuilt the patched kernel and SystemService, then restored this one-line change and rebuilt them and the instance-lock tests. The branch is rebased onto main 105c9e4d91; the intervening merges touch AES unwrap and relative DPP shader instructions, not the linkage or instance-lock code tested here.

  • Main: existing patched_libraries test fails: 392 patched libraries loaded, 15 failed; all 15 failures report LoadLibraryEx failed with error 127, including SystemService and UserService.
  • With the fix: 407 patched libraries loaded, 0 failed.
  • ctest --test-dir <build> -R "^(patched_libraries|instance_lock.*)$" -V: all 7 tests pass, none skipped. Includes lock behavior, host backend, held-lock startup, unset/off configuration and startup without a title.
  • python tools/check_conventions.py --base upstream/main: passes. The explicitly requested --base origin/main was also run; the fork main is stale and reports 18 errors in pre-existing upstream commits, unrelated to this one-line diff.
  • python tools/pr_overlap.py --branch codex/fix-lock-release-linkage --repo boykopovar/AnyPS5: no overlap with the 1,793 other open PRs examined.

Revalidated after a fresh full runtime and relinker build with the supported WinLibs GCC 15.2.0 UCRT/POSIX r7 toolchain on main 105c9e4d91 plus this one-line change: the same seven CTest tests pass, with 407 patched libraries loaded, 0 failed.

No export-only test was added; the existing loader and behavioral tests cover the regression.

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:5210781590 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/17140). Originally posted by [PrivacyOnion](https://github.com/PrivacyOnion) on 2026-11-08T11:04:55Z. --- ### What Closed as obsolete after #17150 was merged in `eb41c5465d`: main removed the title instance lock, `InstanceLockHost.hpp`, and the SystemService release call. There is no remaining helper declaration/import to repair. On main eb41c5465d, a fresh GCC 15.2.0 build and patched_libraries run also passes: 407 patched libraries loaded, 0 failed. The original reproduction and validation below are preserved for reference. Give `ReleaseHostInstanceLock_nid_no_patch` C linkage in its shared declaration. The definition and SystemService caller inherit it from this header. After #17076, MinGW still emits `_Z36ReleaseHostInstanceLock_nid_no_patchv`. Its trailing `v` prevents the NID patcher from recognizing the `_nid_no_patch` suffix, so the patched kernel export no longer matches the SystemService import. Windows reports error 127 loading SystemService and its dependent libraries. C linkage preserves the intended host helper name through patching. This changes linkage only. Lock acquisition, release and guest export behavior are unchanged. No performance gain is claimed. ### Tested Windows 11 10.0.26200, MinGW GCC, Release build. Reproduced with the unmodified header from main `49f36536321fa3941deb9408d556597dab1e4e28`, rebuilt the patched kernel and SystemService, then restored this one-line change and rebuilt them and the instance-lock tests. The branch is rebased onto main `105c9e4d91`; the intervening merges touch AES unwrap and relative DPP shader instructions, not the linkage or instance-lock code tested here. - Main: existing `patched_libraries` test fails: `392 patched libraries loaded, 15 failed`; all 15 failures report `LoadLibraryEx failed with error 127`, including SystemService and UserService. - With the fix: `407 patched libraries loaded, 0 failed`. - `ctest --test-dir <build> -R "^(patched_libraries|instance_lock.*)$" -V`: all 7 tests pass, none skipped. Includes lock behavior, host backend, held-lock startup, unset/off configuration and startup without a title. - `python tools/check_conventions.py --base upstream/main`: passes. The explicitly requested `--base origin/main` was also run; the fork main is stale and reports 18 errors in pre-existing upstream commits, unrelated to this one-line diff. - `python tools/pr_overlap.py --branch codex/fix-lock-release-linkage --repo boykopovar/AnyPS5`: no overlap with the 1,793 other open PRs examined. Revalidated after a fresh full runtime and relinker build with the supported WinLibs GCC 15.2.0 UCRT/POSIX r7 toolchain on main `105c9e4d91` plus this one-line change: the same seven CTest tests pass, with `407 patched libraries loaded, 0 failed`. No export-only test was added; the existing loader and behavioral tests cover the regression. <!-- OS, title or homebrew, what was checked. "Not tested" is a valid answer. A performance change: the summary lines of main and of this PR from the same machine and scene, with the traces attached, captured as the Performance report issue form describes. --> ### 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: <!-- #PR, or none --> none - [x] Fixes: <!-- issue it closes as Fixes #N, or none --> none - [x] Unblocks: <!-- title ID and Game bring-up discussion, e.g. PPSA01325 #3232, or none --> none - [x] GPUs tested: <!-- for AGC, shader recompiler or VideoOut changes: vendor, model, driver and OS of each GPU the GPU tests ran on; otherwise n/a --> n/a - [x] AI-assisted: <!-- yes / no --> yes
coptergui-ops commented 2026-11-08 12:30:21 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by coptergui-ops on 2026-11-08T12:30:21Z.

Review: APPROVED


Reviewed at current head. Change is exactly as described: extern C added to the shared ReleaseHostInstanceLock_nid_no_patch declaration so MinGW stops emitting the mangled _v-suffixed symbol that breaks NID patching (Windows error 127 loading SystemService); definition and other-header copies removed so linkage is declared once; test gains the include. Lock acquisition/release semantics untouched. Conventions checker: no new findings from this diff.

<!-- greyfinch-sync:boykopovar/AnyPS5:review:5817878262 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/17140#pullrequestreview-5817878262). Originally posted by [coptergui-ops](https://github.com/coptergui-ops) on 2026-11-08T12:30:21Z. **Review:** APPROVED --- Reviewed at current head. Change is exactly as described: extern C added to the shared ReleaseHostInstanceLock_nid_no_patch declaration so MinGW stops emitting the mangled _v-suffixed symbol that breaks NID patching (Windows error 127 loading SystemService); definition and other-header copies removed so linkage is declared once; test gains the include. Lock acquisition/release semantics untouched. Conventions checker: no new findings from this diff.

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