upleb.uk

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

summaryrefslogtreecommitdiff
path: root/runtime/shims/process.cpp
AgeCommit message (Collapse)Author
7 daysMerge pull request #2522 from Tyrannys/rt-com-null-barriers-entryMoonEyes
d3d12, process: null barrier arrays, CopyTiles in a bundle, calibration wait, entry thread argument, getmainargs expand (RT-COM-NULL-BARRIERS-ENTRY)
8 daysd3d12, process: null barrier arrays, CopyTiles in a bundle, calibration ↵Tyrannys
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>
8 daysmain keeps its own runtime, tools and tests; the branch's variants stay on ↵NotRexed
port/d3d12-nvidia After the merge the tree held this branch's older states of files main maintains. Run against main's code, tests/test_acphal_abi.py and 11 of the 15 translator tests that differed failed, and the C++ runtime would have been built from two generations of its sources. So that the merge cannot break what main builds and tests: - runtime/ is main's, file for file (68 files only this branch had are not carried over); - every file under tools/, tests/ and docs/ that both sides have is main's (80 files); - ten translator tests only this branch has, which test rules main's translator does not have, and their fixtures are left out. What main gains: d3d12/ (the Rust D3D12 runtime), its launchers and helpers (Launcher.bat, scripts/play*.ps1, play-linux.sh, port_ctl.py, smooth-motion.ps1, fetch_vkd3d_proton.py, sync_victory.py), mods/example_lua, eleven notes under docs/, seven tools and the tests that pass with main's code, the README's sections and credits, and the "Runtime traps" section of AGENTS.md. Everything left out here is on the branch port/d3d12-nvidia. Checked: compileall; make_game.py --help; check_no_game_data.py over every file this adds to main; the line-ending, docs-encoding, CI-registration and docs tests; each test file that differs from main, on its own. Not run: the whole translator suite, the C++ build, cargo over d3d12/ after the merge (d3d12/ is byte for byte the branch's), CI. Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
8 daysMerge mandy's main into port/d3d12-nvidiaNotRexed
Brings the D3D12 runtime branch (d3d12/, its launcher scripts and notes, and the pull requests reviewed and applied on it) together with mandy's main. Conflicts (67 files, none under d3d12/): docs/, make_game.py, runtime/, scripts/build_runtime.ps1, tests/ and tools/. Every one takes main's side: main is where that code is maintained, and this branch's copies were older states of the same files or the same pull requests in another form. tests/test_fspx_unpack.py is main's too, as it tests main's tools/fspx_unpack.py. Nothing under d3d12/ is changed by the merge. Checked before pushing: python -m compileall over make_game.py, tools and tests; make_game.py --help; scripts/check_no_game_data.py over the files this adds to main; tests/test_text_write_line_endings.py. The translator suite, the C++ runtime build and CI have not run on the result. Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
8 daysprocess: the run's cleanup holds one lock, as the UCRT's exit lock; a ↵Mike7581
throwing handler terminates Review follow-up for #1564: - Registration and the cleanup of exit, quick_exit and _cexit hold one recursive lock of the run's own, from before the thread-local callback through the table's drain (and _cexit's stream flush), as the UCRT holds its exit lock: two threads never clean up at once, and a registration from another thread waits for the cleanup. The exiting thread may still register from a handler, _cexit still returns, and the lock is released before the run ends (end_run), also when a handler ends the run from inside a drain. - Each guest cleanup callback (atexit, at_quick_exit, the thread-local destructor callback) runs inside a C++ exception boundary: one that throws ends the run through game_abort, as the UCRT's terminate() would (exit code 3), instead of leaving the process with 0xE06D7363. tiny_atexit gains four modes, held to the native sequence: concurrent_cexit (a second thread's _cexit, with a thread_local of its own, waits for the cleanup), quick_exit_register (an at_quick_exit from a second thread during a quick_exit drain waits, so its handler never runs), quick_exit_throw and exit_throw (exit code 3). In the concurrent modes the slow handler waits until the second thread is about to call, so the sequence is fixed under any scheduling with the lock. All four fail on c5b51e9 through --run.
8 daysprocess: the game's at_quick_exit handlers and thread-local exit callback ↵Mike7581
are the run's own The game's at_quick_exit() (_crt_at_quick_exit) and _register_thread_local_exe_atexit_callback still reached the host CRT, which the game shares with gta6rt. Under `gta6rt --run`: - quick_exit() ran none of the game's at_quick_exit handlers; - exit() and _cexit() never ran the exiting thread's thread_local destructors, and a second registration in the host's one-slot callback would terminate gta6rt. Now _crt_at_quick_exit goes to a second table of the run's own, which quick_exit() runs newest first under the exit lock; _exit() and _Exit() run none (they no longer share game_quick_exit). The thread-local callback is the run's own: exit() and _cexit() call it with DLL_PROCESS_DETACH before the atexit handlers, as the UCRT does, and a second registration aborts, as the UCRT's terminate() does. Both reset per run. tiny_atexit gains five modes (at_quick_exit, at_quick_exit_exit, at_quick_exit__exit, thread_local_exit, thread_local_cexit). Their expected sequences in check_atexit.cmake were measured by running the fixture natively on Windows 11; before this change --run differed on at_quick_exit, thread_local_exit and thread_local_cexit. run_tiny_atexit now holds 13 paths to the Windows sequence.
9 daysprocess: call the EXE's thread-local destructor callback with its real ↵Jan Trencansky
signature, before the atexit handlers (maintainer fix on #2315) #2315 kept `_register_thread_local_exe_atexit_callback` away from the host UCRT, which fast-fails a second registration in the process (gta6rt's own startup makes the first). Review points fixed on top: - The callback is a `_tls_callback_type` (UCRT process.h: `void (__stdcall*)(void*, unsigned long, void*)`), not `void (*)()`: vcruntime's TLS destructor callback reads its reason argument, which was left as whatever rdx held. It is now called as `(nullptr, DLL_PROCESS_DETACH, nullptr)`, as the UCRT does. - `exit` and `_cexit` call it before the atexit table, as the UCRT does: the leaving thread's thread_local objects end before the static ones ([basic.start.term]). #2315 ran it after the static destructors, and not in `_cexit`. - The extra call on every thread detach is dropped, with the per-thread flag and the loader's include of the process shim: the loader already calls the same function from the executable's TLS directory with DLL_THREAD_DETACH, and the UCRT never calls the registered one there. The call after a returning entry point is dropped too (MSVC's mainCRTStartup calls exit itself). - run_tiny_atexit gains thread_local_exit and thread_local_cexit: a thread_local object of the main thread must end before the handlers and destructors. On main the --run path never ends it (Wine) or stops at the second registration (Windows). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
9 daysruntime: own the executable TLS exit callbackZroFreaks
9 daysprocess: log the title's debug output and its TerminateProcessNotRexed
Port VIctory's kernel.rs (GPL-3.0-or-later) OutputDebugStringA/W and TerminateProcess: the title's debug strings go to stderr as "[title] ..." (LEONIDA_TITLE_DEBUG_OUTPUT=0 silences them; the host still gets them for an attached debugger), and a TerminateProcess of the game's own process is logged with its code and caller before it is done, instead of ending gta6rt without a word. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
12 daysfixup: #6942 tests need fcntl/io and an explicit empty-mask refusalKam471
(cherry picked from commit 6680cd1afce95352e428f2bf7f5772a1ab3cf936)
12 daysfix: SetThreadGroupAffinity answers a GROUP_AFFINITY of absent cores or ↵tedin7
groups with the thread's own affinity, served under kernel32, kernelbase and every processtopology API set (retail exe imports it; reported by dadsmallbuk1 on #6942) (cherry picked from commit fc4de7d2272a43dcdb0cc8eed83d6821c36f117e) (cherry picked from commit bbee83abfc1afe5b44ef9bc56c52ea517f6afa86)
12 daysruntime: honor mapped executable argv startup modes (#6117)Hiiva
Squash-merged after diff review of PR #6117
13 daysMerge pull request #4043 from AAyberkUItsNotRexed
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
13 daysMerge pull request #3928 from sds-228ItsNotRexed
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
13 daysprocess shim: the game thread that ends a run no longer exits the process ↵AAyberkU
before gta6rt finishes end_run signalled g_done and only then read g_running. run_entry wakes on g_done, closes it and clears g_running, so the game thread could read false and take the "run is already over" path: ExitProcess with the game's code while main.cpp was still printing "game exited with code N", reporting unimplemented imports, writing the trace "exit" event and cleaning up TLS clones. The exit code stayed right, but the lost line made run_startup_cmdline and the other checks that look for it flaky. end_run now reads g_running before it signals. g_running is set before the game thread starts and is cleared only after g_exited is claimed and g_done is set, so a read taken before the CAS is true for any thread that ends a live run. The exit during host shutdown (no run active) still calls ExitProcess, and so does an exit with no run started, which an "always park the CAS winner" fix would have hung. process_cmdline_test runs 50 entry points that return 77 on one CPU and fails (exit 77) without the fix. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
13 daysruntime: raise SIGABRT from the guest's abort() when a handler is installedsds-228
game_abort() ended the run directly, so a title's own SIGABRT handler never ran. Raise SIGABRT only when a handler is registered (the guest's signal() import binds to the host CRT), leaving the default and ignored cases ending with code 3 so the host is never killed. Add a synthetic fixture with handler, returning-handler, ignore and default modes plus a native-vs-loader exit-code test. AI-assisted (OpenCode)
13 daysMerge pull request #2152 from mzItsNotRexed
13 daysRT-115: gta6rt --run runs the game's atexit handlers and static destructorsmz
The mapped EXE registered atexit handlers and static destructors with the host CRT's process-wide table, which gta6rt never runs, so they were lost. They now go to a table of the run's own: exit() and a return from main run it newest first (including handlers registered during exit), _cexit() runs it and returns, and _exit/_Exit/quick_exit/ExitProcess/abort skip it, as natively. exit/_exit/_Exit/quick_exit share an exit lock like the CRT's, each run starts with an empty table, and a failed registration returns an error instead of throwing into the game. New run_tiny_atexit compares a stand-in program run natively and through --run for 8 termination paths. Not covered yet: at_quick_exit and the thread_local destructor callback. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
13 daysfix(process): close g_done race, guard CreateEventW, and preserve ExitThread ↵totonii
code in run_entry
13 daysruntime: RT-136 review follow-up: check the test's setup, say what the ↵pwu2775-dev
returned table is valid for process_cmdline_test now checks the return values of _putenv_s/_wputenv_s and says when _wenviron already exists at startup, so the first-call check cannot pass silently without exercising the lazy wide-table creation. process.cpp notes that the returned table is the CRT's own and valid until the next _putenv, as with the msvcrt.dll original.
13 daysruntime: __getmainargs/__wgetmainargs read the host environment at call time ↵pwu2775-dev
(RT-136) set_command_line kept _environ/_wenviron pointers. The host CRT has no wide environment until a wide environment function first runs, and _putenv/_wputenv reallocate both tables, so a wide-character startup calling __wgetmainargs got a null or dangling environment. The shims now read the tables when asked and make the CRT create a missing one first. process_cmdline_test covers both functions: the first wide call, and variables set before and after set_command_line.
13 daysRuntime: serve the game's command line and ExitProcess under every import namedracbat
The UCRT's _get_narrow_winmain_command_line and _get_wide_winmain_command_line were not shimmed, so a /MD WinMain executable got gta6rt's own command line as lpCmdLine. GetCommandLineA/W and ExitProcess were shimmed under kernel32.dll only, and the loader matches DLL names exactly. Imported from kernelbase.dll, or from the API sets the umbrella libraries bind them to (api-ms-win-core-processenvironment-l1-1-0, api-ms-win-core-processthreads-l1-1-0), they went to the host. The package's vcomp140.dll imports ExitProcess from the latter. process_cmdline_test checks every name and the WinMain line. docs/runtime_imports.md: the dry-run table regenerated at this commit. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
13 daysprocess shim: keep the game's command line wide so a non-ASCII argument ↵Emre Demir
can't crash --run (RT-84) main.cpp turned each game argument into std::filesystem::path::string(), which throws std::system_error under MSVC when the ANSI code page has no mapping for a character. Nothing caught it, so gta6rt --run ended in 0xc0000409 before the game started. set_command_line now takes wide strings: __wargv and GetCommandLineW hold the arguments exactly, and the narrow argv and GetCommandLineA are their CP_ACP text from WideCharToMultiByte, which replaces a character the code page lacks instead of failing, as the CRT does. process_cmdline_test passes wide arguments and checks a Latin-1 one and a Greek, Cyrillic and CJK one that no single-byte code page holds, so the crash is covered on every system locale, not only 1253.
13 daysMerge pull request #1039 from sanuk369ItsNotRexed
13 daysprocess: the command line parses back to __wargv (backslash rules, ANSI code ↵sanuk369
page) quote() escaped quotes but ignored CommandLineToArgvW's backslash rules, so GetCommandLineA/W and __argv disagreed for an argument ending in a backslash ("C:\My Games\" next" parsed back as 2 arguments, not 3) or holding a backslash before a quote. A backslash run before a quote, or before the closing quote, is now doubled. widen() decoded the arguments as UTF-8, but main.cpp passes std::filesystem::path::string(), which is ANSI code page text, so cafe with an accent reached __wargv as caf\uFFFD. It widens from CP_ACP now; under a UTF-8 activeCodePage that is the same thing. New process_cmdline_test (ctest process_cmdline) checks that GetCommandLineW parses back to __wargv.
13 daysprocess: park game threads that end the run until the host exitsKevin Morales
Under Wine before 11.2, gta6rt --run sometimes exited 0 although the game ended with 1 (run_tiny_game_exit_code in CI's Wine 9.0 job: 13 of 64 runs). end_run signalled the host and called ExitThread; the host's ExitProcess could then send SIGQUIT to that thread while it was exiting, Wine counted the thread out twice and the process ended with _exit(0). Upstream fixed it by blocking SIGQUIT during thread exit (4a9bc42a, wine-11.2). end_run now parks every caller while a run is in progress (the first one after recording the code and signalling), so no game thread is mid-exit when the host calls ExitProcess. This also fixes two threads calling exit at once: the second one called ExitProcess itself, sometimes before the first had stored its code, and ended the process with 0 on any OS. CI requires run_tiny_game_exit_code again.
14 daysruntime: shim the Debug UCRT (ucrtbased.dll) for the game's argv and exitisaactouzani34100
A Debug build of the stand-in game links ucrtbased.dll rather than ucrtbase.dll. The process shim only covered api-ms-win-crt-runtime and ucrtbase, so __p___argc/__p___argv went to the host CRT. The game then got gta6rt's own arguments (argc=6) and run_tiny_game failed in the Debug configuration, which is the Visual Studio generator's default.
14 daysruntime: rename shims/process.h to process_shim.h (it hid the CRT's ↵ItsNotRexed
<process.h> from <thread>) With runtime/shims on the include path, <thread>'s #include <process.h> found #316's header, so _beginthreadex was undeclared in d3d12_com.cpp. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
14 daysRuntime: gta6rt --run, and a stand-in game executable run through the loaderIAmNotSiob
gta6rt --run <exe> [-- args] maps and binds the executable, initialises its modules and calls its entry point on a game thread. shims/process.cpp answers the process-level imports through the game's own import table: argv/argc and GetCommandLine are the game's (UCRT api-set/ucrtbase and msvcrt forms), and exit/_exit/quick_exit/ExitProcess/abort end the run with that exit code instead of the host. gta6rt then exits with the game's code directly, so the game's atexit handlers don't run during host shutdown. tiny_game.exe (CTest run_tiny_game, run_tiny_game_exit_code) does what a title does in its first second: arguments, a static initializer, a 4 MiB allocation, a file round trip, a thread, and xgameruntime.dll imports, which the shim registry answers instead of the link-time stub. thread_local and a C++ exception are opt-in (LEONIDA_RUN_TLS / LEONIDA_RUN_EH) until #93 and #176.