Repository navigation
runtime/shims: remove function-local static guards in registry and classify XCRDAPI!DStorageGetFactory - #7175
Conversation
…assify XCRDAPI!DStorageGetFactory
|
Independent native Windows/MSVC 19.44, SDK 10.0.26100, RelWithDebInfo verification at eccdada: configured an isolated CPU-only CMake build, built registry_init_and_classify_test, ran it: 25 checks, 0 failed. Concurrent registry/thunk/bundled-loader stress and XCRDAPI HRESULT classification checks passed. No C++ source warning observed; MSBuild reports MSB8029 because the isolated build is under TEMP. Vulkan headers unavailable; this is CPU registry coverage. No game files. AI-assisted (Codex). |
|
Tested eccdada on Windows 11, AMD Radeon RX 9070 XT (RDNA4), driver 32.0.32029.2010: pass
AI-assisted (Claude Code). |
|
Tested under Wine 11.22 (CachyOS), clang-cl 23.1.5 + xwin build (which shows the fault), RTX 3060 Laptop / NVIDIA 620.73.04, retail 1.0.2.1 exe (own copy), no-network sandbox. Outcomes only.
So on this build the fault needs #4313 (the TLS block at index 0), not only the registry change. AI-assisted (Claude Code). |
… static guards in registry and classify XCRDAPI!DStorageGetFactory Squashed from ProjectLeonida#7175 by emirhan-karaca, head eccdada (security scan PASS).
…eGetFactory) with file-to-memory reads Squashed from ItsNotRexed#4348 by mariuslozo-boop, head 45c39cf (security scan PASS). Conflicts: runtime/CMakeLists.txt kept main's XTaskQueue/wait_registration test block with its closing endif() (a plain union drops it) and put the dstorage test in its own if(). docs/README.md keeps main's rows and adds the directstorage.md row (main's gameinput.md row kept). registry.cpp's comment merges main's note that the retail executable imports xcrdapi.dll!DStorageGetFactory (ItsNotRexed#6715) with the PR's note that dstorage.cpp serves it; the HRESULT classification was already on the branch (ItsNotRexed#7175). ItsNotRexed#7180 (zlib) not pulled.
…function-local static guards in d3d12_xs, file_system and xgameruntime Squashed from ItsNotRexed#7957 by DevilNine, head b8c7363 (security scan PASS). Clean merge on top of ItsNotRexed#6582's XErrorReport and the Wave 0 static-guard PRs (ItsNotRexed#7175, ItsNotRexed#7198, ItsNotRexed#7359).
…_ for descriptor heaps and translate CPU handles Squashed from ItsNotRexed#7021 by Khuraie, head 355201c (security scan PASS). CONFLICTING upstream. registry.cpp: main (Wave 0, ItsNotRexed#7175) replaced the bundled-loader function-local statics with a constant-initialized SRWLOCK and a global pointer; this PR's XMem hook list used the old function-local-static pattern, so it now follows main's SRWLOCK pattern too (function-local static guards fault under the clang-cl static CRT on Wine). d3d12_xs_device.cpp/.h: slot names, device_slot_overridden and the header list take the union with slots 25/26/48/56/70/133. xs_proxy_mock_test: Kind enum keeps command_list and heap; the slot-18 call of check_descriptor_heap_hooks passes a null view description instead of the placeholder 0x33, which ItsNotRexed#7066's mock now copies from (an access violation reviewers reported for this combination).
LaugeM
left a comment
There was a problem hiding this comment.
Two notes on the parts that touch other open work:
- The
classify()line forxcrdapi.dll(runtime/shims/registry.cpp) is the same change #8461 and #9213 make. This branch conflicts with #8461 inregistry.cppandruntime/CMakeLists.txt(git merge-tree). With #8461 the import is served, so I would drop that line and its checks from this PR and keep it to the static-guard change. - Plausible: the motivation is the mapped executable owning TLS slot 0. Main changed there after this PR was opened:
b7a3fed28gives a/GAexecutable its own TLS at index 0, so the executable no longer writes gta6rt's slot-0 TLS and gta6rt's magic statics are not clobbered. The Wine and static-CRT cross-build case may still need the guard removal, but it is worth rerunning @denisturcanu84's test on current main to show that the failure is still there.
AI-assisted review (Opus 5.5). Read the diff against main; not built.
@ItsNotRexed pinging as requested for an EXE/runtime PR.
Claim: #7049 (comment) (item 1)
Context: RT-488 / #7074 (function-local static init guard null-dereference on guest threads under Wine / static-CRT cross-builds and when the mapped executable owns TLS slot 0) and #6715 (retail executable dry-run reported
unimplemented by return policy: hresult=0 other=30despite importingXCRDAPI.dll!DStorageGetFactory).Problem
runtime/shims/registry.cpp(RT-488 class):table(),bundled_loader_mutex(),bundled_loaders(), andmake_unimplemented_thunk()'ss_thunksall used function-local dynamicstaticinitializers (static auto* m = new .../static std::map<...>), the exact same pattern that caused the RT-488 /#7074null dereference inlibrary_loader.cppwhen called from a guest thread under Wine or static-CRT cross-builds /#4313(where MSVC/clang-cl's_Init_thread_headerguard reads_Init_thread_epochfrom TLS slot 0).XCRDAPI.dllinclassify()(#6715):classify()already classifiesDStorageGetFactoryasReturnClass::HResultfordstorage.dllanddstorage_xs.dll, butgame_scarlett_master.exeimportsDStorageGetFactoryfromXCRDAPI.dll. UnderLEONIDA_UNIMPLEMENTED=fail(when noXCRDAPI.dllshim is registered), it returned0(S_OK) with a null out-pointer instead ofE_NOTIMPL.Changes
runtime/shims/registry.cpp:table()'s function-localstatic std::mapwith a constant-initializedINIT_ONCE(InitOnceExecuteOnce) immortal map pointer — preserves cross-TU static-init safety forSHIM_TABLEand teardown immortality with zero function-local static init guard.bundled_loader_mutex()andbundled_loaders()with a constant-initializedSRWLOCK(SRWLOCK_INIT) and lazy immortalstd::vector*allocated under the lock (fast empty return when no bundled loader is registered).make_unimplemented_thunk()'ss_thunksto a namespace-scope pointer lazily allocated under the already-heldg_pool_mutex.dll == "xcrdapi.dll"alongsidedstorage.dll/dstorage_xs.dllforDStorageGetFactoryinclassify().registry.cpp:startup_trace.h's inlinemutex()guard is left untouched to avoid overlap with openstartup_trace.hPRs.)runtime/test/registry_init_and_classify_test.cpp(new) &runtime/CMakeLists.txt:registry_init_and_classify_test(ctestnameregistry_init_and_classify) coveringSHIM_TABLEresolution,owns_dll,XCRDAPI.dll!DStorageGetFactoryclassification &E_NOTIMPLthunk execution underFailpolicy, bundled-loader null/register/dispatch/remove lifecycle, and 4-thread concurrent stress.Verification
g++ 16.2.0(-std=c++20 -O2 -Wall -Wextra -Werroronregistry.cppin both ANSI and-DUNICODE -D_UNICODEmodes, plus-Wconversion -Wsign-conversion -Werroronregistry_init_and_classify_test.cpp: 0 warnings).nm -C):origin/main09b9ba886registry.o): 4 guard variables inregistry.cpp(table()::t,bundled_loader_mutex()::m,bundled_loaders()::v,make_unimplemented_thunk::s_thunks) plus headerrt::startup_trace::detail::mutex()::m.registry.o): 0 guard variables inregistry.cpp(only the untouchedstartup_trace.hheader symbol remains).registry_init_and_classify_test.cpplinked against unmodifiedorigin/mainregistry.cpp):exit=1 | 25 checks, 3 failed(XCRDAPI.dll!DStorageGetFactoryclassified asOtherand returned0instead ofE_NOTIMPL).exit=0 | 25 checks, 0 failed).exit=0 | 25 checks, 0 failed).winhttp_offline_testlinked with patchedregistry.o: PASS (83 check(s), 0 failure(s)).CRLF=0on all 3 files,git diff --checkexit 0.Disclosures
g++ 16.2.0(with a scratch_AddressOfReturnAddressintrinsic stub forregistry.cpp:160, since MinGW lacks the MSVC intrinsic) and has no local MSVCcl.exeor CMake; full MSVC/W4 /permissive- /utf-8+ctestruns in CI.