15 Commits

Author SHA1 Message Date
2dfcd750dc Merge pull request #4464 from cixotdev
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-22 23:14:57 -05:00
3731598f8b Merge pull request #4209 from JavierBlanco23
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-22 23:12:22 -05:00
3a2f4b3e76 Merge pull request #3874 from kotorvr
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-22 23:09:07 -05:00
34d0120c00 Merge pull request #3682 from shdann
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-22 23:08:16 -05:00
be8570ace1 Merge remote-tracking branch 'origin/main' into triage-r43
# Conflicts:
#	docs/runtime_imports.md
#	runtime/CMakeLists.txt
#	runtime/shims/xgameruntime.cpp
#	runtime/test/xmem_test.cpp
#	tools/rdna2spirv.py
2026-11-22 22:12:50 -05:00
b1d2a061cd winhttp_offline_test: name the context values and clear the event list of the inheritance block
Test only, no change of behaviour: the contexts 7, 9, 11 and 0x51 and the "no value" sentinel get constexpr names,
and the static event list is cleared before the block records into it.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
2026-11-23 05:44:54 +03:00
111eb7e6f6 winhttp_offline: initialize server/port and hold ref across HANDLE_CREATED
In `open_connection()` (`WinHttpConnect`), `make_handle(Kind::Connect, s,
s->async)` previously inserted the new `Handle` into `live()` and
synchronously invoked `WINHTTP_CALLBACK_STATUS_HANDLE_CREATED` before
`c->server = server` and `c->port = port` were assigned, and without
holding a temporary reference on the handle while `HANDLE_CREATED` ran.

This caused three issues when a `HANDLE_CREATED` callback acted on the
handle inline or handed it to another thread:
1. Calling `WinHttpCloseHandle(self)` inside `HANDLE_CREATED` erased and
   freed `Handle` (`refs` 1 -> 0 -> `delete h`) before `make_handle()`
   returned, causing `open_connection()` to write `server` and `port`
   into freed heap memory (use-after-free).
2. Because `make_handle()` held no reference across `HANDLE_CREATED`,
   `WinHttpCloseHandle(self)` inside `HANDLE_CREATED` fired
   `WINHTTP_CALLBACK_STATUS_HANDLE_CLOSING` re-entrantly before
   `HANDLE_CREATED` returned and still returned the freed non-null
   `HINTERNET` handle from `WinHttpConnect` / `WinHttpOpenRequest`,
   whereas native `winhttp.dll` (measured on Windows 11 26200) fires
   `HANDLE_CLOSING` after `HANDLE_CREATED` exits and returns `NULL` with
   `ERROR_WINHTTP_OPERATION_CANCELLED` (12017).
3. Opening and sending a request from inside `HANDLE_CREATED` (or from a
   worker thread notified by it) caused `log_refused()` / `server_of()`
   to read an empty `server` and port `0` (`:0`) or race with
   `std::wstring` assignment.

Initialize `h->server` and `h->port` inside `make_handle()` before
inserting into `live()`, hold an extra reference across
`WINHTTP_CALLBACK_STATUS_HANDLE_CREATED` so `HANDLE_CLOSING` fires after
`HANDLE_CREATED` returns, and return `nullptr` with
`ERROR_WINHTTP_OPERATION_CANCELLED` if the callback closed the handle.

Verification (synthetic tests only, no game files):
- `winhttp_offline_test`: 57/57 checks pass via CTest and direct run
- MSVC `/fsanitize=address`: 57/57 checks pass with 0 ASan errors
  (reproduced `heap-use-after-free` on unpatched `origin/main`)
- Adjacent non-GPU runtime shim tests (`loader`, `dll_thread_calls`,
  `unimplemented_policy`, `xmem`, `process_cmdline`, `file_system`,
  `winhttp_offline`, `xgameruntime`): 8/8 passed via CTest
- `python -I scripts/check_no_game_data.py`: passed

Coordination claim:
https://github.com/ItsNotRexed/Leonida/issues/4257#issuecomment-7088991989

AI-assisted implementation and testing.
2026-11-22 22:34:11 -03:00
f73fba1b4c runtime/winhttp_offline: accept blank-line blocks and enforce RFC 7230 header-name token chars 2026-11-23 01:12:22 +01:00
469447a3cc runtime/winhttp_offline: match host WinHTTP header, handle-type, and buffer-size validation (RT-277) 2026-11-23 00:59:42 +01:00
dcdc1100f3 Merge pull request #3682 from shdann 2026-11-22 17:03:24 -05:00
86be100f3a gta6rt: offline WinHttpSendRequest with context 0 keeps the option's context
WinHttpSendRequest assigned its dwContext to the request unconditionally, so a client that set the context with
WINHTTP_OPTION_CONTEXT_VALUE and sent with 0 got 0 back from WinHttpQueryOption and in its REQUEST_ERROR and
HANDLE_CLOSING callbacks. The host's winhttp.dll (Windows 11, asynchronous session, loopback) keeps the option's
value in all three. A nonzero dwContext still replaces it.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-22 22:03:06 +00:00
4c52ce27a6 Seven fixes from an outside contributor (sent as patches, applied without the author's name)
- rdna2spirv: declare each packed vertex input register once; a register whose elements disagree on the component
  type is refused (SHADER-644).
- runtime: a title's VirtualAlloc drops the console's MEM_GRAPHICS / MEM_TITLE type bits the host rejects (RT-217).
- runtime: XPersistentLocalStorageImpl is served from <overlay>\persistent with the package's 2048 MB quota
  (RT-219; layout from the public docs, not measured in a caller).
- runtime: G:\ names the package and T:\ a scratch folder in the overlay; paths under the configured folders and
  every path with no folders configured stay host paths (RT-218).
- winhttp_offline: header blocks and timeouts the host WinHTTP rejects are rejected the same way.
- cfg_structure.run: a limit of zero or less runs no blocks.
- shader_meta: an s_movk_i32 with a register operand and a float immediate beyond float32 are left unknown instead
  of raising.

Each comes with a test that fails on the old code. Conflicts with main resolved here (internal_dir() hides T:'s
folder; both file_system_test blocks kept).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-22 16:55:46 -05:00
0f83451af9 gta6rt: the offline WinHTTP stub passes a handle's context value to its children
make_handle copied the parent's status callback and notification mask to
a new handle and left its context at 0. The host's winhttp.dll also
passes WINHTTP_OPTION_CONTEXT_VALUE on: a connection and a request start
with the context their parent has when they are made, WinHttpQueryOption
returns it and their HANDLE_CREATED and HANDLE_CLOSING callbacks carry
it. A context set on the handle itself, or given to WinHttpSendRequest,
still replaces it.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
2026-11-23 00:19:59 +03:00
e7e3b7c98e test: winhttp_offline waits for every HANDLE_CLOSING before counting (TEST-721)
The asynchronous block read `closing == 3` right after closing the
connection and the session. When the send's thread-pool callback still holds
the request's last reference, its release delivers the request's
HANDLE_CLOSING (waking the test) and only then drops the request's reference
on the connection, so the connection's and the session's notifications come
on that thread after the read: the check failed, and the late notifications
landed in the next block's count. A wait_for_closing() helper polls up to
two seconds, as the third block already did. The first two blocks now wait
for all three handles before the next block resets the counter.

Proven with temporary delays in the shim (not committed): the old test then
failed 10 of 10 with the reported failure, and the new one passed 20 of 20.
On the unchanged shim: 30 of 30 alone and 40 of 40 four at a time; full
ctest 123/123. Test-only, no runtime behaviour change.
2026-11-22 14:52:20 -06:00
9f41bf65f3 gta6rt: WinHTTP offline for mapped images
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>
2026-11-22 20:35:57 +03:00