mirror of
https://github.com/ubiquitarianism/leonida.git
synced 2026-11-26 23:50:51 +01:00
[PR #2047] runtime: harden COM refcount ordering, private-data updates, and reentrant release in d3d12_com_object #2053
Labels
No labels
bug
pull-request
No milestone
No project
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set
Reference
starred/leonida#2053
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?
📋 Pull Request Information
Original PR: https://github.com/ubiquitarianism/leonida/pull/2047
Author: @IlyassRS3
Created: 11/25/2026
Status: 🔄 Open
Base:
main← Head:rt/d3d12-com-object-atomic-and-private-data-safety📝 Commits (1)
7d496ddruntime: harden COM refcount ordering, private-data updates, and reentrant release in d3d12_com_object📊 Changes
2 files changed (+90 additions, -22 deletions)
View changed files
📝
runtime/shims/d3d12_com_object.h(+47 -22)📝
runtime/test/d3d12_private_data_test.cpp(+43 -0)📄 Description
Claim ID:
RT-D3D12-COM-OBJECT-ATOMIC-AND-PRIVATE-DATA-SAFETYSummary
Hardens the shared COM base classes (
rt::d3d12::Object,rt::d3d12::Child, andrt::d3d12::hand_out) inruntime/shims/d3d12_com_object.h:AddRef()andtry_add_ref()now usestd::memory_order_relaxedandRelease()usesstd::memory_order_acq_relinstead ofseq_cstdefaults, matchingstd::shared_ptr,xg_xs.cpp, andd3d12_xs_rootsig.cppwhile keeping acquire-release synchronization before deletion /last_release().replace()now updates an existing key in place (avoiding vector shifting and reallocation on overwrite), releases the evicted interface outsidedata_mutex_, andSetPrivateData()/SetPrivateDataInterface()catchstd::bad_allocand returnE_OUTOFMEMORYinstead of unwinding acrossSTDMETHODCALLTYPE(releasing the added reference ifSetPrivateDataInterfacefails to growdata_).SetNamelength truncation:SetName()now checkswcslen(name) < UINT_MAX / sizeof(wchar_t)before casting(length + 1) * sizeof(wchar_t)toUINT.Child::attach_device(),Child::~Child(), andObject::~Object():attach_device()and~Child()updatedevice_viastd::exchangebefore callingold->Release(), and~Object()swapsdata_out underdata_mutex_before releasing stored interfaces. Previously, if an evicted device'sRelease()queriedGetDevice(),device_still pointed to the old device (causing infinite recursion / SIGSEGV in the negative control).hand_out(): ReturnsE_OUTOFMEMORYand clears*outinstead of dereferencing a null object pointer.runtime/test/d3d12_private_data_test.cpp(after the recorded Microsoft answer-table comparison sokPrivateDataAnswersis unchanged) with a reentrantRelease()probe verifying lock-free visibility of the replacement entry.Verification
d3d12_private_data_testpending)d3d12_com_object.h):clang++ -std=c++20 -O1 -g -fsanitize=address,undefined -Wall -Wextra -Werror: PASS (failures=0)clang++ -std=c++20 -O1 -g -fsanitize=thread -Wall -Wextra -Werror(4 threads x 15,000 concurrentAddRef/try_add_ref/Release+ concurrentSetPrivateData/GetPrivateData/SetPrivateDataInterface+ deferredlast_release()+ reentrantattach_device& private-data overwrite +hand_out(nullptr)): PASS (failures=0)-O2negative control onmain: reentrantattach_device()crashed withSIGSEGV(exit139); fixed branch passed withfailures=0.-O2A/B check (40MAddRef/Release+ 3MSetPrivateDataoverwrites): bit-exactacc=120000000,last=2999999, throughput parity (ref_ms=125.6 msvs125.6 ms).python3 -I scripts/check_no_game_data.pyclean;python3 -I tests/test_text_write_line_endings.py(3/3 OK).🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.