Repository navigation
Conversation
…'s breakpoint address Spacecer2 measured under Wine 11.22 (ItsNotRexed#7599) that LEONIDA_SKIP_INT3 never took effect: the flag was a block-scope static first read on a title thread, whose MSVC thread-safe-static guard passed with the object still zero, and the handler's int3 set and the trace lock had the same shape. - The flag is read by startup_trace::open(), on the thread that opens the trace, into a constant-initialized atomic. - The trace lock is a constant-initialized SRW lock (no constructor, never destroyed), and the logged int3 sites are a constant-initialized table of atomics: the handler touches no block-scope static. - The int3 is found from Rip (Windows) or Rip - 1 (Spacecer2's Wine run), and Rip always ends one byte past the 0xCC. - skip_int3 returns false for a null EXCEPTION_POINTERS, record or context. - LEONIDA_LOG_GAME_EVENTS and LEONIDA_HDR, read on title threads, are cached in namespace-scope atomics instead of block-scope statics. int3_skip_test runs each case in a child process: real int3s, the Windows and the Wine breakpoint forms, the null pointers, the flag read at open() and the flag off. The wine, null and init cases fail on main. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
|
Tested Built |
|
AI-assisted review and native Windows / MSVC verification (Gemini). PASS (MSVC Environment
Verification Results
Code Review Notes (Non-Blocking)
|
Claimed in the coordination issue: #7599 (comment) (finding by Spacecer2: #7599 (comment)).
LEONIDA_SKIP_INT3never took effect in Spacecer2's Wine boot. The measurements are theirs (Wine 11.22,main1ce6eb5plus several PRs, #4313 applied); this PR is the fix they described, with tests.The four bugs (Spacecer2's measurements)
skip_int3readLEONIDA_SKIP_INT3into a block-scopestatic const bool. Its first use is on the title's thread, and there the MSVC thread-safe-static guard passed while the object was still zero. Soskipstayedfalseand every guestint3stayed fatal.skip_int3'sstatic std::set<const void*> seen, and the trace lock fromdetail::mutex().ExceptionAddressandRipone byte past the0xCC, so theRip == attest rejected every breakpoint.skip_int3and traced it to a nullEXCEPTION_POINTERS.The change
runtime/shims/startup_trace.h:startup_trace::open()readsLEONIDA_SKIP_INT3into aconstinit std::atomic<bool>. That runs on the thread that opens the trace, before any guest code.detail::mutex()) is aconstinitSRW lock. It has no constructor or destructor, so it stays usable after static destruction, as the old leakednew std::mutexwas. Callers are unchanged (std::lock_guard lock(detail::mutex())).constinitopen-addressing table of 4096 atomics. It needs no constructor, lock or allocation inside the handler. If it fills up, a site is logged again rather than lost.Ripfirst (the Windows form, unchanged), thenRip - 1.ExceptionAddressmust be on that byte or one past it.Ripalways ends atint3 + 1. Each byte is checked withVirtualQuerybefore it is read.skip_int3returnsfalsefor a nullEXCEPTION_POINTERS,ExceptionRecordorContextRecord. The handler already rejected a null pointer or record before calling it.runtime/shims/xgameruntime_offline.cpp:LEONIDA_LOG_GAME_EVENTS(XGameEventWrite) andLEONIDA_HDR(XDisplayTryEnableHdrMode) were the otherLEONIDA_*flags read into block-scope statics on title-thread paths. They are now cached in namespace-scopestd::atomic<int>(-1= not read yet), the patternregistry.cppuses forLEONIDA_UNIMPLEMENTED.docs/boot.mdandruntime/README.mdsay that the flag is read when the trace opens.Tests
int3_skip_testnow runs each case in a child process of its own, so a crash fails only that case and each case gets its own environment:mainreal__debugbreak()at two sites, one hit twice: execution continues, 2 eventswindowsEXCEPTION_POINTERSwithRip == aton a0xCCbuffer:Rip == at + 1, one event namingat; not skipped when there is no0xCCorExceptionAddressis elsewherewineExceptionAddress == Rip == at + 1, andExceptionAddress == atwithRip == at + 1: both end atat + 1, one event namingatnullEXCEPTION_POINTERS, null record, null context:false, no crash0xc0000005inskip_int3)initint3is still skippedoffx86_64-w64-mingw32(libstdc++), run under Wine 11.22 (Staging) on Linux. Formain(c1392d06f) the test was built againstmain's header, without the two checks that read the newskip_int3_onflag, which doesn't exist there.xgameruntime_offline_testpasses 44/44, also withLEONIDA_HDR=1 LEONIDA_LOG_GAME_EVENTS=1.startup_trace_test(7 of 26) andfile_system_test(6 of 446) have the same failures onmainand on this branch. They are failures of the mingw/Wine setup, not of this change.xmem.cppcompiles with the new header./W4 /permissive-build is the check for that.What I could and could not reproduce here
Simple probes, Wine 11.22 (Staging):
0xCCis reported the Windows way here (ExceptionAddress == Rip ==the0xCC), on the main thread and on a new thread. OnlyCD 03(int 3, still not handled) and90 CCput both one past the instruction start. So I couldn't reproduce bug 3 with a plainint3. The fix accepts both forms and keeps the Windows one first.EXCEPTION_POINTERS: never seen in those probes. A likely alternative cause of the null+8 access: an MSVCstd::setwhose constructor never ran has a null head node, and its parent pointer is at offset 8. That fits bug 2. The null checks stay either way.__cxa_guard_acquire, not a TLS epoch, so bug 1 can't be reproduced without an MSVC build. The symptom fits an MSVC_Init_thread_epochthat reads 0 instead ofINT_MINthrough gta6rt's_tls_indexon the title's thread. That would mean gta6rt's TLS block on that thread is zero-filled or belongs to someone else.LoadLibrary'd DLL whose TLS template is patched after loading. Wine copies the patched template for threads created afterwards, as Windows does. So the home-clone copy itself looks fine on Wine._Init_thread_epochthrough_tls_indexon a title-created thread in an MSVC build under Wine.thread_local.Related pull requests
startup_trace.h. Spacecer2's measurement was taken with it applied, so it doesn't fix this on its own.startup_trace.h.startup_trace.h: Trace outstanding startup callbacks and game entry by thread #6410, runtime: create startup traces exclusively without fopen x mode #6991, startup trace: a call through a null pointer names its caller (null_call_from) #7189 and loader: hand static TLS index 0 to the mapped title #7524 change other lines. loader: hand static TLS index 0 to the mapped title #7524 movesin_handlerandwide_fallbackfromthread_localtoTlsAllocslots, which is the same class of problem for TLS, and the two changes don't overlap.LEONIDA_SKIP_ASSERTS) has the sameRip == ExceptionAddresstest in its own handler and could take the same two-form lookup.XS_TRACE(d3d12_xs_device.cpp,trace_enabled()) is another env flag read into a block-scope static on a guest-reachable path. It isn't aLEONIDA_*flag and it is in the D3D12 layer, so it's left for a follow-up.Thanks to Spacecer2 for the measurements and the fix this follows.
Checklist
mainand pass with the change (mingw + Wine 11.22; MSVC is left to CI).docs/design.md. (Not applicable: no translator change.)AI-assisted (Claude Code, Claude Opus 5.5).