Implement Missing NGS2 System Functions Lock & Unlock #1542

Manually merged
github merged 5 commits from gh-pr/1542/head into gh-pr/1542/base 2026-11-26 09:59:12 +00:00
Owner

@⁠MrBigBritches on GitHub · 2026-10-15 22:48 UTC · original
MrBigBritches:mbbr-ngs2-system-locking → main · +44 −8 · 3 files · 5 commits · merged 2026-10-15 23:39 UTC

Game: Trails in the Sky 1st Chapter

Problem: The game is able to run without these fixes, but the console output regularly complained about 2 missing functions: gThZqM5PYlQ and JXRC5n0RQls. These functions correlate to locking and unlocking the NGS mutex.

Fix: Implemented both functions loosely based off the existing code available from the AnyPS5 repository^1.

Testing:

  • Manual testing on Windows using the aforementioned game.
  • Existing CI tests

Before
image

After
Screenshot 2026-10-15 154413

AI use: None

1 - core/libs/prx/libSceNgs2.native/src/System.cpp#L225-L237

**@⁠MrBigBritches** on GitHub · 2026-10-15 22:48 UTC · [original](https://github.com/KytyPS5/KytyPS5/pull/1542) `MrBigBritches:mbbr-ngs2-system-locking` → `main` · +44 −8 · 3 files · 5 commits · merged 2026-10-15 23:39 UTC **Game:** Trails in the Sky 1st Chapter **Problem:** The game is able to run without these fixes, but the console output regularly complained about 2 missing functions: `gThZqM5PYlQ` and `JXRC5n0RQls`. These functions correlate to locking and unlocking the NGS mutex. **Fix:** Implemented both functions loosely based off the existing code available from the AnyPS5 repository^1. **Testing:** - Manual testing on Windows using the aforementioned game. - Existing CI tests Before <img width="3977" height="1477" alt="image" src="https://github.com/user-attachments/assets/547433a2-9f9e-412b-af2b-a31d882b3bda" /> After <img width="3954" height="1481" alt="Screenshot 2026-10-15 154413" src="https://github.com/user-attachments/assets/823dd6a0-ae3d-4f7f-ae7c-c41f1e993181" /> **AI use:** None 1 - [core/libs/prx/libSceNgs2.native/src/System.cpp#L225-L237](https://github.com/boykopovar/AnyPS5/blob/5d9dcc42d2ec5401aebd089028b8d4d7410a77b4/core/libs/prx/libSceNgs2.native/src/System.cpp#L225-L237)
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 09:59:10 +00:00
github manually merged commit 1d21428f64 into gh-pr/1542/base 2026-11-26 09:59:12 +00:00
Author
Owner

@⁠coderabbitai[bot] on GitHub · 2026-10-15 22:50 UTC · original · edited 2026-10-15 23:11 UTC

Review in Change Stack →

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration
  • Configuration used: Repository: KytyPS5/KytyPS5/.coderabbit.yaml
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 60bc2a04-2fea-478a-9419-72606671a275
📥 Commits

Reviewing files that changed from the base of the PR and between 194c4a8355 and 8fb7afe4fa.

📒 Files selected for processing: 1
  • src/libs/ngs2.cpp
🚧 Files skipped from review as they are similar to previous changes: 1
  • src/libs/ngs2.cpp

Included review availability: This review used your included allowance. Your plan provides up to 8 included reviews per hour; 5 remain after this review.

📝 Walkthrough

The change adds public Ngs2SystemLock and Ngs2SystemUnlock APIs. Each returns NGS2_ERROR_INVALID_SYSTEM_HANDLE if the handle is zero or its cast pointer is null. Otherwise, each locks or unlocks the mutex of the referenced system. NGS2 initialization registers both APIs.

Priority: ➖ Normal

Change: Bug fix

Merge Risk: 🔵 Low · up to 8fb7a

The new lock and unlock functions fix the missing-function reports. A guest that passes a garbage nonzero system handle could still crash the emulator. Normal games pass valid handles, so the risk is small and bounded, but adding a handle membership check would remove it.

Pre-merge checks: Passed 4 · Failed 1

Failed Failed checks: 1 warning

Check name Status Explanation Resolution
Docstring Coverage Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 6 functions across 3 files. Write docstrings for the functions missing them to satisfy the coverage threshold.
Passed Passed checks: 4 passed
Check name Status Explanation
Title check Passed The title clearly identifies the main change: implementing the missing NGS2 system lock and unlock functions.
Description check Passed The description directly explains the missing functions, the implementation, the testing, and the affected game.
Linked Issues check Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check Passed Check skipped because no linked issues were found for this pull request.
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

**@⁠coderabbitai[bot]** on GitHub · 2026-10-15 22:50 UTC · [original](https://github.com/KytyPS5/KytyPS5/pull/1542#issuecomment-6203909096) · edited 2026-10-15 23:11 UTC <!-- This is an auto-generated comment: summarize by coderabbit.ai --> <!-- review_stack_entry_start --> <a href="https://app.coderabbit.ai/change-stack/KytyPS5/KytyPS5/pull/1542?scope=ghh_OusAJGA4HG8ljoOV0wJvVx8NmnZIjc2DdjmxOu0xZWA&amp;cs_source=review_comment"><picture><source media="(prefers-color-scheme: dark)" srcset="https://storage.googleapis.com/coderabbit_public_assets/review-stack-in-coderabbit-ui-dark.svg?v=3"><source media="(prefers-color-scheme: light)" srcset="https://storage.googleapis.com/coderabbit_public_assets/review-stack-in-coderabbit-ui.svg?v=3"><img src="https://storage.googleapis.com/coderabbit_public_assets/review-stack-in-coderabbit-ui.svg?v=3" alt="Review in Change Stack →" height="32"></picture></a> <!-- review_stack_entry_end --> <!-- recent_review_start --> No actionable comments were generated in the recent review. 🎉 <details> <summary><strong>ℹ️ Recent review info</strong></summary> <dl> <dd> <details> <summary><strong>⚙️ Run configuration</strong></summary> <dl> <dd> - **Configuration used**: Repository: KytyPS5/KytyPS5/.coderabbit.yaml - **Review profile**: CHILL - **Plan**: Advanced - **Run ID**: `60bc2a04-2fea-478a-9419-72606671a275` </dd> </dl> </details> <details> <summary><strong>📥 Commits</strong></summary> <dl> <dd> Reviewing files that changed from the base of the PR and between 194c4a83557ea8828452e46a07124598097b5105 and 8fb7afe4fa5b13d9c68b46e73808bd1fb9573c80. </dd> </dl> </details> <details> <summary><strong>📒 Files selected for processing: 1</strong></summary> <dl> <dd> * `src/libs/ngs2.cpp` </dd> </dl> </details> <details> <summary><strong>🚧 Files skipped from review as they are similar to previous changes: 1</strong></summary> <dl> <dd> * src/libs/ngs2.cpp </dd> </dl> </details> **Included review availability:** This review used your included allowance. Your plan provides up to 8 included reviews per hour; 5 remain after this review. </dd> </dl> </details> <!-- recent_review_end --> <!-- walkthrough_start --> <details> <summary><strong>📝 Walkthrough</strong></summary> <dl> <dd> The change adds public `Ngs2SystemLock` and `Ngs2SystemUnlock` APIs. Each returns `NGS2_ERROR_INVALID_SYSTEM_HANDLE` if the handle is zero or its cast pointer is null. Otherwise, each locks or unlocks the mutex of the referenced system. NGS2 initialization registers both APIs. </dd> </dl> </details> <!-- walkthrough_end --> <!-- change_assessment_start --> **Priority:** ➖ Normal <!-- change_assessment_commit:"8fb7afe4fa5b13d9c68b46e73808bd1fb9573c80" --> **Change:** Bug fix <!-- change_assessment_end --> <details> <summary><strong>Merge Risk:</strong> <strong>🔵 Low</strong> · up to <code>8fb7a</code></summary> <dl> <dd> <!-- final_review_risk_start --> <!-- final_review_risk_label **Merge Risk:** **🔵 Low** · up to `8fb7a` --> <!-- final_review_risk_coverage:{"sourceCommitId":"8fb7afe4fa5b13d9c68b46e73808bd1fb9573c80","coveredCommitId":"8fb7afe4fa5b13d9c68b46e73808bd1fb9573c80","kind":"reviewed"} --> The new lock and unlock functions fix the missing-function reports. A guest that passes a garbage nonzero system handle could still crash the emulator. Normal games pass valid handles, so the risk is small and bounded, but adding a handle membership check would remove it. <!-- final_review_risk_end --> </dd> </dl> </details> <!-- pre_merge_checks_walkthrough_start --> <details> <summary><strong>Pre-merge checks: <sup><picture><img src="https://storage.googleapis.com/coderabbit_public_assets/pre-merge-checks-counter-passed-14-v2.svg" width="14" height="14" align="middle" alt="Passed" title="Passed"></picture></sup> 4 · <sup><picture><img src="https://storage.googleapis.com/coderabbit_public_assets/pre-merge-checks-counter-failed-14-v2.svg" width="14" height="14" align="middle" alt="Failed" title="Failed"></picture></sup> 1</strong></summary> <dl> <dd> <strong><sup><picture><img src="https://storage.googleapis.com/coderabbit_public_assets/pre-merge-checks-counter-failed-14-v2.svg" width="14" height="14" align="middle" alt="Failed" title="Failed"></picture></sup> Failed checks: 1 warning</strong> | Check name | Status | Explanation | Resolution | | :---------------- | :----------------------------------------------------------------------------------------------: | :---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | :--------------------------------------------------------------------------------- | | Docstring Coverage | ![Warning](https://storage.googleapis.com/coderabbit_public_assets/pre-merge-checks-warning.svg) | Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 6 functions across 3 files. | Write docstrings for the functions missing them to satisfy the coverage threshold. | <details> <summary><strong><sup><picture><img src="https://storage.googleapis.com/coderabbit_public_assets/pre-merge-checks-counter-passed-14-v2.svg" width="14" height="14" align="middle" alt="Passed" title="Passed"></picture></sup> Passed checks: 4 passed</strong></summary> <dl> <dd> | Check name | Status | Explanation | | :------------------------ | :--------------------------------------------------------------------------------------------: | :--------------------------------------------------------------------------------------------------------------- | | Title check | ![Passed](https://storage.googleapis.com/coderabbit_public_assets/pre-merge-checks-passed.svg) | The title clearly identifies the main change: implementing the missing NGS2 system lock and unlock functions. | | Description check | ![Passed](https://storage.googleapis.com/coderabbit_public_assets/pre-merge-checks-passed.svg) | The description directly explains the missing functions, the implementation, the testing, and the affected game. | | Linked Issues check | ![Passed](https://storage.googleapis.com/coderabbit_public_assets/pre-merge-checks-passed.svg) | Check skipped because no linked issues were found for this pull request. | | Out of Scope Changes check | ![Passed](https://storage.googleapis.com/coderabbit_public_assets/pre-merge-checks-passed.svg) | Check skipped because no linked issues were found for this pull request. | </dd> </dl> </details> </dd> </dl> </details> <!-- pre_merge_checks_walkthrough_end --> <!-- autopilot:start --> - [ ] <!-- {"checkboxId":"2708ad07-9f24-4260-9c11-7dc76a49f2e3"} --> <strong title="Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts">Autofix</strong> · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts <!-- autopilot:end --> <!-- tips_start --> Thanks for using [CodeRabbit](https://coderabbit.ai?utm_source=oss&utm_medium=github&utm_campaign=KytyPS5/KytyPS5&utm_content=1542)! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. <details> <summary><strong>❤️ Share</strong></summary> <dl> <dd> - [X](https://twitter.com/intent/tweet?text=I%20just%20used%20%40coderabbitai%20for%20my%20code%20review%2C%20and%20it%27s%20fantastic%21%20It%27s%20free%20for%20OSS%20and%20offers%20a%20free%20trial%20for%20the%20proprietary%20code.%20Check%20it%20out%3A&url=https%3A//coderabbit.ai) - [Mastodon](https://mastodon.social/share?text=I%20just%20used%20%40coderabbitai%20for%20my%20code%20review%2C%20and%20it%27s%20fantastic%21%20It%27s%20free%20for%20OSS%20and%20offers%20a%20free%20trial%20for%20the%20proprietary%20code.%20Check%20it%20out%3A%20https%3A%2F%2Fcoderabbit.ai) - [Reddit](https://www.reddit.com/submit?title=Great%20tool%20for%20code%20review%20-%20CodeRabbit&text=I%20just%20used%20CodeRabbit%20for%20my%20code%20review%2C%20and%20it%27s%20fantastic%21%20It%27s%20free%20for%20OSS%20and%20offers%20a%20free%20trial%20for%20proprietary%20code.%20Check%20it%20out%3A%20https%3A//coderabbit.ai) - [LinkedIn](https://www.linkedin.com/sharing/share-offsite/?url=https%3A%2F%2Fcoderabbit.ai&mini=true&title=Great%20tool%20for%20code%20review%20-%20CodeRabbit&summary=I%20just%20used%20CodeRabbit%20for%20my%20code%20review%2C%20and%20it%27s%20fantastic%21%20It%27s%20free%20for%20OSS%20and%20offers%20a%20free%20trial%20for%20proprietary%20code) </dd> </dl> </details> <sub>Comment `@coderabbitai help` to get the list of available commands.</sub> <!-- tips_end -->
Author
Owner

@⁠coderabbitai[bot] on GitHub · 2026-10-15 22:50 UTC · original · edited 2026-10-15 23:39 UTC
On src/libs/ngs2.cpp line 2643 (outdated):

@@ -2634,6 +2636,28 @@ int KYTY_SYSV_ABI Ngs2VoiceGetStateFlags(uintptr_t voice_handle, uint32_t* state
 	return OK;
 }
 
+int KYTY_SYSV_ABI Ngs2SystemLock(uintptr_t system_handle) {
+	PRINT_NAME();
+
+	auto* ngs = reinterpret_cast<Ngs2Internal*>(system_handle);
+	if (ngs == nullptr) return NGS2_ERROR_INVALID_SYSTEM_HANDLE;

🩺 Stability & Availability | 🟠 Major | ⚡ Quick win

Validate system handles before accessing the mutex.

A nonzero invalid system_handle passes this check. ngs->mutex.Lock() then accesses an invalid address and can crash the emulator. The unlock function has the same fault at Line 2654. Check handle membership before dereferencing it, as Ngs2SystemGetInfo does at Lines 1124–1131.

✅ Addressed in commit 1d21428

**@⁠coderabbitai[bot]** on GitHub · 2026-10-15 22:50 UTC · [original](https://github.com/KytyPS5/KytyPS5/pull/1542#discussion_r4289064215) · edited 2026-10-15 23:39 UTC On `src/libs/ngs2.cpp` line 2643 (outdated): ```diff @@ -2634,6 +2636,28 @@ int KYTY_SYSV_ABI Ngs2VoiceGetStateFlags(uintptr_t voice_handle, uint32_t* state return OK; } +int KYTY_SYSV_ABI Ngs2SystemLock(uintptr_t system_handle) { + PRINT_NAME(); + + auto* ngs = reinterpret_cast<Ngs2Internal*>(system_handle); + if (ngs == nullptr) return NGS2_ERROR_INVALID_SYSTEM_HANDLE; ``` **🩺 Stability & Availability** | **🟠 Major** | **⚡ Quick win** **Validate system handles before accessing the mutex.** A nonzero invalid `system_handle` passes this check. `ngs->mutex.Lock()` then accesses an invalid address and can crash the emulator. The unlock function has the same fault at Line 2654. Check handle membership before dereferencing it, as `Ngs2SystemGetInfo` does at Lines 1124–1131. <!-- fingerprinting:phantom:poseidon:wombat --> <!-- cr-indicator-types:potential_issue --> <!-- cr-comment:v1:60b6975c75b1b61ef23ef162 --> <!-- This is an auto-generated comment by CodeRabbit --> ✅ Addressed in commit 1d21428
Author
Owner

@⁠coderabbitai[bot] on GitHub · 2026-10-15 22:50 UTC · original · reviewed

Actionable comments posted: 1


ℹ️ Review info
⚙️ Run configuration
  • Configuration used: Repository: KytyPS5/KytyPS5/.coderabbit.yaml
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 2692fa06-9288-4e1d-ab53-a25bedec929e
📥 Commits

Reviewing files that changed from the base of the PR and between 9e41d8320a and 3d49d79251.

📒 Files selected for processing: 3
  • src/libs/libAudio.cpp
  • src/libs/ngs2.cpp
  • src/libs/ngs2.h

Included review availability: This review used your included allowance. Your plan provides up to 8 included reviews per hour; 7 remain after this review.

**@⁠coderabbitai[bot]** on GitHub · 2026-10-15 22:50 UTC · [original](https://github.com/KytyPS5/KytyPS5/pull/1542#pullrequestreview-5540871896) · **reviewed** **Actionable comments posted: 1** --- <details> <summary>ℹ️ Review info</summary> <details> <summary>⚙️ Run configuration</summary> - **Configuration used**: Repository: KytyPS5/KytyPS5/.coderabbit.yaml - **Review profile**: CHILL - **Plan**: Advanced - **Run ID**: `2692fa06-9288-4e1d-ab53-a25bedec929e` </details> <details> <summary>📥 Commits</summary> Reviewing files that changed from the base of the PR and between 9e41d8320a2774b303fbad344c2347e8d0292e83 and 3d49d79251ac2b5842ac82b893bfff4903cb5165. </details> <details> <summary>📒 Files selected for processing: 3</summary> * `src/libs/libAudio.cpp` * `src/libs/ngs2.cpp` * `src/libs/ngs2.h` </details> **Included review availability:** This review used your included allowance. Your plan provides up to 8 included reviews per hour; 7 remain after this review. </details> <!-- This is an auto-generated comment by CodeRabbit for review status --> <!-- coderabbit-review-publication v1 publication=c3e0a878-986e-4dc6-8ce5-42ff53edd3cd attempt=1c314765-edd4-4f87-bb78-d540c0483db6 batch=1/1 -->
Author
Owner

@⁠coderabbitai[bot] on GitHub · 2026-10-15 23:07 UTC · original · edited 2026-10-15 23:11 UTC
On src/libs/ngs2.cpp line 2642 (outdated):

@@ -2634,6 +2636,32 @@ int KYTY_SYSV_ABI Ngs2VoiceGetStateFlags(uintptr_t voice_handle, uint32_t* state
 	return OK;
 }
 
+int KYTY_SYSV_ABI Ngs2SystemLock(uintptr_t system_handle) {
+	PRINT_NAME();
+
+	EXIT_NOT_IMPLEMENTED(system_handle == 0);

🩺 Stability & Availability | 🟠 Major | ⚡ Quick win

Return the invalid-handle error for zero handles.

EXIT_NOT_IMPLEMENTED(system_handle == 0) runs before the null check in both APIs. The project handler requests emergency shutdown and exits, so handle 0 never returns NGS2_ERROR_INVALID_SYSTEM_HANDLE. Return that error from the zero-handle branch instead. The NGS2 reference APIs return the invalid-system-handle error for unrecognized handles. (raw.githubusercontent.com)

Also applies to: 2655-2655

✅ Addressed in commit 8fb7afe

**@⁠coderabbitai[bot]** on GitHub · 2026-10-15 23:07 UTC · [original](https://github.com/KytyPS5/KytyPS5/pull/1542#discussion_r4289176524) · edited 2026-10-15 23:11 UTC On `src/libs/ngs2.cpp` line 2642 (outdated): ```diff @@ -2634,6 +2636,32 @@ int KYTY_SYSV_ABI Ngs2VoiceGetStateFlags(uintptr_t voice_handle, uint32_t* state return OK; } +int KYTY_SYSV_ABI Ngs2SystemLock(uintptr_t system_handle) { + PRINT_NAME(); + + EXIT_NOT_IMPLEMENTED(system_handle == 0); ``` **🩺 Stability & Availability** | **🟠 Major** | **⚡ Quick win** **Return the invalid-handle error for zero handles.** `EXIT_NOT_IMPLEMENTED(system_handle == 0)` runs before the null check in both APIs. The project handler requests emergency shutdown and exits, so handle `0` never returns `NGS2_ERROR_INVALID_SYSTEM_HANDLE`. Return that error from the zero-handle branch instead. The NGS2 reference APIs return the invalid-system-handle error for unrecognized handles. ([raw.githubusercontent.com](https://raw.githubusercontent.com/KytyPS5/KytyPS5/main/src/common/assert.h)) Also applies to: 2655-2655 <!-- fingerprinting:phantom:triton:serval --> <!-- cr-indicator-types:potential_issue --> <!-- cr-comment:v1:fb869733b2c5656378bd67ad --> <!-- This is an auto-generated comment by CodeRabbit --> ✅ Addressed in commit 8fb7afe
Author
Owner

@⁠coderabbitai[bot] on GitHub · 2026-10-15 23:07 UTC · original · reviewed

Actionable comments posted: 1


ℹ️ Review info
⚙️ Run configuration
  • Configuration used: Repository: KytyPS5/KytyPS5/.coderabbit.yaml
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 52b54925-d102-44ae-a63d-3b5edf9e0a43
📥 Commits

Reviewing files that changed from the base of the PR and between 3d49d79251 and 194c4a8355.

📒 Files selected for processing: 1
  • src/libs/ngs2.cpp

Included review availability: This review used your included allowance. Your plan provides up to 8 included reviews per hour; 6 remain after this review.

**@⁠coderabbitai[bot]** on GitHub · 2026-10-15 23:07 UTC · [original](https://github.com/KytyPS5/KytyPS5/pull/1542#pullrequestreview-5541001580) · **reviewed** **Actionable comments posted: 1** --- <details> <summary>ℹ️ Review info</summary> <details> <summary>⚙️ Run configuration</summary> - **Configuration used**: Repository: KytyPS5/KytyPS5/.coderabbit.yaml - **Review profile**: CHILL - **Plan**: Advanced - **Run ID**: `52b54925-d102-44ae-a63d-3b5edf9e0a43` </details> <details> <summary>📥 Commits</summary> Reviewing files that changed from the base of the PR and between 3d49d79251ac2b5842ac82b893bfff4903cb5165 and 194c4a83557ea8828452e46a07124598097b5105. </details> <details> <summary>📒 Files selected for processing: 1</summary> * `src/libs/ngs2.cpp` </details> **Included review availability:** This review used your included allowance. Your plan provides up to 8 included reviews per hour; 6 remain after this review. </details> <!-- This is an auto-generated comment by CodeRabbit for review status --> <!-- coderabbit-review-publication v1 publication=8792b5df-54e0-4c55-a9d3-523f7288b232 attempt=dd3d7451-f51a-4790-af18-360423b5ff68 batch=1/1 -->
This discussion has been locked. Commenting is limited to contributors.
No description provided.