Skip to content

winrun: safe SuspendThread, Steam accept context, 2048 threads per process - #106

Merged
v3nn7 merged 2 commits into
mainfrom
fix/steam-transport
Nov 4, 2026
Merged

v3nn7 merged 2 commits into
mainfrom
fix/steam-transport

Conversation

@v3nn7

@v3nn7 v3nn7 commented Nov 4, 2026 •

Copy link
Copy Markdown
Collaborator

Follow-up to #105. With this PR the 64-bit Steam client gets through its web helper start, the web UI transport connects, and Steam's "Sign in to Steam" window opens fully rendered (test run s67o: the sign-in form and the QR code the Steam servers sent).

Changes, in the order the Steam test runs found them

  • SuspendThread waits for a safe point (kernel32.rs). The target runs on until it holds none of winrun's locks and the allocator is free (500 ms at most). Before this, Chromium's stack sampler suspended a thread inside the loader, region or heap lock, then called VirtualQuery, and the web helper's browser process hung.
  • SO_UPDATE_ACCEPT_CONTEXT / SO_UPDATE_CONNECT_CONTEXT (ws2_32.rs). Steam calls the first after AcceptEx and dropped every connection when it failed.
  • 2048 threads per process (shared/abi, was 256). Overlapped I/O fails with WSAENOBUFS instead of panicking when no helper thread can start.
  • Non-blocking connect reports WSAEWOULDBLOCK even when the stack connects loopback at once, as on Windows. Before, Chromium's TCPSocketWin hit NOTREACHED on every connect.
  • Socket owner PIDs (kernel/src/net.rs, NetSocket::pid, which replaces the old reserved field, so the record stays 56 bytes; GetExtendedTcpTable dwOwningPid). Steam answers its /transportsocket/ with 403 unless it can open the peer process found through the TCP table.
  • atlthunk.dll. ATL takes its window procedure thunks from it. Without it, ATL raised STATUS_NO_MEMORY a second after the Steam window was created.
  • CallWindowProcA, PtInRegion, Shell_NotifyIconA: the last delay imports steamwebhelper.exe was missing.
  • RWX pages that are not present switch too (mem.rs). V8 code pages that were discarded, or never touched, while mapped read-execute faulted as not present and the renderer died. MEM_RESET now keeps pages committed, as on Windows.
  • GetTokenInformation on another process's token refuses the classes that process can change (open review point from Steam: CEF browser starts its child processes, disk caches and GPU fallback #105).
  • Drawing on another process's window: window handles now name their process, so a handle is valid in every process, as on Windows. GetDC on another process's window gives a DC whose BitBlt sends the pixels to the owning process through its handle service (DRAW request), and the owner draws them. IsWindow asks the owner. Chromium's GPU process draws the browser process's window this way. xwindow.exe tests it (6/6 on Windows 11, passes on OSyx).
  • Z order: windows go to the top when created, shown, activated, or placed at HWND_TOP. EnumWindows lists top-level windows (no child or message-only windows) from the top down. Before this, Chromium's occlusion tracking marked Steam's window as covered and the renderer never drew.
  • File sharing: opening a file only for access that touches no data (WRITE_DAC, READ_CONTROL, attributes) no longer takes part in sharing checks, as on Windows. Chromium's PreventExecuteMapping hit a sharing violation on the temporary file renderers park strings in, and the renderer then died about 75 s after the window appeared (a CHECK in ParkableStringImpl).
  • Winsock: a non-blocking connect that fails at once returns WSAEWOULDBLOCK, and select with every set empty fails with WSAEINVAL, as on Windows 11.
  • Diagnostics under OSYX_WINRUN_FAILTRACE: socket calls and errors, the first bytes of socket transfers, overlapped completions, and the page fault error code in access violation reports.

Verification

  • cargo build of the kernel and all user programs (flags from scripts/build.ps1) succeeds. cargo test -p osyx-abi: 22 passed.
  • New Win32 checks pass on Windows 11: the wsaext.exe IPv6 checks (from Steam: CEF browser starts its child processes, disk caches and GPU fallback #105) and newlibs.exe atlthunk (5/5).
  • Steam runs s66u through s67o on OSyx/QEMU, each confirming one fix above. s67o: the GPU process sends real frames into the browser's window and the sign-in window is fully rendered.
  • Full Win32 suite on OSyx (scripts/win-test.ps1): 2947 passed, 0 failed.
  • Further diagnostics: OSYX_WINRUN_ECHO_FILES copies files a program writes (Steam and CEF logs) to stderr, OSYX_WINRUN_APPEND_ARGS adds arguments when starting a program, and stall reports name each thread.

Remaining

  • ANGLE/SwiftShader EGL initialisation fails in the GPU process; Chromium falls back to software compositing.
  • Web fonts (MotivaSans) fail to load in the renderer (remote_font_face_source NOTREACHED), so Chromium falls back to other fonts.

Labels: bug, network, kernel

🤖 Generated with Claude Code

- kernel32: SuspendThread lets the target run on to a point where it holds
  none of winrun's locks and the allocator is free (half a second at most)
  before it returns. Chromium's stack sampler suspends threads and then
  calls VirtualQuery; a thread stopped inside the loader, region or heap
  lock hung the whole web helper browser process.
- ws2_32: setsockopt SO_UPDATE_ACCEPT_CONTEXT (the accepted socket takes
  the listener's buffer sizes) and SO_UPDATE_CONNECT_CONTEXT. Steam's
  client calls the first after AcceptEx on its local web UI transport
  server and dropped every connection when it failed with
  WSAENOPROTOOPT.
- ws2_32: socket, bind, connect, listen, accept and Winsock errors are
  logged under OSYX_WINRUN_FAILTRACE too, not only under -v.
- ws2_32/overlapped: a helper thread that cannot be started fails the
  operation with WSAENOBUFS instead of panicking the process; helpers use
  64 KiB stacks like winrun's other helpers.
- abi: MAX_THREADS per process 256 -> 2048. The web helper's browser
  process reached the limit (its own threads plus winrun's helpers for
  registered waits and overlapped I/O) and winrun panicked spawning one.
- tokens: GetTokenInformation on another process's token refuses the
  classes that process can change (privileges, owner, primary group,
  default DACL, integrity level) instead of reporting their start state.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@github-actions github-actions Bot added bug Something isn't working network Area: networking labels Nov 4, 2026
@v3nn7 v3nn7 added the kernel Area: kernel label Nov 4, 2026
@github-actions github-actions Bot added the kernel Area: kernel label Nov 4, 2026
@coderabbitai

coderabbitai Bot commented Nov 4, 2026 •

Copy link
Copy Markdown

Explain Change →

Caution

Review failed

The pull request is closed.

Walkthrough

The changes update SuspendThread retry behavior, remote token information queries, Winsock context options and diagnostics, and overlapped helper-thread handling. The maximum thread count also increases from 256 to 2048.

Changes: Thread suspension

Layer / File(s) Summary
Safe suspension retry
compatibility/win32/src/kernel32.rs
SuspendThread retries when the target holds winrun locks or the allocator is busy. It checks for self-suspension and stops retrying when the target is safe or 500 ms elapse. Existing error mappings and the returned suspend count remain in place.

Remote token queries

Layer / File(s) Summary
Remote token information checks
compatibility/win32/src/tokens.rs
Queries for token information classes 3, 4, 5, 6, and 25 return ERROR_ACCESS_DENIED for remote process tokens. Other classes continue through the existing query path.

Winsock options and tracing

Layer / File(s) Summary
Socket context updates
compatibility/win32/src/ws2_32.rs
Adds SO_UPDATE_ACCEPT_CONTEXT and SO_UPDATE_CONNECT_CONTEXT. Accepted-socket updates validate the listener handle and stream type, then copy recorded buffer settings. Connect-context updates return WSAENOTCONN if querying the peer address fails.
Winsock tracing and operation logs
compatibility/win32/src/ws2_32.rs
Error diagnostics are enabled by verbose mode or kernel32 tracing. Bind, connect, listen, and accept also log socket and address details when tracing is enabled.

Overlapped helper threads

Layer / File(s) Summary
Helper thread capacity and failure handling
shared/abi/src/lib.rs, compatibility/win32/src/ws2_32/overlapped.rs
MAX_THREADS increases to 2048. The overlapped helper threads use 64 KiB stacks. If send or receive thread creation fails, the pending operation and held descriptor are cleaned up, and the operation returns WSAENOBUFS with SOCKET_ERROR.

Estimated code review effort: 3 (Moderate) | ~20 minutes

Change: Bug fix

Possibly related PRs

  • OSyxSoftware/OSyx#105: Updates TerminateThread with a retry approach for targets holding winrun locks or when the allocator is busy.
  • OSyxSoftware/OSyx#104: Implements overlapped socket operations and helper threads, which the helper-thread changes modify.
  • OSyxSoftware/OSyx#88: Stores socket buffer settings that SO_UPDATE_ACCEPT_CONTEXT copies to accepted sockets.

Suggested reviewers: claude, zenix1111

Merge Risk: Moderate · up to e0213

This change fixes the Steam hangs and thread-limit failures but adds several regressions. SuspendThread can still leave a thread stopped while it holds a lock, and accepted sockets can fail or lose listener timeouts. The higher thread limit can exhaust kernel memory, a failed overlapped send can duplicate data on retry, and remote integrity-level queries now fail. Address these before merging.

- [ ] Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

@codspeed

codspeed Bot commented Nov 4, 2026 •

Copy link
Copy Markdown
Contributor

Merging this PR will not alter performance

✅ 36 untouched benchmarks


Comparing fix/steam-transport (45c9396) with main (923b19b)1

Open in CodSpeed

Footnotes

  1. No successful run was found on main (45c9396) during the generation of this report, so 923b19b was used instead as the comparison base. There might be some changes unrelated to this pull request in this report. ↩

The kernel connects loopback sockets at once, so a non-blocking connect
to 127.0.0.1 returned 0. On Windows it always fails with WSAEWOULDBLOCK
and reports the connection through FD_CONNECT and select's writability;
Chromium's TCPSocketWin treats a 0 as unreachable (NOTREACHED) on every
connection its network service made to Steam's local servers. The call
now reports a completed non-blocking connect the Windows way; the event
watcher records FD_CONNECT when the connected socket is writable.

Overlapped socket completions are logged under OSYX_WINRUN_FAILTRACE
(the first 400), to follow the traffic.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@v3nn7
v3nn7 merged commit dff9870 into main Nov 4, 2026
3 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working kernel Area: kernel network Area: networking

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant