kernel: make select handle file descriptors through a descriptor table shared with sockets (CP2077) #1765
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!1765
Loading…
Reference in a new issue
No description provided.
Delete branch "gh-pr/1765/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?
@ArtyomZabroda on GitHub · 2026-10-20 16:37 UTC · original
ArtyomZabroda:pr/descriptor-table-main→main· +225 −115 · 3 files · 2 commits · closed without mergingFixes #182.
AI use:
I used the claude code to find the source of the problem, made an initial implementation myself, and used claude to refine it. PR description was written by claude.
Before:
selecton a descriptor that is an open file or device, such as/dev/urandom, failed withEBADF, becauseNet::Selectonly knew sockets. Cyberpunk 2077 gathers entropy the way OpenSSL'sRAND_polldoes: open/dev/urandom,selectwith a 10 ms timeout, andreadonly if it is ready. The failedselectleft it with no entropy, so it calledsceKernelDebugRaiseExceptionOnReleaseModeand returned frommain. The guestexitthen freed the module code whileredHTTPWorkerwas still running, and that thread crashed executing at eboot+0x1ddc93d.After:
selectreports open files as ready for reading, writing and error conditions, as POSIX specifies for regular files. When a file is already ready, it does not wait on the sockets in the same set.To tell a file from a socket,
selectneeds every number to have one owner. Until now files and sockets were numbered separately: files from 3 upward, sockets from 128 to 1023. Once a game had more than 125 files open, the same number could belong to both.How:
ReserveDescriptor,ReleaseDescriptorandGetDescriptorKindinkernel/fileSystemkeep one table of numbers for files and sockets. Both take the lowest free number after the standard streams. Sockets stay below 1024 (FD_SETSIZE).Select,Read,Write,Close,Preadv,WritevandFtruncatecheck the kind of the descriptor instead of callingNet::IsSocket.The first commit only applies clang-format to the touched files. The second commit holds the change.
Before:


After:
@coderabbitai[bot] on GitHub · 2026-10-20 16:43 UTC · original · edited 2026-10-21 13:24 UTC
📝 Walkthrough
File and socket descriptors now share a descriptor-kind registry. File-system operations use it to identify sockets and apply socket-specific behavior. Network socket allocation and release use the shared table.
Selecttreats regular files and directories as immediately ready while continuing to poll sockets.Suggested reviewers:
nmzikPriority: ➖ Normal
Change: Bug fix
Merge Risk: 🟡 Moderate · up to
da932Descriptor-free timed waits can return immediately and cause guest callers to spin. Socket descriptor flags also cannot be read back after being set. Restore the timeout behavior before merging.
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.@ -605,0 +656,4 @@case 1: return 0; // F_GETFDcase 2: return OK; // F_SETFDdefault: return KERNEL_ERROR_EINVAL;}@coderabbitai[bot] on GitHub · 2026-10-20 16:43 UTC · original
🎯 Functional Correctness | 🟡 Minor | ⚡ Quick win
Retain socket descriptor flags for
F_GETFD.If a guest calls
F_SETFDwithFD_CLOEXECon a socket, the nextF_GETFDreturns zero. This breaks the read-after-write contract even though the guest never callsexec. Store the flag with the socket descriptor and return its current value fromF_GETFD.@ -2645,3 +2662,1 @@} else#endif{if (!descriptors.empty()) {@coderabbitai[bot] on GitHub · 2026-10-20 16:43 UTC · original
🩺 Stability & Availability | 🟠 Major | ⚡ Quick win
Preserve timeout waits when no descriptors are requested.
On Linux,
Select(0, nullptr, nullptr, nullptr, timeout)skipsSelectSocketsand returns immediately. A caller usingselectas a timed wait can then spin instead of waiting. Keep the native empty-setselectpath on non-Windows hosts whenfile_descriptorsis empty.@coderabbitai[bot] on GitHub · 2026-10-20 16:43 UTC · original · reviewed
Actionable comments posted: 2
ℹ️ Review info
⚙️ Run configuration
f88c4a95-e37d-4253-9d6e-95180783627d📥 Commits
Reviewing files that changed from the base of the PR and between
7b7f9a70c6andda932d24d4.📒 Files selected for processing: 3
src/kernel/fileSystem.cppsrc/kernel/fileSystem.hsrc/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.
@Nmzik on GitHub · 2026-10-22 20:12 UTC · original
@ArtyomZabroda Credited Thanks!
Pull request closed