Skip to content

gta6rt: WinHTTP offline for mapped images - #2630

Closed
Nhympex0 wants to merge 1 commit into
ItsNotRexed:mainfrom
Nhympex0:winhttp-offline
Closed

Nhympex0 wants to merge 1 commit into
ItsNotRexed:mainfrom
Nhympex0:winhttp-offline

Conversation

@Nhympex0

Copy link
Copy Markdown
Contributor

Claimed in #2300 (claim).

XCurl.dll and libHttpClient.GDK.dll import 16 WinHTTP functions between them (no Winsock) and today bind to the host's winhttp.dll, so a mapped title could reach the network. This makes winhttp.dll a module the shims own (runtime/shims/winhttp_offline.cpp) and answers all 16 in-process, following the "nothing online" rule:

Call Offline behaviour
WinHttpOpen, WinHttpConnect, WinHttpOpenRequest local handles; no name lookup, no socket
WinHttpSendRequest ERROR_WINHTTP_CANNOT_CONNECT; on a WINHTTP_FLAG_ASYNC session returns TRUE and delivers WINHTTP_CALLBACK_STATUS_REQUEST_ERROR {API_SEND_REQUEST, ERROR_WINHTTP_CANNOT_CONNECT} from a thread-pool thread with the request's context (skipped if the request was closed first)
WinHttpReceiveResponse, QueryHeaders, QueryDataAvailable, ReadData, WriteData ERROR_WINHTTP_INCORRECT_HANDLE_STATE
WinHttpSetOption, SetTimeouts, AddRequestHeaders accepted; WINHTTP_OPTION_CONTEXT_VALUE kept per handle
WinHttpQueryOption CONTEXT_VALUE and HANDLE_TYPE; ERROR_WINHTTP_INVALID_OPTION otherwise
WinHttpSetStatusCallback, WinHttpCloseHandle callbacks inherited by child handles (HANDLE_CREATED); every handle reports HANDLE_CLOSING once, last — reference-counted, so a callback that closes its own request is safe
WinHttpCrackUrl the host's (string parsing only, loaded on first use)

Because the shims own the module, a LoadLibrary("winhttp.dll") from a title also gets a pseudo-handle (library_loader.cpp), and a WinHTTP function outside these 16 resolves to NULL, never to the host. Each refused server is logged once ([rt] winhttp: offline, refused <host>:<port>), which records what a title tried to reach. Docs: new "WinHTTP offline" section in docs/runtime_imports.md.

Tested on 49475796 + this branch, Windows 11 24H2, RTX 5070 Ti (NVIDIA 621.01), MSVC 14.44, Ninja RelWithDebInfo:

  • winhttp_offline: 40/40 checks — sync and async paths, callback thread/context/order, close-inside-callback, close-before-delivery, wrong/closed handles, option sizes, WinHttpCrackUrl. Only .invalid names; no connection is opened.
  • Full runtime ctest (excluding d3d12_draw, which fails on main on this GPU independently of this change): 124/124 passed, 5 skipped (no game dir / no RGB9E5 RTV support).

No game files used or added. AI-assisted (Claude Code); reviewed and run locally.

The package's XCurl.dll and libHttpClient.GDK.dll import 16 WinHTTP functions
(no Winsock) and bound to the host's winhttp.dll, so a mapped title could reach
the network. winhttp.dll is now a module the shims own and all 16 are answered
in-process:

- sessions, connections and requests are local handles; no name lookup, no
  socket;
- WinHttpSendRequest fails with ERROR_WINHTTP_CANNOT_CONNECT; on a
  WINHTTP_FLAG_ASYNC session it returns TRUE and reports
  WINHTTP_CALLBACK_STATUS_REQUEST_ERROR {API_SEND_REQUEST, CANNOT_CONNECT} from
  a thread-pool thread with the request's context (not after the request was
  closed);
- reading a response and WinHttpWriteData fail with
  ERROR_WINHTTP_INCORRECT_HANDLE_STATE; options, timeouts and headers are
  accepted, CONTEXT_VALUE and HANDLE_TYPE can be queried;
- callbacks are inherited by child handles (HANDLE_CREATED), and every handle
  reports HANDLE_CLOSING once, last (reference-counted, so a callback that
  closes its own request is safe);
- WinHttpCrackUrl stays the host's (parsing only, loaded on first use).

Each refused server is logged once. winhttp_offline: 40/40 checks, .invalid
names only, no connection opened.

AI-assisted.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@UlteriorMotive00

Copy link
Copy Markdown
Contributor

Tested 9f41bf65 on Windows 11 Home 26300, RTX 5070 (617.42), MSVC 14.44, Ninja RelWithDebInfo: pass

AI-assisted independent run.

  • winhttp_offline_test: 40 check(s), 0 failure(s).
  • Full runtime ctest: 125/125.
  • Import check against my own 1.0.2.1 package (a small PE import-table reader; counts and the public WinHTTP function names only): XCurl.dll and libHttpClient.GDK.dll import 15 WinHTTP functions each, 16 distinct between them, and neither imports a Winsock module. The 16 are exactly the 16 winhttp_offline.cpp defines (AddRequestHeaders, CloseHandle, Connect, CrackUrl, Open, OpenRequest, QueryDataAvailable, QueryHeaders, QueryOption, ReadData, ReceiveResponse, SendRequest, SetOption, SetStatusCallback, SetTimeouts, WriteData), so no import of those two DLLs falls through to the host's winhttp.dll.

I didn't run a mapped title through it (no executable in the package), only the test and the import comparison.

@grahamster2

Copy link
Copy Markdown

Tested 9f41bf6 merged onto main ec8ec4c (clean merge) on Windows 11 26200, Ryzen 5 7600X (6 cores / 12 threads), MSVC 19.44 (VS 2022 Build Tools), Ninja, RelWithDebInfo, elevated shell: pass.

  • winhttp_offline: 40 checks, 0 failures; 10 more back-to-back runs of winhttp_offline_test.exe all pass, so the thread-pool async REQUEST_ERROR path didn't flake here.
  • Full ctest -j 4 with LEONIDA_VK_DEVICE=NVIDIA (RTX 3080, 610.88): 120/120.
  • Full ctest -j 2 with LEONIDA_VK_DEVICE=AMD (Radeon iGPU of the 7600X, gfx1036, AMD 24.30.66): 119/120. The one failure is d3d12_vulkan_device at command_queue(host.p, rt_desc) == S_OK, which main has on this AMD host in an elevated shell too, and which Tests: skip the host realtime-queue check when the host driver refuses it #2422 handles. Nothing from this PR.

@bielfreedom

Copy link
Copy Markdown

Tested 9f41bf65 (on its base 49475796) on Windows 11 Pro build 26200, MSVC build of runtime/ (RelWithDebInfo, Ninja), AMD Radeon RX 9070 XT (driver 32.0.32029.2010), Vulkan validation on: pass.

  • winhttp_offline passes.
  • Full ctest: 116/116 pass, 0 failures, 0 validation errors.

AI-assisted (Claude Code). No game files.

@XFlawless1

Copy link
Copy Markdown
Contributor

Tested 9f41bf65 merged onto main (ec8ec4c9): pass on both GPUs.

Windows 11 Pro 26300, MSVC 19.44 (VS 2022 Build Tools), Ninja RelWithDebInfo via scripts/build_runtime.ps1, Vulkan SDK 1.4.363.0. Full ctest -j1 once per GPU with LEONIDA_VK_DEVICE: AMD Radeon iGPU of a Ryzen 7 9800X3D (RDNA2 0x13C0, driver 32.0.21042.62) and NVIDIA RTX 5080 (621.14). AI-assisted (Claude Code). No game files.

  • Radeon: 123/123. RTX 5080: 123/123. The new winhttp_offline passes on both.
  • main alone at ec8ec4c9: 122/122 pass on both GPUs. The only tests not run are those that need game files or the validation layer (shader_library_corpus, bink_*, fsr_dispatch, bvh_builder, vk_sync_validation, d3d12_first_light), plus d3d12_rgb9e5_rtv on the RTX 5080. All of these are skipped on main too.

@Nhympex0 Nhympex0 closed this Nov 22, 2026
@Nhympex0
Nhympex0 deleted the winhttp-offline branch November 22, 2026 18:59
@gkissel

gkissel commented Nov 22, 2026

Copy link
Copy Markdown

Tested 9f41bf65 under Wine 11.21 on Linux (Ryzen 7 5800H; Windows build cross-compiled with clang-cl 23.1.4 + xwin SDK 10.0.26100). This is the path where Wine's own winhttp.dll would otherwise answer.

  • winhttp_offline: 40 checks, 0 failures.
  • Syscall check: I ran the test under strace -f -e trace=socket,connect, with a fresh wineserver each time, next to a test that does no networking (allocator_proxy_test.exe):
exe socket(AF_INET…) connect to an inet address
allocator_proxy_test.exe (baseline) 76 0
winhttp_offline_test.exe 76 0

The 76 unconnected SOCK_DGRAM sockets come from Wine's own startup and appear for any exe. The WinHTTP test adds none, and nothing connects to an inet address. So on Wine, too, the shim answers in-process and never reaches the network.

AI-assisted.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants