diff options
| author | ubiquitarianism <283527159+ubiquitarianism@users.noreply.github.com> | 2026-11-23 20:26:40 -0500 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2026-11-23 20:26:40 -0500 |
| commit | 30daa6958bd08d4df402cdd0cb6d021ef072cd9d (patch) | |
| tree | 0d4604c50557b9867d657b36401d633eeeeefdec /runtime | |
| parent | ff8ce38825bcd3f5fab377e19e8b582567670804 (diff) | |
| parent | 37246f11d1622e6959c19874000ddc020fa2bf79 (diff) | |
Merge pull request #4 from yyc160/slot14-range-guard
d3d12_xs: only take the console slot-14 layout when the descriptor size agrees
Diffstat (limited to 'runtime')
| -rw-r--r-- | runtime/shims/d3d12_xs_device.cpp | 19 |
1 files changed, 16 insertions, 3 deletions
diff --git a/runtime/shims/d3d12_xs_device.cpp b/runtime/shims/d3d12_xs_device.cpp index 14a4b38ff..1045b86fb 100644 --- a/runtime/shims/d3d12_xs_device.cpp +++ b/runtime/shims/d3d12_xs_device.cpp | |||
| @@ -1563,6 +1563,18 @@ HRESULT proxy_unwrapping_call(DeviceProxy* self, std::uint64_t a1, std::uint64_t | |||
| 1563 | return static_cast<HRESULT>(static_cast<std::uint32_t>(forward_device<Slot>(self, r1, r2, r3, r4, a5))); | 1563 | return static_cast<HRESULT>(static_cast<std::uint32_t>(forward_device<Slot>(self, r1, r2, r3, r4, a5))); |
| 1564 | } | 1564 | } |
| 1565 | 1565 | ||
| 1566 | // A console descriptor heap carries a size as well as an address, and that size is 32 bytes per descriptor. A PC | ||
| 1567 | // desc's trailing words are whatever the caller holds next; they do not encode NumDescriptors * 32, so this | ||
| 1568 | // separates the two layouts without guessing anything about the address itself. | ||
| 1569 | static bool console_heap_range_plausible(const D3D12_DESCRIPTOR_HEAP_DESC* desc, std::uint64_t address, | ||
| 1570 | std::uint64_t size) { | ||
| 1571 | constexpr std::uint64_t kConsoleDescriptorSize = 32; | ||
| 1572 | if (address == 0 || size == 0) return false; | ||
| 1573 | if (desc->NumDescriptors == 0 || desc->NumDescriptors > (0xFFFFFFFFull / kConsoleDescriptorSize)) return false; | ||
| 1574 | if (size != static_cast<std::uint64_t>(desc->NumDescriptors) * kConsoleDescriptorSize) return false; | ||
| 1575 | return true; | ||
| 1576 | } | ||
| 1577 | |||
| 1566 | static bool readable_range(const void* ptr, std::size_t bytes) { | 1578 | static bool readable_range(const void* ptr, std::size_t bytes) { |
| 1567 | if (!ptr || !bytes) return false; | 1579 | if (!ptr || !bytes) return false; |
| 1568 | const auto* p = static_cast<const std::uint8_t*>(ptr); | 1580 | const auto* p = static_cast<const std::uint8_t*>(ptr); |
| @@ -1602,9 +1614,10 @@ HRESULT proxy_create_descriptor_heap(DeviceProxy* self, const D3D12_DESCRIPTOR_H | |||
| 1602 | std::uint64_t size = 0; | 1614 | std::uint64_t size = 0; |
| 1603 | std::memcpy(&address, tail, sizeof(address)); | 1615 | std::memcpy(&address, tail, sizeof(address)); |
| 1604 | std::memcpy(&size, bytes + sizeof(D3D12_DESCRIPTOR_HEAP_DESC) + sizeof(address), sizeof(size)); | 1616 | std::memcpy(&size, bytes + sizeof(D3D12_DESCRIPTOR_HEAP_DESC) + sizeof(address), sizeof(size)); |
| 1605 | // Console-extended slot 14 (issue #313): address/size follow the PC desc. Only take this path when a | 1617 | // Console-extended slot 14 (issue #313): address/size follow the PC desc. A non-zero word is not evidence |
| 1606 | // non-zero console VA is present; normal PC 16-byte descs never enter it. | 1618 | // of that layout - the bytes after a PC desc are whatever the caller holds next, and they are almost |
| 1607 | if (address != 0) { | 1619 | // always readable and non-zero. The size has to agree with the descriptor count for the path to be taken. |
| 1620 | if (console_heap_range_plausible(desc, address, size)) { | ||
| 1608 | const ConsoleDescriptorHeapHandler handler = | 1621 | const ConsoleDescriptorHeapHandler handler = |
| 1609 | g_console_descriptor_heap.load(std::memory_order_acquire); | 1622 | g_console_descriptor_heap.load(std::memory_order_acquire); |
| 1610 | if (handler) { | 1623 | if (handler) { |