Repository navigation
RR runtime: set_device checks the result of Map on the completion marker - #81
Merged
Merged
Conversation
set_device mapped the 256-byte readback buffer used as the completion marker and ignored the result; a failed Map left the pointer null and the writes right after it dereferenced null. A failed Map now drops the device and returns WG_E_D3D_API, as the Model M runtime does. drop_device unmaps the marker only if it was mapped. Fixes #67 Signed-off-by: phantoslayer21 <156617979+phantoslayer21@users.noreply.github.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #67
What was wrong
In
set_device, the RR runtime maps the 256-byte readback buffer used as the completion marker and ignored the result (rt.marker->Map(0, &r, &m);inclean/rr_f/runtime/src/rr_runtime.cpp). It then wrote throughrt.marker_map. IfMapfailed,mwas null and those writes dereferenced null. The Model M runtime (clean/runtime/device_d3d12.cpp) already checks this result.In practice
Mapof a freshly created small readback buffer fails only on device removal or address-space exhaustion duringset_device, so the effect would be a crash at initialization in an already broken state.The fix
set_device:if (FAILED(rt.marker->Map(0, &r, &m)) || !m) { drop_device(); return WG_E_D3D_API; }.drop_devicecalledrt.marker->Unmapwhenever the buffer existed. With the new early return the buffer exists but was never mapped, so the call is now guarded byrt.marker_map(which is set only after a successfulMapand cleared right after the unmap). That is the guard the issue asks for, without a new flag.The test
None added. The failure needs a fault-injection seam around
Map, andset_devicerequires an RDNA 4 adapter, so it cannot be reached on the CPU (WARP or a stub). The issue says a code check is enough.Code check:
marker_mapis null untilMapsucceeds, so the early return leaves it null;drop_devicethen skipsUnmap, resetsmarker_mapto null and drops the buffer; every other read ofmarker_mapis already guarded (if (!rt.marker_map) return rt.serial;).Tested
cl /Zs /EHsc /std:c++17 /W3overrr_runtime.cpp(MSVC): no errors; only the existing_wfopen/getenvdeprecation warnings.Not tested