Repository navigation
RT-115: gta6rt --run runs the game's atexit handlers and static destructors - #2152
Conversation
|
Independent Windows check of
Synthetic inputs only. AI-assisted testing. |
f3a1417 to
d50114e
Compare
|
Independent Wine/Proton check of
AI-assisted (Claude-Opus). |
…uctors 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>
run_tiny_atexit compared `gta6rt --run` with the native run. Under Wine the native leg uses Wine's own CRT, which differs from Windows in two places (it drops a handler registered while handlers run, and its _exit from a second thread does not wait for the exit lock), so the test failed there although --run gave the Windows sequence (reported on ItsNotRexed#2152). --run is now held to the expected sequence directly. On Windows this is the same check, since the native run must match that sequence too. With RUNNER set (Wine), a native difference is reported without failing. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
d50114e to
b40df7a
Compare
|
Thanks for the Wine/Proton check, @kmorales13. That's the part I couldn't test here. You were right that the native leg was the problem, and b40df7a does what you suggested without needing Also rebased on main |
|
Tested b40df7a on Windows 11 (MSVC RelWithDebInfo): full runtime build, then ctest for the shim/loader tests (loader, pe_loader, loader_tls, dll_thread_calls, unimplemented_policy, startup_trace, xmem, process_cmdline, file_system, winhttp_offline, xgameruntime, run_tiny_*, allocator_proxy) — 26 of 26 passed. AI-assisted. |
Claimed in the coordination issue as: RT-115 (claim, status)
Depends on: #1895
(No code dependency: RT-119 and this PR both edit
runtime/shims/process.cpp. Merged together there is one conflict, inrun_entry, where #1895 adds the stack-size line and this PR adds the table reset; keeping both lines is the whole resolution. Checked below.)What and why
Under
gta6rt --run, the mapped EXE registered itsatexithandlers and static destructors with the host CRT's process-wide table (through_crt_atexit), which it shares with gta6rt.main.cppends withExitProcessso that table is never run, so the game's handlers never ran;shims/process.cppdocumented this. Measured with a stand-in program: nativelyreturnandexit(7)print the handlers' and destructors' lines; under--runnone appeared (exit codes matched)._cexit()only looked right by accident: it ran the shared table, gta6rt's own handlers included.runtime/shims/process.cpp:_crt_atexit(UCRT; MSVC'satexitand static destructors reach it) and msvcrt'satexit/_onexitregister into a table of the run's own.exit()runs it newest first, including handlers registered while it runs (as the UCRT does), then ends the run.exit()again from a handler ends the run with that code._exit,_Exit,quick_exit,ExitProcessandabortrun no handlers.exit,_exit,_Exitandquick_exitfrom a second thread wait while the first thread is leaving (natively,_exitfrom another thread duringexitwaits for every handler; before this the run ended mid-handler)._cexit()runs the table and flushes the streams, then returns;_c_exit()returns.run_entrystarts with an empty table and no exiting thread, so a run never sees another run's handlers. A registration that cannot be stored (out of memory) returns -1 / NULL instead of throwing into the game.Not covered yet (documented in the file and
runtime/README.md):at_quick_exithandlers (quick_exitruns none) and the thread-local destructor callback (_register_thread_local_exe_atexit_callback); both still reach the host CRT.Tested
New
run_tiny_atexit(CTest;test/check_atexit.cmake+test/fixtures/tiny_atexit.cpp): a stand-in program run natively and through--runforreturn,exit(7),_exit(8),quick_exit(9),ExitProcess(10),_cexit(),_c_exit(), and_exit()from a second thread whileexit()runs a handler. Both runs must print the same lines and end with the same exit code, and the native run must match the sequence written in the script, so the two cannot agree on a wrong answer. One handler registers another during exit. It goes throughCMAKE_CROSSCOMPILING_EMULATORlikerun_tiny_async.return,exitandc_exitfailed (handlers and destructors missing); the native runs matched the written sequences.f847748c+39d3ab8c+b40df7a5; rebases only touched theruntime/CMakeLists.txtblocks next to other new fixtures, all kept):run_tiny_atexit20/20 repeats; runtime suite 51/51, 0 failures (46 passed, 5 skipped because they need game files,gameinputdisabled without SDL3).49475796+d50114e2: 45/45, 0 failures (40 passed),run_tiny_atexit20/20. Main4eb6155d+f3a14170: 43/43, 0 failures (38 passed),run_tiny_atexit30/30;mainalone there: 42/42 (37 passed).RUNNERset) the native leg runs Wine's CRT, which differs from Windows (a handler registered during exit is dropped;_exitfrom a second thread doesn't wait for the exit lock), sob40df7a5holds--runto the expected Windows sequence directly and only reports a native difference there. On Windows it is the same check, since the native run must match that sequence too. Checked here by running the script with and without a pass-throughRUNNER: both pass, and a fault that makesexitrun no handlers fails both. Not re-run under Wine on my side; see kmorales13's Wine/Proton check in the comments.process.cppwere each caught byrun_tiny_atexit: handlers oldest first,exitrunning none,_exitrunning them,quick_exitrunning them, registrations during exit dropped,_c_exitrunning them,_cexitrunning none,_crt_atexitleft to the host CRT,_exitignoring the exit lock.0af9b816) merged in as well (onf3a14170):run_tiny_atexit,run_stack_reserve,stack_reserve_shimandprocess_cmdline10/10 each; full suite 0 failures.Windows 11 (build 26300), MSVC 19.51 (VS 2026 Build Tools), Windows SDK 10.0.26100, Ninja, RelWithDebInfo. CPU tests only: no GPU involved, Vulkan tools not built. Not tested here: Wine/Proton (independent checks in the comments: Windows by Ingenioeren, Wine/Proton by kmorales13), MinGW (the msvcrt bindings follow the same contract but no MinGW build was run).
AI-assisted (Claude Code).
Checklist
docs/design.md, with how it was confirmed. (Not applicable: no translator change.)