From d411fe9b4a3aab2a75dfbed4d6e4f01d758ef668 Mon Sep 17 00:00:00 2001 From: Tyrannys <80750971+Tyrannys@users.noreply.github.com> Date: Fri, 27 Nov 2026 18:25:47 -0600 Subject: 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 --- runtime/test/process_cmdline_test.cpp | 54 +++++++++++++++++++++++++++++++++++ 1 file changed, 54 insertions(+) (limited to 'runtime/test/process_cmdline_test.cpp') diff --git a/runtime/test/process_cmdline_test.cpp b/runtime/test/process_cmdline_test.cpp index bf55821d1..f30d4607f 100644 --- a/runtime/test/process_cmdline_test.cpp +++ b/runtime/test/process_cmdline_test.cpp @@ -218,6 +218,59 @@ void check_getmainargs_environment() { ++failures; } } + +// __getmainargs/__wgetmainargs's `expand` (the CRT's _dowildcard): nonzero expands wildcards in the arguments, as +// _configure_*_argv's mode 2 does; zero leaves them as typed. A null argc or argv fails instead of being written +// through. Synthetic files in a temporary folder. +void check_getmainargs_expand() { + using Narrow = int(__cdecl*)(int*, char***, char***, int, void*); + using Wide = int(__cdecl*)(int*, wchar_t***, wchar_t***, int, void*); + const auto narrow_fn = reinterpret_cast(rt::shims::find("msvcrt.dll", "__getmainargs")); + const auto wide_fn = reinterpret_cast(rt::shims::find("msvcrt.dll", "__wgetmainargs")); + if (!narrow_fn || !wide_fn) return; // check_getmainargs_environment reports it + wchar_t temp[MAX_PATH]{}; + if (!GetTempPathW(MAX_PATH, temp)) { + std::fprintf(stderr, "FAIL GetTempPathW\n"); + ++failures; + return; + } + const std::wstring dir = std::wstring(temp) + L"leonida_getmainargs_" + std::to_wstring(GetCurrentProcessId()); + CreateDirectoryW(dir.c_str(), nullptr); + const std::wstring files[] = {dir + L"\\a1.lx", dir + L"\\a2.lx"}; + for (const auto& f : files) { + const HANDLE h = CreateFileW(f.c_str(), GENERIC_WRITE, 0, nullptr, CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, nullptr); + if (h != INVALID_HANDLE_VALUE) CloseHandle(h); + } + const std::wstring pattern = dir + L"\\*.lx"; + rt::process::set_command_line(L"game.exe", {pattern}); + for (const int expand : {0, 1}) { + const int want = expand ? 3 : 2; // game.exe and the two files, or game.exe and the pattern + int argc = 0; + char** argv = nullptr; + if (narrow_fn(&argc, &argv, nullptr, expand, nullptr) != 0 || argc != want || !argv || + (!expand && std::strchr(argv[1], '*') == nullptr) || (expand && std::strchr(argv[1], '*') != nullptr)) { + std::fprintf(stderr, "FAIL __getmainargs(expand=%d): argc %d, want %d\n", expand, argc, want); + ++failures; + } + int wargc = 0; + wchar_t** wargv = nullptr; + if (wide_fn(&wargc, &wargv, nullptr, expand, nullptr) != 0 || wargc != want || !wargv || + (!expand && std::wcschr(wargv[1], L'*') == nullptr) || (expand && std::wcschr(wargv[1], L'*') != nullptr)) { + std::fprintf(stderr, "FAIL __wgetmainargs(expand=%d): argc %d, want %d\n", expand, wargc, want); + ++failures; + } + } + int argc = 0; + char** argv = nullptr; + wchar_t** wargv = nullptr; + if (narrow_fn(nullptr, &argv, nullptr, 0, nullptr) == 0 || narrow_fn(&argc, nullptr, nullptr, 0, nullptr) == 0 || + wide_fn(nullptr, &wargv, nullptr, 0, nullptr) == 0 || wide_fn(&argc, nullptr, nullptr, 0, nullptr) == 0) { + std::fprintf(stderr, "FAIL __getmainargs/__wgetmainargs accepted a null argc or argv\n"); + ++failures; + } + for (const auto& f : files) DeleteFileW(f.c_str()); + RemoveDirectoryW(dir.c_str()); +} } // namespace int main() { @@ -234,6 +287,7 @@ int main() { check_import_names(); check_argv_reset(); check_getmainargs_environment(); + check_getmainargs_expand(); check_winmain(L"game.exe", {L"-foo", L"with space"}, L"-foo \"with space\"", "arguments after a plain name"); check_winmain(L"C:\\My Games\\game.exe", {L"-x"}, L"-x", "a quoted program name with a space"); check_winmain(L"game.exe", {}, L"", "no arguments"); -- cgit v1.2.3