Skip to content

hle/dstorage: fix queue error reset, event handle duplication, close/release races, and pointer validation - #81

Merged
ivall merged 1 commit into
xcl-dev:mainfrom
certified-retart:fix/dstorage-queue-bugs
Nov 23, 2026
Merged

ivall merged 1 commit into
xcl-dev:mainfrom
certified-retart:fix/dstorage-queue-bugs

Conversation

@certified-retart

Copy link
Copy Markdown
Contributor

Summary

Fixes several queue lifecycle, error-reporting, and pointer-validation bugs in crates/xcl/src/hle/dstorage.rs:

  1. RetrieveErrorRecord never cleared errors or reset error_event:
    • Cleared the error count and first failure record and called ResetEvent(q.error_event) under q.errors.lock() (the same mutex held by QueueInner::fail when calling SetEvent, avoiding lost notifications).
  2. GetErrorEvent returned the internal HANDLE directly:
    • Duplicated error_event with DuplicateHandle(..., DUPLICATE_SAME_ACCESS) (matching file_get_handle), so the caller can close its returned handle via CloseHandle without invalidating the queue's internal event or causing a double-close in QueueInner::drop.
  3. Concurrent Release() could leak the worker thread and QueueInner:
    • Replaced the non-atomic refs.load() == 1 pre-check before fetch_sub with a single atomic fetch_sub(1, Ordering::AcqRel) - 1 == 0 check so exactly one thread takes worker and tears down the Arc<QueueInner> ↔ worker thread cycle.
  4. Close() vs. Enqueue*() / Submit() races and in-flight worker completion:
    • Acquired worker then pending (matching submit()'s lock order) in queue_close and checked closed under the respective locks in submit(), enqueue(), and enqueue_request(), preventing post-close enqueues or worker respawns.
    • Stopped executing queued requests/signals after closed is set in QueueInner::run (marking remaining submitted statuses E_QUEUE_CLOSED) and waited outside queue locks on a worker_active condvar in queue_close so no worker touches caller buffers after Close() returns (including for concurrent Close() callers).
    • Released worker before dropping any unsent batch on spawn/send failure so fence Release() cannot re-enter while holding the mutex.
  5. In-order refused error reporting & pointer validation:
    • Carried refused request diagnostics in Entry::Refused so errors are published in queue order (and skipped if closed before execution).
    • Validated readable() and status_vtbl() in queue_enqueue_status, and readable() on fence + vtable in queue_enqueue_signal.

Tests

  • Added error_record_resets_after_retrieval_and_event_is_duplicated
  • Added queue_release_concurrent_breaks_worker_cycle
  • Added queue_validates_status_and_fence_pointers_and_closed_rejects_work
  • Ran cargo test -p xcl --lib hle::dstorage::tests -- --test-threads=2: 8 passed; 0 failed.

@ivall
ivall merged commit f8e7c2b into xcl-dev:main Nov 23, 2026
@ivall

ivall commented Nov 23, 2026

Copy link
Copy Markdown
Collaborator

Merged. Fortnite reads all of its data through DirectStorage – with this it still loads to its splash screen, no DirectStorage errors in the log. Tested on Windows 11 with an RX 9070 (RDNA4): cargo test --workspace green with the retail samples (shader pack, console DLLs, texture archive), lib tests also with XCL_SPLIT_WAVE64=1; Unicorn Overlord, Minecraft and Fortnite run with this round merged. Thanks!

Michael-Glaser added a commit to Michael-Glaser/xcl that referenced this pull request Nov 24, 2026
…cl-dev#104)

On newer GDK runtimes (QUEUE_SHIFTED), 20 command list console methods shift up by +2 via NEWER_LIST_SLOTS, leaving 11 older slots (xcl-dev#59, xcl-dev#60, xcl-dev#68, xcl-dev#69, xcl-dev#78, xcl-dev#81, xcl-dev#84, xcl-dev#88, xcl-dev#89, xcl-dev#93, xcl-dev#94) without another shifted method taking their old index. Those slots remained wired directly to the older layout's handlers, so a newer-layout call hit the wrong method.

Wrap those orphaned slots in make_layout_split so newer-layout title calls go to a logged stub while older-layout titles keep the handler and non-title callers keep their PC target (including cl_execute_indirect at xcl-dev#59 and the original base-table stub for slots >= scanned). Slot xcl-dev#10 (Reset) stays Reset on both layouts and is not orphaned.

Assisted-by: Antigravity (Gemini 4 Neon)
vincentes added a commit to vincentes/xcl-wasm that referenced this pull request Nov 24, 2026
In the software D3D12.X device:

- The console's frame clock (device xcl-dev#78–xcl-dev#81): SetFrameIntervalX,
  ScheduleFrameEventX, WaitFrameEventX (the origin hands out the frame's
  token; S_FALSE at the timeout) and GetFrameStatisticsX, on guest time.
  The ancillary handles of an event are not signalled.
- PresentX (queue xcl-dev#30) goes through the queue like everything else; when
  the queue gets to it the frame is flipped for the statistics and the
  back buffer's memory is kept as `d3d.frame` (width, height, format,
  pixels) for the host to show. Textures are linear in this device: the
  console's tiling is not modelled.
- ClearRenderTargetView (list xcl-dev#52) fills a target of 8 bits a channel;
  CreateRenderTargetView remembers which resource a descriptor shows.
- The device answers QueryInterface for IDXGIDevice / 1 / 2 with an
  object of that layout; its adapter has the device's LUID and no output.

Measured on macOS (aarch64): the test title's "frame clock + PresentX of
the title's back buffer" passes, 41 checks in all. `cargo test -p
xcl-guest`: 47 passed, 0 failed, run on the staged tree in a separate
copy: the working tree does not build at the moment (another agent's
half-written crates/xcl/src/hle/export_names.rs).

Co-Authored-By: Claude Fable 5.2 <[email protected]>
Michael-Glaser added a commit to Michael-Glaser/xcl that referenced this pull request Nov 24, 2026
…vall#104)

On newer GDK runtimes (QUEUE_SHIFTED), 20 command list console methods shift up by +2 via NEWER_LIST_SLOTS, leaving 11 older slots (ivall#59, ivall#60, ivall#68, ivall#69, ivall#78, ivall#81, ivall#84, ivall#88, ivall#89, ivall#93, ivall#94) without another shifted method taking their old index. Those slots remained wired directly to the older layout's handlers, so a newer-layout call hit the wrong method.

Wrap those orphaned slots in make_layout_split so newer-layout title calls go to a logged stub while older-layout titles keep the handler and non-title callers keep their PC target (including cl_execute_indirect at ivall#59 and the original base-table stub for slots >= scanned). Slot ivall#10 (Reset) stays Reset on both layouts and is not orphaned.

Assisted-by: Antigravity (Gemini 4 Neon)
rootw0rm pushed a commit to rootw0rm/xcl that referenced this pull request Nov 27, 2026
…nd backend

1d split 1 of 2 (honest split: route halves stay under the line budget).
Device frame-clock slots route on Vulkan objects only: xcl-dev#78
SetFrameIntervalX, xcl-dev#79 ScheduleFrameEventX (with ancillary handle routing),
xcl-dev#80 WaitFrameEventX, xcl-dev#81 GetFrameStatisticsX — thin adapters over the Linux
twin (d3d12x_frame_linux). register_ancillary remembers the schedule block's
handles per type (E_INVALIDARG past the 63-handle cap, like Windows; Linux
trusts the block — readable() is windows-only); the clock thread signals
each with kernelx SetEvent at fire. Unscheduling clears. Null device keeps
logging stubs: no behavior change while XCL_VULKAN_BACKEND is unset. Queue
xcl-dev#30 PresentX + the real present follow in 1d(ii).

Failing-first: the routing test failed pre-fix (E0599 no VulkanQueue;
then E_FAIL at xcl-dev#81 with PresentX still stubbed); passes now (slots +
ancillary-signal asserts, serialised on CLOCK_SERIAL with the twin's tests).
Gates: check -p xcl --tests EXIT 0 (40 pre-existing warnings, none new);
check --workspace EXIT 0; lib 794 passed/0 failed/1 ignored (+1 new).
Title e2e + retail controls run at 1d(ii).
rootw0rm pushed a commit to rootw0rm/xcl that referenced this pull request Nov 27, 2026
…nd backend

1d split 2 of 2 (honest split: a real WSI staging present is indivisible
at ~350 lines — slicing further would leave dead code or fake success).
Queue xcl-dev#30 PresentX routes on Vulkan queues only (VulkanQueue from a Vulkan
device; null queues keep the logging stub): plane 0's resource bytes
(R8G8B8A8 2D texture; committed Map backing or placed title memory,
unmodelled shapes present nothing) upload through the new
vulkan_present::present_rgba_image — X window + swapchain, staging-buffer
copy, one acquire/submit/present — then mark_flipped(token) for xcl-dev#81.
Headless ('no ' display/WSI/device) still flips + S_OK: a console present
never fails. Null default unchanged.

Failing-first: the 1d routing test failed pre-route (E_FAIL at xcl-dev#81, no
flip); passes now end to end (set/schedule/wait/token/present/stats), and
present_rgba_image proved REAL on hardware (Intel Arc split-32, 2x2 frame
presented in 0.11s, no SKIPPED).
Gates: check -p xcl --tests EXIT 0 (40 pre-existing warnings, none new);
check --workspace EXIT 0; lib 795 passed/0 failed/1 ignored
(--test-threads=4; default-thread full runs flake pre-existing, base too).
Title e2e delta 0 (12 FAILs null, stashed baseline 12; 10 on Vulkan, both
baselines); FAIL #2 still-failing: the title dies at DXGI GetAdapter/GetDesc
before reaching the routed slots (no xcl-dev#78/PresentX in xcl.log) — next slice.
Retail HOLDS (SIGSEGV exe+0x2237320, exit 139, called_stubs 20, 0 d3d12,
xgr exactly XAsync/XNetworking/XUser).
rootw0rm pushed a commit to rootw0rm/xcl that referenced this pull request Nov 27, 2026
List slots 28/29 count draws into banked occlusion samples and slot 30
writes them as u64s into the results buffer's committed backing
(SAMPLES_PER_DRAW each: outer = 2N, inner = single = N, so the title's
nesting assert passes on both backends). PC draws (slots 12/13) and
console DrawIndexedX (xcl-dev#81) feed the same counter. CopyTextureRegion from
a committed 2D RGBA8 render target stashes a pending copy at record
time; the S4 Execute flush fills it from the submit's pixels row by
row (pitch-aware), so Map reads real offscreen pixels on Vulkan (null
Executes drain unwritten — readbacks stay zero).

Evidence: new draw_s5_query_resolve_and_readback failed pre-change
(slots 28-30 stubs, counts [0,0,0]) and passes post on Arc A770 (null
counts [2048,0,1024]; Vulkan outer 2048 + centre green / corner clear);
S4 test needed a shared draw_serial mutex (exact global-counter asserts
raced under --test-threads=4 once two tests flush). lib 810 passed, 0
failed, 1 ignored (x2 runs); both cargo checks clean; title same-harness
delta 0 (null 4 / Vulkan 3) with the triangle FAIL moved past occlusion
(null: zeros top-right; Vulkan: clear-blue top-right from the real
submit); retail HOLDS (exit 139 @ exe+0x2237320, SIGSEGV fault 0, 20
stubs, 0 d3d12, xgr XAsync/XNetworking/XUser).
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.

2 participants