kernel: name guest threads on the host #1106

Manually merged
github merged 1 commit from gh-pr/1106/head into gh-pr/1106/base 2026-11-26 09:43:07 +00:00
Owner

@⁠oberdfr on GitHub · 2026-10-06 14:14 UTC · original
oberdfr:upstream-clean → main · +5 −0 · 1 files · 1 commits · merged 2026-10-06 19:43 UTC

PthreadCreate carries a guest thread name, but RunThread did not pass it to the host, so guest threads appeared under a generic host thread name in diagnostics.

Call pthread_setname_np() on Linux for nonempty guest thread names, truncated to the 15-character host limit. This PR contains only the pthread naming change in src/kernel/pthread.cpp.

Validation: verified that the PR contains one commit and only the five-line pthread naming addition; git diff --check passes. No new build or runtime tests were run for this scope reduction.

**@⁠oberdfr** on GitHub · 2026-10-06 14:14 UTC · [original](https://github.com/KytyPS5/KytyPS5/pull/1106) `oberdfr:upstream-clean` → `main` · +5 −0 · 1 files · 1 commits · merged 2026-10-06 19:43 UTC PthreadCreate carries a guest thread name, but RunThread did not pass it to the host, so guest threads appeared under a generic host thread name in diagnostics. Call pthread_setname_np() on Linux for nonempty guest thread names, truncated to the 15-character host limit. This PR contains only the pthread naming change in src/kernel/pthread.cpp. Validation: verified that the PR contains one commit and only the five-line pthread naming addition; git diff --check passes. No new build or runtime tests were run for this scope reduction.
PthreadCreate carries a guest thread name, but RunThread never handed it to
the host, so every guest thread showed up as the same generic host thread
name in core dumps, perf samples and htop.

Call pthread_setname_np() on Linux so host-side diagnostics can attribute
work to the guest thread that caused it.
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 09:43:06 +00:00
github manually merged commit ebe6126251 into gh-pr/1106/base 2026-11-26 09:43:07 +00:00
Author
Owner

@⁠coderabbitai[bot] on GitHub · 2026-10-06 14:18 UTC · original · edited 2026-10-06 19:42 UTC

Review in Change Stack →

📝 Walkthrough

Walkthrough

The change updates PRT aperture and direct-memory range handling, sets Linux host thread names from guest thread names, and adds four LibNet socket wrappers with symbol-table registrations.

Suggested reviewers: nmzik

Priority: ➖ Normal

Change: Bug fix

Merge Risk: 🟡 Moderate · up to 29169

The network wrappers and Linux thread naming look low risk. The PRT aperture changes can corrupt the virtual-range bookkeeping, though. Clearing an aperture that holds mapped memory can make a later memory release crash the emulator. An aperture that overlaps existing ranges can also be reported as set without being reserved. Fix both before merging.

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ 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 12 functions across 3 files. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
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.
Title check ✅ Passed The title accurately describes the Linux guest-thread naming change, which is one part of the pull request. It does not mention the PRT aperture or libNet changes.
Description check ✅ Passed The description covers the guest-thread naming change, which is part of the pull request. However, its claim that the pull request contains only that change conflicts with the provided summary, which …
  • Autopilot · 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-06 14:18 UTC · [original](https://github.com/KytyPS5/KytyPS5/pull/1106#issuecomment-6018278801) · edited 2026-10-06 19:42 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/1106?scope=ghh_OusAJGA4HG8ljoOV0wJvVx8NmnZIjc2DdjmxOu0xZWA&amp;cs_source=review_comment"><img src="https://storage.googleapis.com/coderabbit_public_assets/review-stack-in-coderabbit-ui-dark.svg?v=2" alt="Review in Change Stack →" width="220" height="32"></a> <!-- review_stack_entry_end --> <!-- walkthrough_start --> <details> <summary>📝 Walkthrough</summary> ## Walkthrough The change updates PRT aperture and direct-memory range handling, sets Linux host thread names from guest thread names, and adds four LibNet socket wrappers with symbol-table registrations. **Suggested reviewers:** `nmzik` </details> <!-- walkthrough_end --> <!-- change_assessment_start --> **Priority:** ➖ Normal <!-- change_assessment_commit:"291692796c22bea4e52c1be30b3ce319f4f36030" --> **Change:** Bug fix <!-- change_assessment_end --> <!-- final_review_risk_start --> **Merge Risk:** _🟡 Moderate_ · up to `29169` <!-- final_review_risk_coverage:{"sourceCommitId":"291692796c22bea4e52c1be30b3ce319f4f36030","coveredCommitId":"291692796c22bea4e52c1be30b3ce319f4f36030","kind":"reviewed"} --> The network wrappers and Linux thread naming look low risk. The PRT aperture changes can corrupt the virtual-range bookkeeping, though. Clearing an aperture that holds mapped memory can make a later memory release crash the emulator. An aperture that overlaps existing ranges can also be reported as set without being reserved. Fix both before merging. <!-- final_review_risk_end --> <!-- pre_merge_checks_walkthrough_start --> <details> <summary>🚥 Pre-merge checks | ✅ 4 | ❌ 1</summary> ### ❌ 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 12 functions across 3 files. | Write docstrings for the functions missing them to satisfy the coverage threshold. | <details> <summary>✅ Passed checks (4 passed)</summary> | Check name | Status | Explanation | | :------------------------: | :------- | :-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | | 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. | | Title check | ✅ Passed | The title accurately describes the Linux guest-thread naming change, which is one part of the pull request. It does not mention the PRT aperture or libNet changes. | | Description check | ✅ Passed | The description covers the guest-thread naming change, which is part of the pull request. However, its claim that the pull request contains only that change conflicts with the provided summary, which … | </details> </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">Autopilot</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=1106)! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. <details> <summary>❤️ Share</summary> - [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) </details> <sub>Comment `@coderabbitai help` to get the list of available commands.</sub> <!-- tips_end -->
Author
Owner

@⁠coderabbitai[bot] on GitHub · 2026-10-06 14:18 UTC · original
On src/kernel/memory.cpp line 2434 (outdated):

@@ -2431,13 +2431,15 @@ int KYTY_SYSV_ABI KernelSetPrtAperture(int index, void* addr, size_t len) {
 	}
 	if (old.size != 0) {
 		UnmapGpuRange(old.address, old.size);
+		g_virtual_ranges->Remove(old.address, old.size);

🗄️ Data Integrity & Integration | 🟠 Major | 🏗️ Heavy lift

Preserve mappings when an aperture is cleared.

If a direct mapping replaces part of an aperture’s Reserved span, Remove(old.address, old.size) also deletes the Direct entry. The physical mapping remains. A later direct-memory release then fails the ownership check in ReleaseDirectMemoryInternal and terminates the emulator. Remove only aperture-owned reserved spans, and keep committed mappings in the virtual range table.

**@⁠coderabbitai[bot]** on GitHub · 2026-10-06 14:18 UTC · [original](https://github.com/KytyPS5/KytyPS5/pull/1106#discussion_r4196417482) On `src/kernel/memory.cpp` line 2434 (outdated): ```diff @@ -2431,13 +2431,15 @@ int KYTY_SYSV_ABI KernelSetPrtAperture(int index, void* addr, size_t len) { } if (old.size != 0) { UnmapGpuRange(old.address, old.size); + g_virtual_ranges->Remove(old.address, old.size); ``` **🗄️ Data Integrity & Integration** | **🟠 Major** | **🏗️ Heavy lift** **Preserve mappings when an aperture is cleared.** If a direct mapping replaces part of an aperture’s `Reserved` span, `Remove(old.address, old.size)` also deletes the `Direct` entry. The physical mapping remains. A later direct-memory release then fails the ownership check in `ReleaseDirectMemoryInternal` and terminates the emulator. Remove only aperture-owned reserved spans, and keep committed mappings in the virtual range table. <!-- fingerprinting:phantom:poseidon:wombat --> <!-- cr-indicator-types:potential_issue --> <!-- cr-comment:v1:550b318b8e645a7efb7add66 --> <!-- This is an auto-generated comment by CodeRabbit -->
Author
Owner

@⁠coderabbitai[bot] on GitHub · 2026-10-06 14:18 UTC · original
On src/kernel/memory.cpp line 2442 (outdated):

@@ -2431,13 +2431,15 @@ int KYTY_SYSV_ABI KernelSetPrtAperture(int index, void* addr, size_t len) {
 	}
 	if (old.size != 0) {
 		UnmapGpuRange(old.address, old.size);
+		g_virtual_ranges->Remove(old.address, old.size);
 	}
 	{
 		Common::LockGuard lock(g_prt_aperture_mutex);
 		g_prt_apertures[static_cast<size_t>(index)] =
 		    len == 0 ? PrtAperture {} : PrtAperture {address, static_cast<uint64_t>(len)};
 	}
 	if (len != 0) {
+		g_virtual_ranges->Add(address, len, 0, 0, 0, VirtualRangeType::Reserved, "prt_aperture");

🗄️ Data Integrity & Integration | 🟠 Major | ⚡ Quick win

Handle failure to register the aperture range.

If the requested aperture overlaps an existing virtual range, VirtualRanges::Add returns false. KernelSetPrtAperture nevertheless records the aperture and returns OK. The aperture then appears in KernelGetPrtAperture and IsInPrtAperture without the intended reserved range. Check registration before publishing the aperture state, and return an error when registration fails.

**@⁠coderabbitai[bot]** on GitHub · 2026-10-06 14:18 UTC · [original](https://github.com/KytyPS5/KytyPS5/pull/1106#discussion_r4196417497) On `src/kernel/memory.cpp` line 2442 (outdated): ```diff @@ -2431,13 +2431,15 @@ int KYTY_SYSV_ABI KernelSetPrtAperture(int index, void* addr, size_t len) { } if (old.size != 0) { UnmapGpuRange(old.address, old.size); + g_virtual_ranges->Remove(old.address, old.size); } { Common::LockGuard lock(g_prt_aperture_mutex); g_prt_apertures[static_cast<size_t>(index)] = len == 0 ? PrtAperture {} : PrtAperture {address, static_cast<uint64_t>(len)}; } if (len != 0) { + g_virtual_ranges->Add(address, len, 0, 0, 0, VirtualRangeType::Reserved, "prt_aperture"); ``` **🗄️ Data Integrity & Integration** | **🟠 Major** | **⚡ Quick win** **Handle failure to register the aperture range.** If the requested aperture overlaps an existing virtual range, `VirtualRanges::Add` returns false. `KernelSetPrtAperture` nevertheless records the aperture and returns `OK`. The aperture then appears in `KernelGetPrtAperture` and `IsInPrtAperture` without the intended reserved range. Check registration before publishing the aperture state, and return an error when registration fails. <!-- fingerprinting:phantom:poseidon:wombat --> <!-- cr-indicator-types:potential_issue --> <!-- cr-comment:v1:c81350469a03185c66db9b5c --> <!-- This is an auto-generated comment by CodeRabbit -->
Author
Owner

@⁠coderabbitai[bot] on GitHub · 2026-10-06 14:18 UTC · original · reviewed

Actionable comments posted: 2


ℹ️ Review info
⚙️ Run configuration
  • Configuration used: Repository: KytyPS5/KytyPS5/.coderabbit.yaml
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 680460d6-b413-4f51-bd0c-71a370d641fb
📥 Commits

Reviewing files that changed from the base of the PR and between fb7ff7ec03 and 291692796c22bea4e52c1be30b3ce319f4f36030.

📒 Files selected for processing (3)
  • src/kernel/memory.cpp
  • src/kernel/pthread.cpp
  • src/libs/libNet.cpp

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-06 14:18 UTC · [original](https://github.com/KytyPS5/KytyPS5/pull/1106#pullrequestreview-5429779629) · **reviewed** **Actionable comments posted: 2** --- <details> <summary>ℹ️ Review info</summary> <details> <summary>⚙️ Run configuration</summary> - **Configuration used**: Repository: KytyPS5/KytyPS5/.coderabbit.yaml - **Review profile**: CHILL - **Plan**: Advanced - **Run ID**: `680460d6-b413-4f51-bd0c-71a370d641fb` </details> <details> <summary>📥 Commits</summary> Reviewing files that changed from the base of the PR and between fb7ff7ec03e8b7a940b7debdc9f54892a98ab4a5 and 291692796c22bea4e52c1be30b3ce319f4f36030. </details> <details> <summary>📒 Files selected for processing (3)</summary> * `src/kernel/memory.cpp` * `src/kernel/pthread.cpp` * `src/libs/libNet.cpp` </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=87410c6d-2ec9-407c-a179-5f21d9a8e7aa attempt=a2d2fbd6-79e4-4497-a894-a0a001f9d327 batch=1/1 -->
Author
Owner

@⁠defektu on GitHub · 2026-10-06 17:46 UTC · original

#1093 LibNet parts have similarities. Commit c937236 looks as if it was taken from #1093.

**@⁠defektu** on GitHub · 2026-10-06 17:46 UTC · [original](https://github.com/KytyPS5/KytyPS5/pull/1106#issuecomment-6022070849) #1093 LibNet parts have similarities. Commit c937236 looks as if it was taken from #1093.
Author
Owner

@⁠Nmzik on GitHub · 2026-10-06 19:40 UTC · original · edited 2026-10-06 19:44 UTC

image Game is in-game state on main with depth-to-color patch. @⁠oberdfr I couldnt verify ur PRT changes as game doesnt request any of it
**@⁠Nmzik** on GitHub · 2026-10-06 19:40 UTC · [original](https://github.com/KytyPS5/KytyPS5/pull/1106#issuecomment-6024074654) · edited 2026-10-06 19:44 UTC <img width="1268" height="719" alt="image" src="https://github.com/user-attachments/assets/d8c012bb-9bf5-4155-bcba-b983100c864d" /> Game is in-game state on main with depth-to-color patch. @⁠oberdfr I couldnt verify ur PRT changes as game doesnt request any of it
This discussion has been locked. Commenting is limited to contributors.
No description provided.