Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 7 additions & 3 deletions runtime/shims/d3d12_xs_device.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1714,12 +1714,16 @@ HRESULT proxy_unwrapping_call(DeviceProxy* self, std::uint64_t a1, std::uint64_t
}

// A console descriptor heap carries a size as well as an address, and that size is 32 bytes per descriptor. A PC
// desc's trailing words are whatever the caller holds next; they do not encode NumDescriptors * 32, so this
// separates the two layouts without guessing anything about the address itself.
// desc's trailing words are whatever the caller holds next; they rarely encode NumDescriptors * 32, but for a
// one-descriptor heap a small count of 32 next to it is enough. MSVC's RelWithDebInfo d3d12_draw_test leaves the
// words 1 and 32 after its one-entry RTV desc, which passed the size check and turned the RTV handle into 0x1. So
// the address also has to lie above the first 64 KiB, which Windows never maps (the lowest user-mode address is
// 0x10000) and no console heap address can be in either.
static bool console_heap_range_plausible(const D3D12_DESCRIPTOR_HEAP_DESC* desc, std::uint64_t address,
std::uint64_t size) {
constexpr std::uint64_t kConsoleDescriptorSize = 32;
if (address == 0 || size == 0) return false;
constexpr std::uint64_t kLowestMappedAddress = 0x10000;
if (address < kLowestMappedAddress || size == 0) return false;
if (desc->NumDescriptors == 0 || desc->NumDescriptors > (0xFFFFFFFFull / kConsoleDescriptorSize)) return false;
if (size != static_cast<std::uint64_t>(desc->NumDescriptors) * kConsoleDescriptorSize) return false;
return true;
Expand Down
24 changes: 24 additions & 0 deletions runtime/test/d3d12_console_descriptor_heap_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,30 @@ bool check_xs_proxy_slot14(ID3D12Device* real_device) {
static_cast<unsigned long long>(console.address));
return false;
}

// An ordinary one-descriptor desc followed by the words 1 and 32 (what d3d12_draw_test's RTV desc had after it
// on the stack under MSVC RelWithDebInfo): the size matches 1 * 32, but 0x1 is no heap address, so slot 14 has
// to create an ordinary heap instead of handing out 0x1 as the heap start.
ConsoleDescriptorHeapDesc stray{};
stray.desc.Type = D3D12_DESCRIPTOR_HEAP_TYPE_RTV;
stray.desc.NumDescriptors = 1;
stray.address = 1;
stray.size = 32;
Ref<ID3D12DescriptorHeap> stray_heap;
const HRESULT stray_hr = proxy->CreateDescriptorHeap(&stray.desc, IID_PPV_ARGS(stray_heap.put()));
ID3D12DescriptorHeap* stray_real = SUCCEEDED(stray_hr) && stray_heap.get()
? rt::d3d12_xs::heap_proxy_real_heap(stray_heap.p) : nullptr;
if (!stray_real) {
std::fprintf(stderr, "proxy CreateDescriptorHeap(stray trailing words) failed: 0x%08lx\n",
static_cast<unsigned long>(stray_hr));
return false;
}
const auto stray_cpu = stray_real->GetCPUDescriptorHandleForHeapStart();
if (stray_cpu.ptr == 0 || stray_cpu.ptr == static_cast<SIZE_T>(stray.address)) {
std::fprintf(stderr, "stray trailing words were taken as a console heap: CPU start 0x%llx\n",
static_cast<unsigned long long>(stray_cpu.ptr));
return false;
}
return true;
}

Expand Down
Loading