startup-runtime: d3d12_xs wrap() does not check _aligned_malloc, so a failed allocation becomes an access violation #2645

Closed
opened 2026-11-26 00:35:15 +00:00 by Not-Saii · 0 comments
Not-Saii commented 2026-11-26 00:35:15 +00:00 (Migrated from github.com)
Contributor

Imported from R0Y00/Xbox2Windows. Originally posted by Not-Saii on 2026-11-26T00:35:15Z.


Commit or build

main at d371ce46c57bf972f225616d462f99486f323f77, release preset.

Reproduction

Observed in a local startup run under the job memory cap. It is not yet reproduced on a source-built input (see "Proposed check" below).

.\tools\startup\run.ps1 -Exe <run dir>\<title>.exe -DataDir G:\ -LogDir out\startup\run13 `
    -ShaderCache out\startup\shader_cache_rekeyed -Seconds 900 -MemoryGiB 12 -Render -Translate -FakeUser `
    -GpuMirror -HostCpu -StartupBelow40 -ContinueAsserts 1000 -StoragePath <absolute path>

Process commit (PagefileUsage in the DirectStorage heartbeat) went from 5.3 GiB to 12.2 GiB once loading started, at the 12 GiB cap.

wrap() in src/startup_stubs/d3d12_xs_device.cpp (line 463 at this commit):

auto* block = static_cast<unsigned char*>(_aligned_malloc(sizeof(WrapperOwn) + area, 16));
std::memset(block, 0, sizeof(WrapperOwn) + area);

_aligned_malloc can return nullptr. The result is used without a check.

Expected behavior

When the wrapper allocation fails, the calling slot returns E_OUTOFMEMORY (and leaves *out null), so the title can handle the failure or report it through its own error path.

Observed behavior

Debugger stop at 221.29 s: second-chance access violation, a write to 0x20, at d3d12_xs.dll+0x587d90 (vmovdqa [rcx],ymm0 in the CRT memset).

Stack inside d3d12_xs.dll (release build, no PDB; identified from the disassembly and the format strings next to each call):

Return address Code
+0x5621f7 wrap(): _aligned_malloc(0x530, 16) returned nullptr, then memset(nullptr, 0, 0x530)
+0x528928 Device::slot55 (derived pipeline), the placeholder path: *out = wrap(nullptr, pipeline_kind)

wrap() has 16 call sites in d3d12_xs_device.cpp (queues, root signatures, descriptor heaps, command lists, resources, pipelines, command signatures, the device). None of them can see a failure today, because wrap() never returns one.

Proposed check

A source-built fixture under a job commit limit (the view census test already uses one) could fill the commit until one more allocation fails, then call one wrapping slot (for example a derived pipeline or a root signature). Expected: E_OUTOFMEMORY and a null output. A control without the check would end the process on an access violation.

A fix needs one decision per call site: what each slot returns, and which side effects (registry insertion, desktop object references) must be undone when the wrapper cannot be created.

Environment

  • Windows 11 Pro build 26300.9974
  • MSVC 19.44 (toolset 14.44.35207), Windows SDK 10.0.26100.0
  • NVIDIA GeForce RTX 4090, driver 32.0.16.1088; D3D12 debug layer off
  • AMD Ryzen 9 7900X, 32 GB RAM

Related: #1199 (commit exhaustion during loading). This issue only covers the missing check; the memory growth itself belongs to #1199.

  • I reproduced this on a source-built input. (Not yet: observed in a local run only.)
  • I did not include game files, dumps, distribution links or credentials.

AI-assisted (Claude Code).

<!-- greyfinch-sync:R0Y00/Xbox2Windows:issue:6616758436 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/issues/2653). Originally posted by [Not-Saii](https://github.com/Not-Saii) on 2026-11-26T00:35:15Z. --- ### Commit or build `main` at `d371ce46c57bf972f225616d462f99486f323f77`, `release` preset. ### Reproduction Observed in a local startup run under the job memory cap. It is not yet reproduced on a source-built input (see "Proposed check" below). ```powershell .\tools\startup\run.ps1 -Exe <run dir>\<title>.exe -DataDir G:\ -LogDir out\startup\run13 ` -ShaderCache out\startup\shader_cache_rekeyed -Seconds 900 -MemoryGiB 12 -Render -Translate -FakeUser ` -GpuMirror -HostCpu -StartupBelow40 -ContinueAsserts 1000 -StoragePath <absolute path> ``` Process commit (`PagefileUsage` in the DirectStorage heartbeat) went from 5.3 GiB to 12.2 GiB once loading started, at the 12 GiB cap. `wrap()` in `src/startup_stubs/d3d12_xs_device.cpp` (line 463 at this commit): ```cpp auto* block = static_cast<unsigned char*>(_aligned_malloc(sizeof(WrapperOwn) + area, 16)); std::memset(block, 0, sizeof(WrapperOwn) + area); ``` `_aligned_malloc` can return `nullptr`. The result is used without a check. ### Expected behavior When the wrapper allocation fails, the calling slot returns `E_OUTOFMEMORY` (and leaves `*out` null), so the title can handle the failure or report it through its own error path. ### Observed behavior Debugger stop at 221.29 s: second-chance access violation, a **write** to `0x20`, at `d3d12_xs.dll+0x587d90` (`vmovdqa [rcx],ymm0` in the CRT `memset`). Stack inside `d3d12_xs.dll` (release build, no PDB; identified from the disassembly and the format strings next to each call): | Return address | Code | |---|---| | `+0x5621f7` | `wrap()`: `_aligned_malloc(0x530, 16)` returned `nullptr`, then `memset(nullptr, 0, 0x530)` | | `+0x528928` | `Device::slot55` (derived pipeline), the placeholder path: `*out = wrap(nullptr, pipeline_kind)` | `wrap()` has 16 call sites in `d3d12_xs_device.cpp` (queues, root signatures, descriptor heaps, command lists, resources, pipelines, command signatures, the device). None of them can see a failure today, because `wrap()` never returns one. ### Proposed check A source-built fixture under a job commit limit (the view census test already uses one) could fill the commit until one more allocation fails, then call one wrapping slot (for example a derived pipeline or a root signature). Expected: `E_OUTOFMEMORY` and a null output. A control without the check would end the process on an access violation. A fix needs one decision per call site: what each slot returns, and which side effects (registry insertion, desktop object references) must be undone when the wrapper cannot be created. ### Environment - Windows 11 Pro build 26300.9974 - MSVC 19.44 (toolset 14.44.35207), Windows SDK 10.0.26100.0 - NVIDIA GeForce RTX 4090, driver 32.0.16.1088; D3D12 debug layer off - AMD Ryzen 9 7900X, 32 GB RAM Related: #1199 (commit exhaustion during loading). This issue only covers the missing check; the memory growth itself belongs to #1199. - [ ] I reproduced this on a source-built input. *(Not yet: observed in a local run only.)* - [x] I did not include game files, dumps, distribution links or credentials. AI-assisted (Claude Code).
Sign in to join this conversation.
No labels
No milestone
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Reference
R0Y00/Xbox2Windows#2645
No description provided.