upleb.uk

Public git repos — served from a NIP-34 GRASP relay at git.upleb.uk

summaryrefslogtreecommitdiff
path: root/runtime/test/process_cmdline_test.cpp
diff options
context:
space:
mode:
authorTyrannys <80750971+Tyrannys@users.noreply.github.com>2026-11-27 18:25:47 -0600
committerTyrannys <80750971+Tyrannys@users.noreply.github.com>2026-11-27 18:25:47 -0600
commitd411fe9b4a3aab2a75dfbed4d6e4f01d758ef668 (patch)
tree6fddc2666fe152d622b034a73741b3436613d582 /runtime/test/process_cmdline_test.cpp
parentd44285197237cfe331684aa150fb9dec4b1d08b5 (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/test/process_cmdline_test.cpp')
-rw-r--r--runtime/test/process_cmdline_test.cpp54
1 files changed, 54 insertions, 0 deletions
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() {
218 ++failures; 218 ++failures;
219 } 219 }
220} 220}
221
222// __getmainargs/__wgetmainargs's `expand` (the CRT's _dowildcard): nonzero expands wildcards in the arguments, as
223// _configure_*_argv's mode 2 does; zero leaves them as typed. A null argc or argv fails instead of being written
224// through. Synthetic files in a temporary folder.
225void check_getmainargs_expand() {
226 using Narrow = int(__cdecl*)(int*, char***, char***, int, void*);
227 using Wide = int(__cdecl*)(int*, wchar_t***, wchar_t***, int, void*);
228 const auto narrow_fn = reinterpret_cast<Narrow>(rt::shims::find("msvcrt.dll", "__getmainargs"));
229 const auto wide_fn = reinterpret_cast<Wide>(rt::shims::find("msvcrt.dll", "__wgetmainargs"));
230 if (!narrow_fn || !wide_fn) return; // check_getmainargs_environment reports it
231 wchar_t temp[MAX_PATH]{};
232 if (!GetTempPathW(MAX_PATH, temp)) {
233 std::fprintf(stderr, "FAIL GetTempPathW\n");
234 ++failures;
235 return;
236 }
237 const std::wstring dir = std::wstring(temp) + L"leonida_getmainargs_" + std::to_wstring(GetCurrentProcessId());
238 CreateDirectoryW(dir.c_str(), nullptr);
239 const std::wstring files[] = {dir + L"\\a1.lx", dir + L"\\a2.lx"};
240 for (const auto& f : files) {
241 const HANDLE h = CreateFileW(f.c_str(), GENERIC_WRITE, 0, nullptr, CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, nullptr);
242 if (h != INVALID_HANDLE_VALUE) CloseHandle(h);
243 }
244 const std::wstring pattern = dir + L"\\*.lx";
245 rt::process::set_command_line(L"game.exe", {pattern});
246 for (const int expand : {0, 1}) {
247 const int want = expand ? 3 : 2; // game.exe and the two files, or game.exe and the pattern
248 int argc = 0;
249 char** argv = nullptr;
250 if (narrow_fn(&argc, &argv, nullptr, expand, nullptr) != 0 || argc != want || !argv ||
251 (!expand && std::strchr(argv[1], '*') == nullptr) || (expand && std::strchr(argv[1], '*') != nullptr)) {
252 std::fprintf(stderr, "FAIL __getmainargs(expand=%d): argc %d, want %d\n", expand, argc, want);
253 ++failures;
254 }
255 int wargc = 0;
256 wchar_t** wargv = nullptr;
257 if (wide_fn(&wargc, &wargv, nullptr, expand, nullptr) != 0 || wargc != want || !wargv ||
258 (!expand && std::wcschr(wargv[1], L'*') == nullptr) || (expand && std::wcschr(wargv[1], L'*') != nullptr)) {
259 std::fprintf(stderr, "FAIL __wgetmainargs(expand=%d): argc %d, want %d\n", expand, wargc, want);
260 ++failures;
261 }
262 }
263 int argc = 0;
264 char** argv = nullptr;
265 wchar_t** wargv = nullptr;
266 if (narrow_fn(nullptr, &argv, nullptr, 0, nullptr) == 0 || narrow_fn(&argc, nullptr, nullptr, 0, nullptr) == 0 ||
267 wide_fn(nullptr, &wargv, nullptr, 0, nullptr) == 0 || wide_fn(&argc, nullptr, nullptr, 0, nullptr) == 0) {
268 std::fprintf(stderr, "FAIL __getmainargs/__wgetmainargs accepted a null argc or argv\n");
269 ++failures;
270 }
271 for (const auto& f : files) DeleteFileW(f.c_str());
272 RemoveDirectoryW(dir.c_str());
273}
221} // namespace 274} // namespace
222 275
223int main() { 276int main() {
@@ -234,6 +287,7 @@ int main() {
234 check_import_names(); 287 check_import_names();
235 check_argv_reset(); 288 check_argv_reset();
236 check_getmainargs_environment(); 289 check_getmainargs_environment();
290 check_getmainargs_expand();
237 check_winmain(L"game.exe", {L"-foo", L"with space"}, L"-foo \"with space\"", "arguments after a plain name"); 291 check_winmain(L"game.exe", {L"-foo", L"with space"}, L"-foo \"with space\"", "arguments after a plain name");
238 check_winmain(L"C:\\My Games\\game.exe", {L"-x"}, L"-x", "a quoted program name with a space"); 292 check_winmain(L"C:\\My Games\\game.exe", {L"-x"}, L"-x", "a quoted program name with a space");
239 check_winmain(L"game.exe", {}, L"", "no arguments"); 293 check_winmain(L"game.exe", {}, L"", "no arguments");