Skip to content

RR runtime: set_device checks the result of Map on the completion marker - #81

Merged
phantoslayer21 merged 1 commit into
mainfrom
fix/67-marker-map-check
Nov 13, 2026
Merged

phantoslayer21 merged 1 commit into
mainfrom
fix/67-marker-map-check

Conversation

@phantoslayer21

Copy link
Copy Markdown
Owner

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); in clean/rr_f/runtime/src/rr_runtime.cpp). It then wrote through rt.marker_map. If Map failed, m was null and those writes dereferenced null. The Model M runtime (clean/runtime/device_d3d12.cpp) already checks this result.

In practice Map of a freshly created small readback buffer fails only on device removal or address-space exhaustion during set_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_device called rt.marker->Unmap whenever the buffer existed. With the new early return the buffer exists but was never mapped, so the call is now guarded by rt.marker_map (which is set only after a successful Map and 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, and set_device requires 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_map is null until Map succeeds, so the early return leaves it null; drop_device then skips Unmap, resets marker_map to null and drops the buffer; every other read of marker_map is already guarded (if (!rt.marker_map) return rt.serial;).

Tested

  • cl /Zs /EHsc /std:c++17 /W3 over rr_runtime.cpp (MSVC): no errors; only the existing _wfopen / getenv deprecation warnings.
  • Repository gates (secrets, personal data, licence, view layout): pass.

Not tested

  • No test for the changed behaviour (see above); nothing run on a GPU or in a game.
  • The full runtime build (kernels, DXC) and the RR test host were not run; they need the GPU toolchain and a Radeon RX 9000 card.

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>
@phantoslayer21
phantoslayer21 marked this pull request as ready for review November 13, 2026 21:01
@phantoslayer21
phantoslayer21 merged commit 5ba74ce into main Nov 13, 2026
2 checks passed
@phantoslayer21
phantoslayer21 deleted the fix/67-marker-map-check branch November 13, 2026 21:02
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

RR does not check the result of Map on the completion marker buffer

1 participant