d3d12_xs: texture upload decommit race causes unrecoverable AV #110

Closed
opened 2026-11-22 09:51:48 +00:00 by Trwthh · 1 comment
Trwthh commented 2026-11-22 09:51:48 +00:00 (Migrated from github.com)

Imported from omonkeyz/xbox-emulator. Originally posted by Trwthh on 2026-11-22T09:51:48Z.


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.

<!-- greyfinch-sync:omonkeyz/xbox-emulator:issue:6540974190 --> Imported from [omonkeyz/xbox-emulator](https://github.com/omonkeyz/xbox-emulator/issues/110). Originally posted by [Trwthh](https://github.com/Trwthh) on 2026-11-22T09:51:48Z. --- ## 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.
omonkeyz commented 2026-11-22 17:24:23 +00:00 (Migrated from github.com)
Author

Imported from omonkeyz/xbox-emulator. Originally posted by omonkeyz on 2026-11-22T17:24:23Z.


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.

<!-- greyfinch-sync:omonkeyz/xbox-emulator:comment:7082813499 --> Imported from [omonkeyz/xbox-emulator](https://github.com/omonkeyz/xbox-emulator/issues/110#issuecomment-7082813499). Originally posted by [omonkeyz](https://github.com/omonkeyz) on 2026-11-22T17:24:23Z. --- 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.
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
omonkeyz/xbox-emulator#110
No description provided.