d3d12_xs: texture upload decommit race causes unrecoverable AV #110

Closed
opened 2026-11-26 06:10:33 +00:00 by github-bot · 1 comment
Owner

@⁠Trwthh on GitHub · 2026-11-22 09:51 UTC · original

Bug

In crates/compat/d3d12_xs/src/upload.rs, the texture upload copy loop (line ~30+) reads from placed-resource backing memory that a title thread can decommit concurrently. The code documents the risk ("a decommit racing the read would fault") but has no SEH guard or VirtualQuery pre-check.

On Xbox hardware this cannot happen because the GPU and CPU share unified memory with hardware-managed residency. On PC, the backing memory is a separate CPU-side buffer whose lifetime is managed by VirtualAlloc/VirtualFree, and a title that frees placed-resource memory while the uploader is mid-copy causes an access violation with no recovery path.

Impact

Intermittent crash (AV) during texture streaming, especially in titles that aggressively recycle placed-resource memory (observed as a risk during Fortnite lobby texture streaming and Terraria texture upload). Hard to reproduce because it requires a narrow race window.

Suggested fix

Wrap the copy loop in a Windows SEH __try/__except(EXCEPTION_EXECUTE_HANDLER) (or the Rust equivalent via windows-rs or inline asm), and treat a fault as a failed upload (fill with black or skip the mip), matching the graceful-degradation pattern already used for "upload unreadable placed texture" cases.

**@⁠Trwthh** on GitHub · 2026-11-22 09:51 UTC · [original](https://github.com/omonkeyz/xbox-emulator/issues/110) ## Bug In `crates/compat/d3d12_xs/src/upload.rs`, the texture upload copy loop (line ~30+) reads from placed-resource backing memory that a title thread can decommit concurrently. The code documents the risk ("a decommit racing the read would fault") but has no SEH guard or VirtualQuery pre-check. On Xbox hardware this cannot happen because the GPU and CPU share unified memory with hardware-managed residency. On PC, the backing memory is a separate CPU-side buffer whose lifetime is managed by VirtualAlloc/VirtualFree, and a title that frees placed-resource memory while the uploader is mid-copy causes an access violation with no recovery path. ## Impact Intermittent crash (AV) during texture streaming, especially in titles that aggressively recycle placed-resource memory (observed as a risk during Fortnite lobby texture streaming and Terraria texture upload). Hard to reproduce because it requires a narrow race window. ## Suggested fix Wrap the copy loop in a Windows SEH `__try/__except(EXCEPTION_EXECUTE_HANDLER)` (or the Rust equivalent via `windows-rs` or inline asm), and treat a fault as a failed upload (fill with black or skip the mip), matching the graceful-degradation pattern already used for "upload unreadable placed texture" cases.
github-bot 2026-11-26 06:10:33 +00:00
  • closed this issue
  • added the
    bug
    label
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 06:10:33 +00:00
Author
Owner

@⁠omonkeyz on GitHub · 2026-11-22 17:24 UTC · original

Fixed by #153, merged in fe391fe (commits 5d5bc33 and 439826e). Reads of placed-texture memory now run inside a range-scoped fault guard. If the title decommits the memory while a read is in progress, the read is skipped and logged, instead of an access violation taking down the process. A fault outside the declared range still crashes as before.

**@⁠omonkeyz** on GitHub · 2026-11-22 17:24 UTC · [original](https://github.com/omonkeyz/xbox-emulator/issues/110#issuecomment-7082813499) Fixed by #153, merged in fe391fe (commits 5d5bc33 and 439826e). Reads of placed-texture memory now run inside a range-scoped fault guard. If the title decommits the memory while a read is in progress, the read is skipped and logged, instead of an access violation taking down the process. A fault outside the declared range still crashes as before.
This discussion has been locked. Commenting is limited to contributors.
No description provided.