kernel: fix kernel_file_system_tests on Windows (guest thread cancellation, truncate and socket-option errors) #1805
No reviewers
Labels
No labels
bug
documentation
duplicate
enhancement
GPU
GUI
help wanted
question
Shaders
Video
wontfix
No milestone
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set
Reference
github/KytyPS5--KytyPS5!1805
Loading…
Reference in a new issue
No description provided.
Delete branch "gh-pr/1805/head"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
@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 mergingkernel_file_system_testsfails on Windows on current main: the mutex-cancel case added ine87fb8c85crashes 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
longjmpback to the start routine, which unwinds throughRtlUnwind. A guest thread is cancelled while on its guest stack: those frames have no unwind dataand
RunOnGuestStackclears the TEB stack limits, so the unwind raises STATUS_BAD_STACK. Anyhonoured cancellation of a guest thread takes this path (e.g.
scePthreadCancelplus a join, or anasynchronous cancel type).
Fix: on Windows,
RunThreadpushes a cleanup handler around the guest entry that leaves the entrythe same way
PthreadExitdoes (its stack switch moved toLeaveGuestEntry). The thread thenreturns
(void*)-1, matching Linux hosts. Linux/macOS are unchanged.Error codes
sceKernelTruncateonfile/childreturned ENOENT (MSVC'sstd::filesystemreports a missingpath); it now returns ENOTDIR like POSIX hosts.
SOL_SOCKEToptions went to Winsock unchanged and came back as EINVAL; they now returnENOPROTOOPT, as Linux hosts already do.
Testing
Windows 11, clang-cl 19.1.5, Release + LTO, configured as in build.yml.
kernel_file_system_testspasses 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_testsis 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
@coderabbitai[bot] on GitHub · 2026-10-21 23:47 UTC · original · edited 2026-10-22 00:20 UTC
No actionable comments were generated in the recent review. 🎉
ℹ️ Recent review info
⚙️ Run configuration
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.cpptests/KernelFileSystemTests.cppIncluded 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
KernelTruncateerror mapping when a non-directory ancestor blocks path traversal. They add shared guest-entry restoration forPthreadExitand Windows thread cancellation. They restrict Windows socket-option translation by operation type and expand error coverage for unsupported options.Suggested reviewers:
nmzikPriority: ➖ Normal
Change: Bug fix
Merge Risk: 🔵 Low · up to
23dfdA 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:
4 ·
1
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 helpto get the list of available commands.@coderabbitai[bot] on GitHub · 2026-10-21 23:47 UTC · original
On
src/libs/network.cppline 1098 (outdated):🎯 Functional Correctness | 🟡 Minor | ⚡ Quick win
Use an operation-aware allowlist for Windows
SOL_SOCKEToptions.This predicate accepts unsupported values such as
SO_USELOOPBACK(0x40). It also acceptsSO_RCVLOWAT,SO_SNDLOWAT, andSO_TYPEin the0x1001–0x1008range. Windows reports these cases as unsupported or get-only options, often withWSAEINVAL. (learn.microsoft.com)Setsockoptforwards these values at Line 2298, then mapsWSAEINVALto guestPOSIX_EINVALat Line 994. The guest still receivesEINVAL, not the requiredENOPROTOOPT.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 · reviewed
Actionable comments posted: 1
ℹ️ Review info
⚙️ Run configuration
0c60091a-5eee-47c4-b29b-da745f208213📥 Commits
Reviewing files that changed from the base of the PR and between
919fac13d0and d9648bff146e2b7c59586ad8cba42b1320ea1ed7.📒 Files selected for processing: 3
src/kernel/fileSystem.cppsrc/kernel/pthread.cppsrc/libs/network.cppIncluded review availability: This review used your included allowance. Your plan provides up to 8 included reviews per hour; 7 remain after this review.
@ -1094,2 +1124,4 @@}return option;#else(void)set;@coderabbitai[bot] on GitHub · 2026-10-22 00:06 UTC · original
🎯 Functional Correctness | 🟡 Minor | ⚡ Quick win
🔎 Supported by static analysis
🏁 Script executed:
Repository: KytyPS5/KytyPS5
Length of output: 6895
Reject
SO_ERRORbefore calling Winsock forsetsockopt.The
0x1007mapping returnsSO_ERRORbeforeWinsockSharesSocketOptionchecks the operation. A guestsetsockopt(..., SOL_SOCKET, SO_ERROR, ...)therefore reaches Winsock. Winsock definesSO_ERRORas a get-and-clear option, so the set call can returnWSAEINVAL, which this file translates to guestEINVALinstead of the expectedENOPROTOOPT.Suggested fix
@coderabbitai[bot] on GitHub · 2026-10-22 00:06 UTC · original · reviewed
Actionable comments posted: 1
ℹ️ Review info
⚙️ Run configuration
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.cpptests/KernelFileSystemTests.cppIncluded review availability: This review used your included allowance. Your plan provides up to 8 included reviews per hour; 6 remain after this review.
@ZrDaniel07 on GitHub · 2026-10-22 03:18 UTC · original
Tested on Windows, confirms the crash and the fix.
main@8502d8a:kernel_file_system_tests.exeexits with 0xC0000028 (STATUS_BAD_STACK)main@8502d8a+ the three commits of this PR (cherry-picked cleanly):KernelFileSystemTests: all cases passed, exit 0Note for coordination with #1770: this PR makes a cancelled guest thread return
(void*)-1on Windows, while #1770 changes the same check to compare against the hostPTHREAD_CANCELED, which in the bundled winpthread is0xDEADBEEF(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