Repository navigation
runtime/shims: add offline ws2_32.dll Winsock2 shim for mapped EXE - #6943
emirhan-karaca wants to merge 3 commits into
Conversation
Hiiva
left a comment
There was a problem hiding this comment.
Native Windows review of exact head 59fbf52. The unchanged synthetic fixture builds and passes under MSVC.
- ANSI: 147 checks, 0 failed.
- UNICODE: 147 checks, 0 failed.
- Same fixture linked with registry.cpp but without ws2_32_offline.cpp: 10 checks, 8 expected failures.
- test_build_runtime_fallback.py: 8 methods passed.
- test_ctest_registration.py: 4 methods passed.
Each fixture executable's direct DLL dependency list was inspected before execution: only KERNEL32.dll, with no host Winsock import. Source inspection found no host socket/DNS calls or LoadLibrary/GetProcAddress path in the new shim. The local socket/refusal/event/query implementation also received a separate source review. MSVC emitted 28 C4996 warnings in each positive build for SDK-deprecated ANSI Winsock fields; there were no compile or link errors. These were direct focused MSVC builds, not a full runtime CTest run.
I also compiled one binding-only probe against unchanged main 1cc6e3c and this exact head, using actual production loader, registry, library-loader, and Winsock sources. Both runs passed 688 expected-observation checks across 53 map-only import cases. All mapped synthetic images have zero entry points and are never initialized.
| Control | Main 1cc6e3c | This head |
|---|---|---|
| #1 through #23, getaddrinfo and freeaddrinfo, direct imports | Host | Shim |
| Same 25 public API spellings through PE forwarders | Host | Shim |
| All 89 registered named/ordinal pairs through the dynamic module handle | Host | Shim |
| Registered names through a real System32 HMODULE | Host | Shim |
| Registered ordinals through that real HMODULE | Host | Host |
| Unregistered WSALookupServiceBeginW, static and forwarded | Host | Host |
| Unregistered WSALookupServiceBeginW through the owned dynamic handle | Host | NULL / ERROR_PROC_NOT_FOUND |
| Same unregistered export through a real HMODULE | Host | Host |
| Bare ws2_32 module name importing socket | Host | Host |
The ordinal oracle independently checks each of the 89 mappings against actual System32 export addresses. Registry/IAT/dynamic results are compared with those addresses; no returned host Winsock pointer is called. The positive stock fixture executes only the local shim.
The remaining Host rows are existing loader limitations, separate from the implemented functions. #5731 at c4fcea0 covers the missing static/forwarder guard and bare-module normalization. Source inspection of #4861 at c190750 shows coverage of registered ordinals on real host handles, but retains unregistered-export fallback. Neither PR was combined into these #6943 runs. This supports the covered offline import surface; it is not a claim of complete host-network containment.
Environment: Windows 11 build 26200, MSVC toolset 14.44.35207, Windows SDK 10.0.26100.0. Synthetic inputs only; no title execution, game access, GPU, firewall changes, or production edits. AI-assisted.
|
Independent CPU-only check of The table registers 89 functions by name and ordinal. |
|
Thanks @Hiiva for the thorough native Windows/MSVC verification, the 688-check loader/ordinal oracle cross-check, and catching the 28 MSVC Fixed in |
|
Reviewed I also read the whole shim and ran a small probe through
Items 1 and 5 are the ones I'd fix before merging; 2–4 are smaller fidelity gaps that only matter if the title hits those paths. AI-assisted. Synthetic inputs only, no game files. |
|
Tested
Not covered: AI-assisted: built, run and written with Claude Code (Claude Opus 5.5); the numbers above are its unedited output. |
|
Tested Built |
…, UDP writability, 4-aligned handles, numeric DNS, docs)
fcf3fc1 to
32b235b
Compare
|
Thanks @hiddenblur for the thorough code review and edge-case probes, @oVolkra for confirming all 25 retail Rebased cleanly onto
Re-verified locally (
|
|
Tested on RTX 5090, 621.24, Windows 11: pass. +25 shim, −25 host, and |
|
Tested
What this does not show: these runs stop at an asset-loading assert soon after No game files in this comment. AI-assisted (Claude Code). |
Integrates upstream PR ItsNotRexed#6943 through 32b235b. Routes mapped Winsock imports to the offline implementation before further boot attempts, matching the repository's no-online rule. Includes its synthetic API tests in the Windows integration build. AI-assisted integration; local fallback-build tests and no-game-data check pass.
@ItsNotRexed pinging as requested for an EXE/runtime PR.
Claim: #6750 (comment)
Context: #6715 (
game_scarlett_master.exemaps undergta6rt --dry-runand imports 25 functions fromws2_32.dll— 23 by classic Winsock ordinal plusgetaddrinfoandfreeaddrinfo).Problem
While
gta6rtalready ownswinhttp.dll(runtime/shims/winhttp_offline.cpp) so mapped titles cannot make live HTTP requests,ws2_32.dllhad no shim table. Everyws2_32.dllimport — both static IAT/delay-load imports (including ordinal imports formatted as#<ordinal>bype_loader.cpp) and dynamicLoadLibrary/GetProcAddresslookups vialibrary_loader.cpp— fell straight through to the host'sws2_32.dll, allowing live DNS queries, real TCP/UDP sockets, and blocking network timeouts.Changes
runtime/shims/ws2_32_offline.cpp(new):ws2_32.dllordinal (178SHIM_TABLEentries), givingrt::shims::owns_dll("ws2_32.dll") == trueand covering all classic Winsock 1.1 ordinals (#1–#23,#51–#57,#111–#116,#151),getaddrinfo/freeaddrinfo(#192/#191),GetAddrInfoW/FreeAddrInfoW,GetAddrInfoEx*/FreeAddrInfoEx*,getnameinfo/GetNameInfoW,GetHostNameW,inet_pton/inet_ntop/InetPtonW/InetNtopW,WSAAddressToString*/WSAStringToAddress*,WSASocketA/W,WSAConnect*,WSAAccept,WSASend*/WSARecv*,WSAPoll,WSAIoctl(includingSIO_UDP_CONNRESET=0x9800000C/FIONREAD/FIONBIO),WSAEventSelect/WSAEnumNetworkEvents/WSA*Event,WSAAsyncSelect,WSAHton*/WSANtoh*,WSAEnumProtocolsA/W, andWSAGetOverlappedResult.ws2_32.dllcalls or linkage — answers every operation in-process.connect/WSAConnect/WSAConnectByNameA/W/WSAConnectByList/sendto/WSASendTo/WSASendMsgfail immediately withWSAENETUNREACH, recordSO_ERROR, fireFD_CONNECTon registeredWSAEventSelectevents, and log each unique target once tostderr([rt] ws2_32: offline, refused <kind> <target>). Streamsend/recv/getpeernamereturnWSAENOTCONN; bound non-blocking UDPrecvfrom/WSARecvFromreturnWSAEWOULDBLOCK.WSAStartup/WSACleanupmaintain a lock-protected refcount; local syntheticSOCKEThandles supportbind(with ephemeral ports),getsockname,listen,setsockopt/getsockopt,ioctlsocket,WSAIoctl, and boundedselect/WSAPoll(capped to 10 ms / 1 ms for infinite waits).getaddrinfo/GetAddrInfoW/GetAddrInfoEx*resolve numeric IPv4/IPv6 literals,AI_PASSIVEwildcards, andlocalhost(withAI_CANONNAME) in-process; any remote hostname is logged once and fails immediately withWSAHOST_NOT_FOUND.SRWLOCK+InitOnceExecuteOnce, Win32FlsAllocfor per-threadinet_ntoabuffers, and file-scope POD tables forgethostbyname/getprotoby*— zero_tls_indexand zero function-local static init guards (__cxa_guard_acquire/_Init_thread_header).runtime/test/ws2_32_offline_test.cpp(new):#ordinalthroughrt::shims::find(using RFC 2606.invalidand RFC 5737/3849 documentation addresses; zero network traffic, zero hostws2_32.dllimports).runtime/CMakeLists.txt&scripts/build_runtime.ps1:shims/ws2_32_offline.cpptogta6rtin bothruntime/CMakeLists.txtandscripts/build_runtime.ps1(keepingtests/test_build_runtime_fallback.pyin sync), and registersws2_32_offline_test(ctestnamews2_32_offline).Verification
g++ 16.2.0(-std=c++20 -O2 -Wall -Wextra -Wconversion -Wsign-conversion -Werroronws2_32_offline.cppandws2_32_offline_test.cppin both ANSI and-DUNICODE -D_UNICODEmodes: 0 warnings).ws2_32_offline_test.cpp+registry.cppwithoutws2_32_offline.cpp, representingorigin/main1cc6e3c12):exit=1 | 10 checks, 8 failed(FAIL shim registry owns ws2_32.dll,FAIL all 89 ws2_32 exports resolve identically by name and Windows ordinal, plus 6 null-resolution guards).exit=0 | 147 checks, 0 failed, includingPASS all 89 ws2_32 exports resolve identically by name and Windows ordinal).gta6rt): PASS (exit=0 | 147 checks, 0 failed).winhttp_offline_test.cpp+winhttp_offline.cpp+ws2_32_offline.cpp+registry.cpp):exit=0 | 83 check(s), 0 failure(s)), proving zero symbol collisions or regressions when both offline network shims are linked together.objdump -p ws2_32_offline_test.exeDLL imports: onlyKERNEL32.dllandmsvcrt.dll(zerows2_32.dllimport).nm -u ws2_32_unicode.o: zero_tls_index, zero__cxa_guard_*, zero hostws2_32symbols.add_executable(gta6rt ...).cppset matchesscripts/build_runtime.ps1$files(missing=0).git diff --check: exit 0 (CRLF=0on all new files andruntime/CMakeLists.txt).Disclosures
ws2_32.dll), and test run was locally verified.g++ 16.2.0(linked untouchedregistry.cppwith a scratch_AddressOfReturnAddressintrinsic stub) and no local MSVCcl.exe, CMake, or Python; full MSVC/W4 /permissive- /utf-8+ctest+test_build_runtime_fallback.pyverification will run in CI.