kernel: fix kernel_file_system_tests on Windows (guest thread cancellation, truncate and socket-option errors) #1805

Closed
github-bot wants to merge 3 commits from gh-pr/1805/head into gh-pr/1805/base
Owner

@⁠CarRamRod-963 on GitHub · 2026-10-21 23:41 UTC · original
CarRamRod-963:upstream-pthread-cancel-2026-10-21 → main · +132 −45 · 4 files · 3 commits · closed without merging

kernel_file_system_tests fails on Windows on current main: the mutex-cancel case added in
e87fb8c85 crashes the process with 0xc0000028 (STATUS_BAD_STACK). The test is not in the CI lists,
so it only shows up when run locally. With the crash fixed, two more checks fail because of host
error codes.

Guest thread cancellation (crash)

winpthreads honours a cancellation with a longjmp back to the start routine, which unwinds through
RtlUnwind. A guest thread is cancelled while on its guest stack: those frames have no unwind data
and RunOnGuestStack clears the TEB stack limits, so the unwind raises STATUS_BAD_STACK. Any
honoured cancellation of a guest thread takes this path (e.g. scePthreadCancel plus a join, or an
asynchronous cancel type).

Fix: on Windows, RunThread pushes a cleanup handler around the guest entry that leaves the entry
the same way PthreadExit does (its stack switch moved to LeaveGuestEntry). The thread then
returns (void*)-1, matching Linux hosts. Linux/macOS are unchanged.

Error codes

  • sceKernelTruncate on file/child returned ENOENT (MSVC's std::filesystem reports a missing
    path); it now returns ENOTDIR like POSIX hosts.
  • Unknown SOL_SOCKET options went to Winsock unchanged and came back as EINVAL; they now return
    ENOPROTOOPT, as Linux hosts already do.

Testing

Windows 11, clang-cl 19.1.5, Release + LTO, configured as in build.yml. kernel_file_system_tests
passes with these commits and exits with 0xc0000028 without them. The Windows CI ctest list plus
memory_tracker and page_manager all pass. Not run on Linux/macOS (the cancel handler and the socket
filter are Windows-only).

kernel_file_system_tests is in none of the build.yml test lists; adding it would have caught this.
It opens a hidden Vulkan window, so the runner needs a Vulkan device.

🤖 Generated with Claude Code

**@⁠CarRamRod-963** on GitHub · 2026-10-21 23:41 UTC · [original](https://github.com/KytyPS5/KytyPS5/pull/1805) `CarRamRod-963:upstream-pthread-cancel-2026-10-21` → `main` · +132 −45 · 4 files · 3 commits · closed without merging `kernel_file_system_tests` fails on Windows on current main: the mutex-cancel case added in e87fb8c85 crashes the process with 0xc0000028 (STATUS_BAD_STACK). The test is not in the CI lists, so it only shows up when run locally. With the crash fixed, two more checks fail because of host error codes. **Guest thread cancellation (crash)** winpthreads honours a cancellation with a `longjmp` back to the start routine, which unwinds through `RtlUnwind`. A guest thread is cancelled while on its guest stack: those frames have no unwind data and `RunOnGuestStack` clears the TEB stack limits, so the unwind raises STATUS_BAD_STACK. Any honoured cancellation of a guest thread takes this path (e.g. `scePthreadCancel` plus a join, or an asynchronous cancel type). Fix: on Windows, `RunThread` pushes a cleanup handler around the guest entry that leaves the entry the same way `PthreadExit` does (its stack switch moved to `LeaveGuestEntry`). The thread then returns `(void*)-1`, matching Linux hosts. Linux/macOS are unchanged. **Error codes** - `sceKernelTruncate` on `file/child` returned ENOENT (MSVC's `std::filesystem` reports a missing path); it now returns ENOTDIR like POSIX hosts. - Unknown `SOL_SOCKET` options went to Winsock unchanged and came back as EINVAL; they now return ENOPROTOOPT, as Linux hosts already do. **Testing** Windows 11, clang-cl 19.1.5, Release + LTO, configured as in build.yml. `kernel_file_system_tests` passes with these commits and exits with 0xc0000028 without them. The Windows CI ctest list plus memory_tracker and page_manager all pass. Not run on Linux/macOS (the cancel handler and the socket filter are Windows-only). `kernel_file_system_tests` is in none of the build.yml test lists; adding it would have caught this. It opens a hidden Vulkan window, so the runner needs a Vulkan device. 🤖 Generated with [Claude Code](https://claude.com/claude-code)
winpthreads runs a canceled thread's cleanup handlers on its current stack
and then longjmps to the start routine, which unwinds with RtlUnwind. A
guest thread is canceled on its guest stack: the guest frames have no unwind
data and RunOnGuestStack clears the TEB stack limits, so the unwind raised
STATUS_BAD_STACK (0xc0000028) and took the whole process down at the first
honored cancellation (pthread_testcancel -> _pthread_invoke_cancel ->
pthread_exit -> longjmp -> RtlUnwindEx).

Push an innermost cleanup handler around the guest entry on Windows that
returns from the entry the way PthreadExit already does (its stack switch is
now LeaveGuestEntry). RunThread then runs CleanupThread and returns the
canceled value guests see on Linux hosts ((void*)-1), so joins report the
cancellation. A cancellation outside the guest entry keeps the winpthreads
path.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Windows reports "file/child" as a missing path, so sceKernelTruncate answered
ENOENT where POSIX hosts (and the guest) see ENOTDIR. When the host says the
path is missing, check the nearest existing ancestor and report ENOTDIR if it
is not a directory.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Unknown SOL_SOCKET options were passed to Winsock unchanged, which rejects
them with WSAEINVAL on datagram sockets, so the guest saw EINVAL instead of
ENOPROTOOPT (Linux hosts already reject every unmapped option). Pass through
only the options Winsock implements under their BSD numbers for the
requested operation (SO_ACCEPTCONN and SO_TYPE only for a get) and report
ENOPROTOOPT for the rest, including SO_USELOOPBACK, SO_SNDLOWAT and
SO_RCVLOWAT, which Winsock does not implement. Winsock also accepts a
set of the get-only SO_ERROR; reject it like BSD.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 10:06:13 +00:00
github-bot closed this pull request 2026-11-26 10:06:14 +00:00
Author
Owner

@⁠coderabbitai[bot] on GitHub · 2026-10-21 23:47 UTC · original · edited 2026-10-22 00:20 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: f7c2b7ea-8dfc-485b-9279-b2fac3f79298
📥 Commits

Reviewing files that changed from the base of the PR and between 19ac7b4e7b10a1e2a6425c4c8fa0f0b4545603bd and 23dfd5ad1a.

📒 Files selected for processing: 2
  • src/libs/network.cpp
  • tests/KernelFileSystemTests.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 changes update KernelTruncate error mapping when a non-directory ancestor blocks path traversal. They add shared guest-entry restoration for PthreadExit and Windows thread cancellation. They restrict Windows socket-option translation by operation type and expand error coverage for unsupported options.

Suggested reviewers: nmzik

Priority: ➖ Normal

Change: Bug fix

Merge Risk: 🔵 Low · up to 23dfd

A narrowly timed thread cancellation could crash the process. The socket-option error mapping is fixed; merging with the remaining cancellation risk warrants explicit owner acceptance.

Pre-merge checks: Passed 4 · Failed 1

Failed Failed checks: 1 warning

Check name Status Explanation Resolution
Docstring Coverage Warning Docstring coverage is 25.00% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 16 functions across 4 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 Windows-specific fixes for kernel_file_system_tests, including guest thread cancellation, truncate errors, and socket-option errors.
Description check Passed The description directly explains the three Windows failures, their causes, the implemented fixes, and the reported test results.
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-21 23:47 UTC · [original](https://github.com/KytyPS5/KytyPS5/pull/1805#issuecomment-6329114498) · edited 2026-10-22 00:20 UTC <!-- coderabbit-ai-generated:v1 --> <!-- 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/1805?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**: `f7c2b7ea-8dfc-485b-9279-b2fac3f79298` </dd> </dl> </details> <details> <summary><strong>📥 Commits</strong></summary> <dl> <dd> Reviewing files that changed from the base of the PR and between 19ac7b4e7b10a1e2a6425c4c8fa0f0b4545603bd and 23dfd5ad1a8d3d5d1e6f05bc8ff849a8d78ea660. </dd> </dl> </details> <details> <summary><strong>📒 Files selected for processing: 2</strong></summary> <dl> <dd> * `src/libs/network.cpp` * `tests/KernelFileSystemTests.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 changes update `KernelTruncate` error mapping when a non-directory ancestor blocks path traversal. They add shared guest-entry restoration for `PthreadExit` and Windows thread cancellation. They restrict Windows socket-option translation by operation type and expand error coverage for unsupported options. **Suggested reviewers:** `nmzik` </dd> </dl> </details> <!-- walkthrough_end --> <!-- change_assessment_start --> **Priority:** ➖ Normal <!-- change_assessment_commit:"23dfd5ad1a8d3d5d1e6f05bc8ff849a8d78ea660" --> **Change:** Bug fix <!-- change_assessment_end --> <details> <summary><strong>Merge Risk:</strong> <strong>🔵 Low</strong> · up to <code>23dfd</code></summary> <dl> <dd> <!-- final_review_risk_start --> <!-- final_review_risk_label **Merge Risk:** **🔵 Low** · up to `23dfd` --> <!-- final_review_risk_coverage:{"sourceCommitId":"23dfd5ad1a8d3d5d1e6f05bc8ff849a8d78ea660","coveredCommitId":"23dfd5ad1a8d3d5d1e6f05bc8ff849a8d78ea660","kind":"reviewed"} --> A narrowly timed thread cancellation could crash the process. The socket-option error mapping is fixed; merging with the remaining cancellation risk warrants explicit owner acceptance. <!-- 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 25.00% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 16 functions across 4 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 Windows-specific fixes for kernel_file_system_tests, including guest thread cancellation, truncate errors, and socket-option errors. | | Description check | ![Passed](https://storage.googleapis.com/coderabbit_public_assets/pre-merge-checks-passed.svg) | The description directly explains the three Windows failures, their causes, the implemented fixes, and the reported test results. | | 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=1805)! 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-21 23:47 UTC · original
On src/libs/network.cpp line 1098 (outdated):

@@ -1091,6 +1091,12 @@ static int ConvertSocketOptionName(int level, int option) {
 		return TCP_NODELAY;
 	}
 #if defined(_WIN32)
+	if (level == 0xffff) {
+		// Winsock shares the BSD numbers of these socket-level options; it rejects others with
+		// WSAEINVAL, which would hide the guest's ENOPROTOOPT.
+		const bool flag = option > 0 && option <= 0x100 && (option & (option - 1)) == 0;
+		return flag || (option >= 0x1001 && option <= 0x1008) ? option : -1;

🎯 Functional Correctness | 🟡 Minor | ⚡ Quick win

Use an operation-aware allowlist for Windows SOL_SOCKET options.

This predicate accepts unsupported values such as SO_USELOOPBACK (0x40). It also accepts SO_RCVLOWAT, SO_SNDLOWAT, and SO_TYPE in the 0x1001–0x1008 range. Windows reports these cases as unsupported or get-only options, often with WSAEINVAL. (learn.microsoft.com)

Setsockopt forwards these values at Line 2298, then maps WSAEINVAL to guest POSIX_EINVAL at Line 994. The guest still receives EINVAL, not the required ENOPROTOOPT.

Filter options according to the requested operation and reject unsupported values before calling Winsock.

**@⁠coderabbitai[bot]** on GitHub · 2026-10-21 23:47 UTC · [original](https://github.com/KytyPS5/KytyPS5/pull/1805#discussion_r4343140642) On `src/libs/network.cpp` line 1098 (outdated): ```diff @@ -1091,6 +1091,12 @@ static int ConvertSocketOptionName(int level, int option) { return TCP_NODELAY; } #if defined(_WIN32) + if (level == 0xffff) { + // Winsock shares the BSD numbers of these socket-level options; it rejects others with + // WSAEINVAL, which would hide the guest's ENOPROTOOPT. + const bool flag = option > 0 && option <= 0x100 && (option & (option - 1)) == 0; + return flag || (option >= 0x1001 && option <= 0x1008) ? option : -1; ``` <!-- coderabbit-ai-generated:v1 --> **🎯 Functional Correctness** | **🟡 Minor** | **⚡ Quick win** **Use an operation-aware allowlist for Windows `SOL_SOCKET` options.** This predicate accepts unsupported values such as `SO_USELOOPBACK` (`0x40`). It also accepts `SO_RCVLOWAT`, `SO_SNDLOWAT`, and `SO_TYPE` in the `0x1001`–`0x1008` range. Windows reports these cases as unsupported or get-only options, often with `WSAEINVAL`. ([learn.microsoft.com](https://learn.microsoft.com/th-th/windows/win32/winsock/sol-socket-socket-options)) `Setsockopt` forwards these values at Line 2298, then maps `WSAEINVAL` to guest `POSIX_EINVAL` at Line 994. The guest still receives `EINVAL`, not the required `ENOPROTOOPT`. Filter options according to the requested operation and reject unsupported values before calling Winsock. <!-- fingerprinting:phantom:triton:caracal --> <!-- cr-indicator-types:potential_issue --> <!-- cr-comment:v1:c4e59ad29f72bc99209b3715 --> <!-- This is an auto-generated comment by CodeRabbit -->
Author
Owner

@⁠coderabbitai[bot] on GitHub · 2026-10-21 23:47 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: 0c60091a-5eee-47c4-b29b-da745f208213
📥 Commits

Reviewing files that changed from the base of the PR and between 919fac13d0 and d9648bff146e2b7c59586ad8cba42b1320ea1ed7.

📒 Files selected for processing: 3
  • src/kernel/fileSystem.cpp
  • src/kernel/pthread.cpp
  • src/libs/network.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-21 23:47 UTC · [original](https://github.com/KytyPS5/KytyPS5/pull/1805#pullrequestreview-5607599245) · **reviewed** <!-- coderabbit-ai-generated:v1 --> **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**: `0c60091a-5eee-47c4-b29b-da745f208213` </details> <details> <summary>📥 Commits</summary> Reviewing files that changed from the base of the PR and between 919fac13d048097f1823d7ef9333351d8e850541 and d9648bff146e2b7c59586ad8cba42b1320ea1ed7. </details> <details> <summary>📒 Files selected for processing: 3</summary> * `src/kernel/fileSystem.cpp` * `src/kernel/pthread.cpp` * `src/libs/network.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=1fcd2dda-09f8-4251-9b89-e743e28c0457 attempt=d7d9d618-1e21-4eba-9464-da313976ce7e batch=1/1 -->
@ -1094,2 +1124,4 @@
}
return option;
#else
(void)set;
Author
Owner

@⁠coderabbitai[bot] on GitHub · 2026-10-22 00:06 UTC · original

🎯 Functional Correctness | 🟡 Minor | ⚡ Quick win

🔎 Supported by static analysis

🏁 Script executed:

sed -n '985,1020p' src/libs/network.cpp
sed -n '1075,1130p' src/libs/network.cpp
sed -n '2305,2355p' src/libs/network.cpp
rg -n 'SO_ERROR|NET_SO_ERROR|POSIX_ENOPROTOOPT|WSAEINVAL' src/libs/network.cpp tests/KernelFileSystemTests.cpp | head -90

Repository: KytyPS5/KytyPS5

Length of output: 6895


Reject SO_ERROR before calling Winsock for setsockopt.

The 0x1007 mapping returns SO_ERROR before WinsockSharesSocketOption checks the operation. A guest setsockopt(..., SOL_SOCKET, SO_ERROR, ...) therefore reaches Winsock. Winsock defines SO_ERROR as a get-and-clear option, so the set call can return WSAEINVAL, which this file translates to guest EINVAL instead of the expected ENOPROTOOPT.

Suggested fix
-			case 0x1007: return SO_ERROR;
+			case 0x1007: return set ? -1 : SO_ERROR;
**@⁠coderabbitai[bot]** on GitHub · 2026-10-22 00:06 UTC · [original](https://github.com/KytyPS5/KytyPS5/pull/1805#discussion_r4343248775) <!-- coderabbit-ai-generated:v1 --> **🎯 Functional Correctness** | **🟡 Minor** | **⚡ Quick win** <details> <summary>🔎 Supported by static analysis</summary> 🏁 Script executed: ```bash sed -n '985,1020p' src/libs/network.cpp sed -n '1075,1130p' src/libs/network.cpp sed -n '2305,2355p' src/libs/network.cpp rg -n 'SO_ERROR|NET_SO_ERROR|POSIX_ENOPROTOOPT|WSAEINVAL' src/libs/network.cpp tests/KernelFileSystemTests.cpp | head -90 ``` Repository: KytyPS5/KytyPS5 Length of output: 6895 --- </details> **Reject `SO_ERROR` before calling Winsock for `setsockopt`.** The `0x1007` mapping returns `SO_ERROR` before `WinsockSharesSocketOption` checks the operation. A guest `setsockopt(..., SOL_SOCKET, SO_ERROR, ...)` therefore reaches Winsock. Winsock defines `SO_ERROR` as a get-and-clear option, so the set call can return `WSAEINVAL`, which this file translates to guest `EINVAL` instead of the expected `ENOPROTOOPT`. <details> <summary>Suggested fix</summary> ```diff - case 0x1007: return SO_ERROR; + case 0x1007: return set ? -1 : SO_ERROR; ``` </details> <!-- fingerprinting:phantom:medusa:wombat --> <!-- cr-indicator-types:potential_issue --> <!-- cr-comment:v1:800f50ed2917c4a043047972 --> <!-- This is an auto-generated comment by CodeRabbit -->
Author
Owner

@⁠coderabbitai[bot] on GitHub · 2026-10-22 00:06 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: 552bf701-f142-470e-a1e8-f4ef7551d8c4
📥 Commits

Reviewing files that changed from the base of the PR and between d9648bff146e2b7c59586ad8cba42b1320ea1ed7 and 19ac7b4e7b10a1e2a6425c4c8fa0f0b4545603bd.

📒 Files selected for processing: 2
  • src/libs/network.cpp
  • tests/KernelFileSystemTests.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-22 00:06 UTC · [original](https://github.com/KytyPS5/KytyPS5/pull/1805#pullrequestreview-5607720915) · **reviewed** <!-- coderabbit-ai-generated:v1 --> **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**: `552bf701-f142-470e-a1e8-f4ef7551d8c4` </details> <details> <summary>📥 Commits</summary> Reviewing files that changed from the base of the PR and between d9648bff146e2b7c59586ad8cba42b1320ea1ed7 and 19ac7b4e7b10a1e2a6425c4c8fa0f0b4545603bd. </details> <details> <summary>📒 Files selected for processing: 2</summary> * `src/libs/network.cpp` * `tests/KernelFileSystemTests.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=0ac6a6f1-3777-4b33-8f6e-dc71c963bf97 attempt=24cc0a5b-cb3e-4570-8212-b26d53df8cc1 batch=1/1 -->
Author
Owner

@⁠ZrDaniel07 on GitHub · 2026-10-22 03:18 UTC · original

Tested on Windows, confirms the crash and the fix.

  • Setup: Windows 11 Pro (build 26300), clang-cl 19.1.5 (VS 2022 Build Tools), Release, Ninja, Ryzen 9 5900X, RTX 5090 (driver 617.42, Vulkan 1.4.351)
  • main @ 8502d8a: kernel_file_system_tests.exe exits with 0xC0000028 (STATUS_BAD_STACK)
  • main @ 8502d8a + the three commits of this PR (cherry-picked cleanly): KernelFileSystemTests: all cases passed, exit 0

Note for coordination with #1770: this PR makes a cancelled guest thread return (void*)-1 on Windows, while #1770 changes the same check to compare against the host PTHREAD_CANCELED, which in the bundled winpthread is 0xDEADBEEF (3rdparty/winpthread/include/pthread.h:130). So after both land, that check would expect the wrong value on Windows (I could not run that combination, see my comment on #1770).

AI use: Claude Code helped me build, run the tests and read the results; I reviewed the output myself.

**@⁠ZrDaniel07** on GitHub · 2026-10-22 03:18 UTC · [original](https://github.com/KytyPS5/KytyPS5/pull/1805#issuecomment-6331827542) Tested on Windows, confirms the crash and the fix. - Setup: Windows 11 Pro (build 26300), clang-cl 19.1.5 (VS 2022 Build Tools), Release, Ninja, Ryzen 9 5900X, RTX 5090 (driver 617.42, Vulkan 1.4.351) - `main` @ 8502d8a: `kernel_file_system_tests.exe` exits with 0xC0000028 (STATUS_BAD_STACK) - `main` @ 8502d8a + the three commits of this PR (cherry-picked cleanly): `KernelFileSystemTests: all cases passed`, exit 0 Note for coordination with #1770: this PR makes a cancelled guest thread return `(void*)-1` on Windows, while #1770 changes the same check to compare against the host `PTHREAD_CANCELED`, which in the bundled winpthread is `0xDEADBEEF` (`3rdparty/winpthread/include/pthread.h:130`). So after both land, that check would expect the wrong value on Windows (I could not run that combination, see my comment on #1770). AI use: Claude Code helped me build, run the tests and read the results; I reviewed the output myself.

Pull request closed

This discussion has been locked. Commenting is limited to contributors.
No description provided.