diff options
| author | Tyrannys <80750971+Tyrannys@users.noreply.github.com> | 2026-11-27 18:25:47 -0600 |
|---|---|---|
| committer | Tyrannys <80750971+Tyrannys@users.noreply.github.com> | 2026-11-27 18:25:47 -0600 |
| commit | d411fe9b4a3aab2a75dfbed4d6e4f01d758ef668 (patch) | |
| tree | 6fddc2666fe152d622b034a73741b3436613d582 /runtime/shims/process.cpp | |
| parent | d44285197237cfe331684aa150fb9dec4b1d08b5 (diff) | |
d3d12, process: null barrier arrays, CopyTiles in a bundle, calibration wait, entry thread and getmainargs expand
From kevincommits' finding (item 4) in #1608.
- d3d12_com.cpp:
- ResourceBarrier: a count with no array fails the list (check(false)) instead
of reading through null, as WriteBufferImmediate does.
- Barrier: the same for a null group array, and for a group with barriers but
no barrier array (the three array pointers are one union).
- CopyTiles: a bundle is refused for reserved buffers too, not only for sparse
images; no copy is allowed in a bundle.
- submitted_calibration: vkGetQueryPoolResults asks VK_QUERY_RESULT_WAIT_BIT,
so the read cannot answer VK_NOT_READY.
- process.cpp:
- run_entry passes the entry point itself to the game thread instead of a
pointer to its own stack: another thread can end the run before the game
thread first runs, and run_entry's frame is then gone.
- __getmainargs/__wgetmainargs expand wildcards when `expand` is nonzero
(mode 2, as _configure_*_argv does) and fail on a null argc or argv.
Tests: d3d12_com_test (null arrays fail Close; counts of 0 and valid calls
do not), d3d12_buffer_tiles_test (CopyTiles of a reserved buffer in a bundle
fails Close), process_cmdline_test (expand 0 and 1, null argc/argv).
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Diffstat (limited to 'runtime/shims/process.cpp')
| -rw-r--r-- | runtime/shims/process.cpp | 25 |
1 files changed, 12 insertions, 13 deletions
diff --git a/runtime/shims/process.cpp b/runtime/shims/process.cpp index 2c37292e2..29663a92f 100644 --- a/runtime/shims/process.cpp +++ b/runtime/shims/process.cpp | |||
| @@ -417,30 +417,30 @@ wchar_t** current_wide_environment() { | |||
| 417 | return _wenviron; | 417 | return _wenviron; |
| 418 | } | 418 | } |
| 419 | 419 | ||
| 420 | // msvcrt.dll: int __getmainargs(int* argc, char*** argv, char*** env, int expand, void* startinfo) | 420 | // msvcrt.dll: int __getmainargs(int* argc, char*** argv, char*** env, int expand, void* startinfo). A nonzero |
| 421 | int __cdecl game_getmainargs(int* argc, char*** argv, char*** env, int, void*) { | 421 | // `expand` (the CRT's _dowildcard) expands wildcards in the arguments, as _configure_narrow_argv's mode 2 does. |
| 422 | if (const int error = game_configure_narrow_argv(1)) return error; | 422 | int __cdecl game_getmainargs(int* argc, char*** argv, char*** env, int expand, void*) { |
| 423 | if (!argc || !argv) return -1; | ||
| 424 | if (const int error = game_configure_narrow_argv(expand ? 2 : 1)) return error; | ||
| 423 | *argc = g_argc; | 425 | *argc = g_argc; |
| 424 | *argv = g_argv_ptr; | 426 | *argv = g_argv_ptr; |
| 425 | if (env) *env = current_environment(); | 427 | if (env) *env = current_environment(); |
| 426 | return 0; | 428 | return 0; |
| 427 | } | 429 | } |
| 428 | int __cdecl game_wgetmainargs(int* argc, wchar_t*** argv, wchar_t*** env, int, void*) { | 430 | int __cdecl game_wgetmainargs(int* argc, wchar_t*** argv, wchar_t*** env, int expand, void*) { |
| 429 | if (const int error = game_configure_wide_argv(1)) return error; | 431 | if (!argc || !argv) return -1; |
| 432 | if (const int error = game_configure_wide_argv(expand ? 2 : 1)) return error; | ||
| 430 | *argc = g_argc; | 433 | *argc = g_argc; |
| 431 | *argv = g_wargv_ptr; | 434 | *argv = g_wargv_ptr; |
| 432 | if (env) *env = current_wide_environment(); | 435 | if (env) *env = current_wide_environment(); |
| 433 | return 0; | 436 | return 0; |
| 434 | } | 437 | } |
| 435 | 438 | ||
| 436 | struct EntryCall { | 439 | // `p` is the entry point itself: run_entry can return (another thread ended the run) before this thread first runs, |
| 437 | void* entry; | 440 | // so nothing of run_entry's frame may be read here. |
| 438 | }; | ||
| 439 | |||
| 440 | DWORD WINAPI game_thread(void* p) { | 441 | DWORD WINAPI game_thread(void* p) { |
| 441 | auto* call = static_cast<EntryCall*>(p); | ||
| 442 | // An EXE entry point (mainCRTStartup and friends) takes the PEB pointer and returns the process exit code. | 442 | // An EXE entry point (mainCRTStartup and friends) takes the PEB pointer and returns the process exit code. |
| 443 | auto entry = reinterpret_cast<DWORD(WINAPI*)(void*)>(call->entry); | 443 | auto entry = reinterpret_cast<DWORD(WINAPI*)(void*)>(p); |
| 444 | const DWORD code = entry(nullptr); | 444 | const DWORD code = entry(nullptr); |
| 445 | end_run(static_cast<int>(code)); // returning from the entry point is an exit too | 445 | end_run(static_cast<int>(code)); // returning from the entry point is an exit too |
| 446 | } | 446 | } |
| @@ -480,8 +480,7 @@ int run_entry(void* entry, size_t stack_bytes) { | |||
| 480 | g_done = CreateEventW(nullptr, TRUE, FALSE, nullptr); | 480 | g_done = CreateEventW(nullptr, TRUE, FALSE, nullptr); |
| 481 | if (!g_done) return -1; | 481 | if (!g_done) return -1; |
| 482 | g_running = true; | 482 | g_running = true; |
| 483 | EntryCall call{entry}; | 483 | HANDLE thread = CreateThread(nullptr, stack_bytes, game_thread, entry, STACK_SIZE_PARAM_IS_A_RESERVATION, nullptr); |
| 484 | HANDLE thread = CreateThread(nullptr, stack_bytes, game_thread, &call, STACK_SIZE_PARAM_IS_A_RESERVATION, nullptr); | ||
| 485 | if (!thread) { | 484 | if (!thread) { |
| 486 | g_running = false; | 485 | g_running = false; |
| 487 | CloseHandle(g_done); | 486 | CloseHandle(g_done); |