agc_driver_tests: rare heap-corruption exit (0xc0000374) on Windows remains after #2976 #3171
Loading…
Reference in a new issue
No description provided.
Delete branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Imported from boykopovar/AnyPS5. Originally posted by SleglJan on 2026-10-11T00:02:02Z.
What
On Windows,
agc_driver_testsoccasionally ends withSTATUS_HEAP_CORRUPTION(0xc0000374); @Yuva1024's loop reported it as exit 127. #2976 removed one candidate cause and closed #2891, but the exit still occurs with that change applied. I'm opening this as @adriadam10 asked on #2976.Data so far (all from #2891)
BUILD_TESTING=ON, RTX 4060 (617.42).agc_driver_testsran alone, 4 copies in parallel, with no CPU stress:main1476f769: 1 of 240 runs exits 127. With 3 copies in parallel: 0 of 120.mainplus the #2909 change, merged as #2976: 1 of 400 runs exits 127.main, a heap-use-after-free on the first run: a registration-preparation thread reads theShaderDeviceProfile(RecompileCacheKey::append) afterDriver::stophas freed it throughDevicePointer::Reset.The exit still happens with #2976 applied, so a cause remains. Whether the use-after-free was ever one of the causes is open. At about 0.3 %, the Windows rate is too low to tell whether #2976 lowered it.
Next step
A Windows run with full page heap, as queeeef suggested:
gflags /p /enable agc_driver_tests.exe /full. It turns a bad heap write into an immediate access violation, which the crash reporter prints with a backtrace. I have no Windows machine, so I can't run it myself.Related:
0xc0000374exits on Windows in another executable,agc_driver_gated_dispatch_capture, underctest --parallel 6. Neither is traced yet.0xc0000374exits invideo_out_flip_lifetime. It is closed, and its fixes (#2570, #2615) are already in1476f769, so this exit is not that bug.AI-assisted: yes (Claude Code)
Imported from boykopovar/AnyPS5. Originally posted by mrcrapto on 2026-10-11T05:19:58Z.
Additional Windows reproduction data on
mainrevision961b25fe24582361833a90b912eff5793550afdf, which includes the registration-preparation shutdown drain:BUILD_TESTING=ON.agc_driver_tests.exealone: 400 runs, four processes in parallel, no additional CPU stress. Vulkan required; shader disk cache disabled.I did not enable full page heap: the session was non-elevated and Windows Debugging Tools were unavailable. This is therefore a standard-heap reproduction result, not the requested page-heap diagnosis. Zero failures in this campaign do not establish that the rare corruption is fixed. No faulting-write trace or new fix is claimed.
AI-assisted: yes (validation scripts and reporting); tests ran on local hardware.
Validation evidence and reproduction scripts (published by @mrcrapto).
Imported from boykopovar/AnyPS5. Originally posted by Silverash-i8 on 2026-10-11T05:26:18Z.
A possibly useful trigger for this, from my Windows machine tonight: after device losses, the heap-corruption exit stops being rare.
Setup: Windows 11 Home (26200), WinLibs GCC 15.2.0 r7, Release,
main961b25fe(plus #3141, which only touches the relinker), Arrow Lake iGPU (ANYPS5_GPU=Intel, driver 101.8991).Earlier tonight, while testing #2985 on #2832, the iGPU went through a burst of Windows GPU watchdog resets (
LiveKernelEvent 141). Since thenagc_driver_gated_dispatch_capturemostly loses the device on it, even on plainmain, where it passed before. In that state:ctest, 23 runs on961b25feandd31b57a4: 2 passed, 14 failed with device lost, 6 exited0xc0000374, 1 segfaulted.agc_driver_gated_dispatch_capture_tests.exedirectly 8 times just now: 7 exit 1 (device lost), 1 exits 127 (0xc0000374, as in Yuva1024's loop).The last lines differ between the two kinds of run:
So the corrupting write seems to happen on the path after a recorder submission fails and the queue drops its labels, before the test reports and the teardown runs. That might also be what the rare cases hit, if a submission occasionally fails there. The RTX 5060 in the same machine passes
gated_dispatch_capture10/10 with no device loss.I can't run
gflags /p /enable ... /fullright now (it needs an elevated prompt), but I can once I'm back at the machine, and the device-lost state makes it reproducible here in a few runs.AI-assisted (Claude Code); I ran all of this on my machine.
Imported from boykopovar/AnyPS5. Originally posted by mrcrapto on 2026-10-11T06:13:14Z.
Following the submission-failure lead, I isolated a deterministic cleanup defect in
Recorder::Submit(): after moving out the open batch, a failingvkEndCommandBufferorvkQueueSubmitdestroys that batch while leaving its label-table entries, completion counts and Vulkan handles behind. The labels can therefore retain pointers to the destroyed batch.Patch: #3298 (commit). The PR was automatically closed by the current intake policy; the commit remains available for review or cherry-picking.
The patch discards the failed batch without running its completions, preserves earlier submitted batches, and waits for device idle before releasing resources after queue-submit device loss, following the Vulkan lost-device rules. The initial two-case injected regression failed on unchanged code with 14 failed assertions. All six final failure variants pass, including both allowed idle-wait results and preservation of an earlier batch.
On the final
de129cfdbase, NVIDIA RTX 4060 Laptopagc_driverand gated-dispatch capture pass. On the initiald7cfa728base, Intel UHD gated-dispatch capture returned device loss twice with the patch, while one unchanged-code comparison passed. The Intel cause remains unresolved. Full default Windows compilation, the relevant runtime library/test targets and the conventions check passed.This is not a confirmed fix for the reported heap corruption or Intel device loss; I have no page-heap faulting-write trace. It is a separately reproduced cleanup defect on the error path you identified.
Regression and validation logs. AI-assisted: yes; tests ran locally.
Imported from boykopovar/AnyPS5. Originally posted by Silverash-i8 on 2026-10-11T06:28:33Z.
@mrcrapto thanks, I ran your commit in the device-lost state I described, since it reproduces here in a few runs. Same machine and Arrow Lake iGPU,
agc_driver_gated_dispatch_capture_tests.exerun directly 24 times each:0xc0000374)de129cfd(your base)e487ff00(your commit)So in this state the heap-corruption exit is still there with the patch. 2 vs 5 out of 24 is noise at this sample size, so I'm not reading anything into that difference. The cleanup defect you found looks real to me; it just isn't the one this repro hits.
Every
0xc0000374run, with and without the patch, ends on the same line, and the test's ownthe gated submissions did not finishnever prints:That message comes from the
Clearguard's destructor inDriver::recordDeferredLabels(Execution/src/Driver/Synchronization/DeferredLabels.cpp:104), so it runs while an exception from the label loop (WriteLabelOnGpu,WaitIdle,GuestMemory::WriteornoteLabelStoreafter the device is lost) is unwinding. Right after the print it doeslabels.clear(),Recorder::CloseLabelGroup(0)andRecorder::ForgetQueuedLabels(). Since stderr is unbuffered and nothing else gets printed, the corrupting write is probably in one of those three steps, or in a destructor that runs during the same unwind. That's a different path from theRecorder::Submit()one your commit fixes, which may be why it doesn't change this.The page-heap run is still on my list for when I have an elevated prompt.
AI-assisted (Claude Code); I ran all of this on my machine.
Imported from boykopovar/AnyPS5. Originally posted by Silverash-i8 on 2026-10-11T06:46:03Z.
Correction to my last comment: I added probe prints, and the corruption isn't in those three cleanup steps. On
de129cfd, first with prints afterlabels.clear(),CloseLabelGroupandForgetQueuedLabelsin theCleardestructor (16 runs, 3 heap-corruption exits), then also at the queue worker'scatch (...)entry, after the flip failures and afterReportFailureinQueueWorker.cpp(26 runs, 2 heap-corruption exits). All 5 heap-corruption runs printed every probe their build had, same as the device-lost runs that exit normally.So the destructor finishes, the exception reaches the worker's
catch (...), andReportFailurereturns. The process dies after that and before the test's ownthe gated submissions did not finish, so somewhere between the worker reporting the failure and the main thread getting it back. The heap is only checked at the next allocation or free, so that's where it's noticed, not necessarily where the bad write happens.So the page-heap run is really the next step; prints won't narrow it much further. I'll do it when I have an elevated prompt, with this device-lost state as the reproducer.
AI-assisted (Claude Code); I ran this on my machine.
Imported from boykopovar/AnyPS5. Originally posted by zaydzaari on 2026-10-11T11:56:23Z.
Windows full page heap exposed a separate reproducible AGC TLS use-after-free during this investigation. Refs #3171; I have not established that it explains the original rare
0xc0000374exit.Two debugger runs of the unchanged baseline (
06da1176) failed instd::vector<Driver::PendingWait>::~vector. In the second run the object address was0x2415b6c0fe8;!heap -p -aidentified its allocation as already freed. The recorded free stack was:The subsequent access came through
vector<PendingWait>::~vector -> run_dtor_list -> tls_callback -> LdrShutdownThread. This establishes that emutls cleanup freed the vector object's storage before the DLL TLS callback invoked its C++ destructor. The evidence supports a use-after-free of the object itself; it does not establish a double free or heap overwrite.The authored correction is c32d7e3f92fd34f2e3da14510dbfcb9ae0dc0076, on
fix/agc-thread-local-teardown-current, based on upstream0f863c10. It applies the existingShaderRecompiler::ThreadOwnedandHostThreadLocalhelpers to the remaining affected wait vector, dispatch map, image memo, recorder scratch vectors, and precise-wait timer. This follows the lifetime approach used in #590. The seven-file patch also adds a MinGW object-symbol regression guard against__cxa_thread_atexitregistrations, using a generated manifest to avoid Windows command-line limits.Local Windows 11 / MinGW-w64 GCC 15.2.0 Release validation:
agc_driverandagc_driver_registration_prepare_shutdown: each passed 10/10 repetitions. Conventions and Git whitespace checks passed.The guard can be run with
ctest --test-dir <build> -R '^agc_driver_thread_local_destructors$' --output-on-failure. These results eliminate the demonstrated TLS failure in the tested cases, but do not prove complete resolution of #3171 or the reported device-loss scenario. Full CI and independent Linux validation remain outstanding.Claude Code and Codex assisted with implementation, review, and testing. Would a maintainer consider reviewing or carrying this patch, preserving the original authored commit where possible?
Imported from boykopovar/AnyPS5. Originally posted by screamm on 2026-10-11T13:01:29Z.
More data points: on this Windows 11 Pro 26220 host (WinLibs GCC 15.2.0 r7, Release, RTX 4070 driver 32.0.15.9621, 16 CPUs)
agc_driverhit the0xc0000374exit in about one of threectest -j8suite runs today across unrelated branches onmain0c617baetoa11c8f7f(six runs, no message before the exit, roughly 4 to 5 s in); run alone it failed once on the first repeat and then passed 3/3 twice on the same binaries. So the rate is higher than rare under parallel load here. Written with Claude Code assistance.Imported from boykopovar/AnyPS5. Originally posted by AlxcBTW on 2026-10-11T13:09:03Z.
@zaydzaari's finding is the cause, and I think it also explains the rare suite exits. I got here from #2980 (
agc_driver_draw_cache_reusecrashing on Windows + NVIDIA) and ended up at the same stack.Reproduction without page heap. Started under cdb, which turns on the debug heap's tail and free checks,
agc_driver_draw_cache_reusestops withc0000374in every run: 127 of 127, on Windows 11, WinLibs GCC 15.2.0 and an RTX 5070 Laptop. It stops asDriver::stopjoins the queue worker:pthread_create_wrapper→LdrShutdownThread→tls_callback→run_dtor_list→freeThat is after winpthread's key cleanup already ran
emutls_destroy. A ten-line DLL with athread_local std::vectorused from astd::threadfails the same way, and passes once the vector lives inHostThreadLocal. So this is MinGW's TLS teardown order, and any worker thread that ends can hit it.Why it fits the reports here.
ctest -j8runs: everyagc_driverprocess ends its workers, and load decides whether the stale free lands on a block in use.Driver::runreturns from itscatch (...)right afterReportFailure, so the worker ends exactly where the process died. I haven't reproduced that state, so that part is a fit, not a proof.The fix, extended. The same pattern is outside the driver too:
random_device;PreciseSleepUs's timer, whose destructor also closed a stale handle.AlxcBTW/AnyPS5
fix/thread-local-teardownmoves the driver objects from @zaydzaari's c32d7e3f plus these toHostThreadLocal. It addsprx_thread_local_destructors, a MinGW-only test that checks all 122 built modules for__cxa_thread_atexitregistrations outside libc's guest destructors. On main it fails on libSceRandom.Results with it:
agc_driver_draw_cache_reuse: clean in 43 of 43 cdb runs.agc_driver_tests: clean in 6 of 6.agc_driveron NVIDIA: 295 of 295.mainalready does (#3411, #3459, #3460).@zaydzaari found it first, so if you'd rather extend c32d7e3f, take whatever helps from the branch.
AI-assisted: yes (Claude Code)
Imported from boykopovar/AnyPS5. Originally posted by Amoenus on 2026-10-11T13:28:34Z.
Additional deferred-undecodable serial reproduction on Windows (2026-10-11)
Reproduced
STATUS_HEAP_CORRUPTION(0xc0000374) in a different small execution case,agc_driver_prepared_shaders_deferred_undecodable/agc_driver_prepared_shaders_tests.exe --deferred-undecodable.a11c8f7f. It includes our kernel/math/D64 and experimental sampled-MSAA changes. This is not an unchanged-main control and does not establish their involvement or independence. The PreparedShaders.cpp test source is unchanged froma11c8f7f.Last line in the serial failed run:
The test's final
deferred undecodable shader tests passedmarker is absent. There is no device-loss message in that failed log. This identifies the last observed output, not the faulting write or cleanup function.Reproduction after building this integration:
At that checkpoint there was no debugger/full-page-heap trace or corrected-build comparison. I have read the independently traced TLS findings and fork fixes above; I have not validated them against this case, and am not claiming a shared cause. Reporting here to avoid a duplicate heap-corruption issue. Raw CTest logs/XML are retained locally; the exact failure excerpts and commands are supplied above. No PR created. AI-assisted investigation/reporting: Codex.
Exact-main control follow-up
On unchanged main
a11c8f7f, separate serial--repeat until-fail:20 --parallel 1 --timeout 30campaigns now reproduce0xc0000374inagc_driver_prepared_shaders_debug,agc_driver_prepared_shaders_deferred_undecodableandagc_driver_prepared_shaders_deferred. Same supported WinLibs r7/RTX 5080 environment, Vulkan required and cache disabled; no MSAA integration or game execution required. These are exit-signature matches, without a faulting-write trace or shared-cause claim. Independent #3661 peer/main controls separate the passing focused tests from the remaining heap failures. Raw commands, logs and XML are retained locally.Corrected integration follow-up (2026-10-12)
The three production changes from #4029 are now applied locally on pinned maina672 integration, with author credit. Its original module-destructor scanner passes all122 unpatched modules; the preserved original AGC module fails it. All five selected heap cases pass ×20 (100/100), and the full suite records863pass/0fail/5skip. Commands, exact commit scope and limitations. Before applying it, this machine again reproduced heap exits in parallel debug and sequential deferred-undecodable runs. No local debugger teardown trace, Linux runtime or unchanged wholePRhead claim; finite clean campaigns do not prove all rare crashes absent. No push/new PR.
Imported from boykopovar/AnyPS5. Originally posted by Silverash-i8 on 2026-10-11T13:33:28Z.
Here's the page heap run I promised. It points at @zaydzaari's finding for the
0xc0000374exits in my repro too (@AlxcBTW could only call that a fit), and AlxcBTW's branch makes the fault go away.Setup. Windows 11, WinLibs GCC 15.2.0 r7, Release,
main0f863c10(the base of AlxcBTW's branch),agc_driver_gated_dispatch_capture_tests.exeon the Arrow Lake iGPU (ANYPS5_GPU=Intel,ANYPS5_NO_SHADER_CACHE=1). That's the run that gave0xc0000374in roughly one of five to eight runs after the device-lost path. No gflags or cdb here, so I set full page heap through Image File Execution Options for that executable (GlobalFlag0x02000000,PageHeapFlags3) and read the test's own crash report.On
main: 4 of 4 runs fault at the same instruction. Under page heap none of them reached the device loss: each logs aWAIT_REG_MEM ... timed out after 1000msand then faults while the driver shuts down, before the test reports a result:With the module's symbols (
nm, nearest preceding symbol):+0x6399d3isstd::vector<AgcDriver::DriverDetail::Driver::PendingWait>::~vector()+0x3, thestatic thread_local std::vector<PendingWait> waitsinWaitMemory.cpp:57+0x5cc906istls_callback+0x16d, and the stack also holdsrun_dtor_list+0x43 (bothtls_atexit.c)The read hits memory page heap has already freed. In all four reports the main thread is in
Driver::Shutdown()and another thread is inReleaseThreadMain(), so the faulting thread is a worker ending at shutdown. That's the same~vector -> run_dtor_list -> tls_callbackpath zaydzaari traced. Without page heap the stale free usually goes unnoticed, which fits the rare0xc0000374I saw at the end of runs, after the device loss, and screamm's suite-level rate.With AlxcBTW's
fix/thread-local-teardown(20dfb170), page heap still on: 6 of 6 runs end without a fault. Three passed. Three hit the device loss (dropped 1 queued labels, "the gated submissions did not finish", exit 1) and still shut down cleanly.Then without page heap, 20 runs of the branch: 18 passed, 2 took the device-lost path and exited 1, none exited with
0xc0000374. On its own that's weak, since the iGPU passes most runs today, so few of them reach the exit that corrupted the heap. The page heap comparison is the real evidence.I haven't looked at @Amoenus's
--deferred-undecodablecase; it isn't covered by any of the above.AI-assisted (Claude Code); I ran all of this on my machine.
Imported from boykopovar/AnyPS5. Originally posted by kr4y4 on 2026-10-11T17:27:57Z.
Another Windows reproduction, and a check of @AlxcBTW's
fix/thread-local-teardown(20dfb170).Setup: Windows 11 (26200), WinLibs GCC 15.2.0 r7, Release, an RTX 4070 Laptop GPU and an Intel Raptor Lake-S iGPU. Each executable is started under the WinLibs
gdb(gdb -batch -ex run), which turns on the debug heap's checks.On
maina11c8f7f(RTX 4070), these stop withCritical error detected c0000374every time:agc_driver_dword_pattern_fillagc_driver_draw_cache_reuseagc_driver_prepared_shaders --deferredagc_driver_compute_user_data_callsEvery stack is
_endthreadex→LdrShutdownThread→tls_callback→run_dtor_list→freeinlibSceAgcDriver.prx, the same as above. A test that only callsRecompileandVulkanDevice::Dispatch, with no driver worker threads, is clean.libSceAgcDriver.prxhas 121__emutls_v.*objects; the ones that own memory includeRecorder::refreshDrawSnapshot's five vectors andDriver::pendingWaits'swaits.Without a debugger, the bug shows up as rare exits. With 8 copies of
agc_driver_prepared_shaders --deferredstarted at once on the RTX 4070, 2 of 64 runs exited with0xc0000374(exit 127 in Git Bash) onmain. The same happened in the--registeredmode ofagc_driver_compute_user_data_calls(#3294), 2 of 64 runs.On the branch:
dword_pattern_fill,draw_cache_reuseandprepared_shaders --deferredreport no heap corruption on either GPU.compute_user_data_callsand its--registeredmode are clean on the RTX 4070.--deferred: 0 failures in 64 runs.Written with AI assistance.
Imported from boykopovar/AnyPS5. Originally posted by AlxcBTW on 2026-10-11T17:28:56Z.
@kr4y4 thanks, that's a clean check: four tests that fail every time under gdb on
mainare clean on the branch, and 0 of 64 against 2 of 64 for the 8-way run.I'll open
fix/thread-local-teardownas a PR as soon as #3546 is merged; until then the intake rules allow me one open PR. If someone wants to carry it sooner, 20dfb170 is ready.AI-assisted: yes (Claude Code)
Imported from boykopovar/AnyPS5. Originally posted by AlxcBTW on 2026-10-11T21:36:44Z.
Opened as #4029 (
fix/thread-local-teardown-2, rebased ontomaina11c8f7f7), with @Silverash-i8's and @kr4y4's checks linked. Thanks both.AI-assisted: yes (Claude Code)
Imported from boykopovar/AnyPS5. Originally posted by oneandonlydean on 2026-10-12T06:17:03Z.
Closing: fixed by #4029 (thread_local objects with destructors no longer run in module teardown on Windows) together with #3661. Reopen with the stack if
0xc0000374still shows up on a build that has both.