Skip to content
Closed
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
9 changes: 7 additions & 2 deletions docs/retail_boot_chain.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ numbers, call shapes and counts. [boot.md](boot.md) has the runbook that produce
executable under `--dry-run`.

Setup: `main` `1cc6e3c12` with #6709, #4531, #6582, #4313, #4348 and #2490 merged locally, plus the local
stand-ins named below (not pull requests yet). Own 1.0.2.1 copy, Windows 11, RTX 4090 (driver 617.42),
stand-ins named below (row 9 is now #601; the rest are not pull requests yet). Own 1.0.2.1 copy, Windows 11, RTX 4090 (driver 617.42),
`LEONIDA_D3D12=vulkan`, MSVC 2022 `RelWithDebInfo` build.

## 1. The chain
Expand All @@ -22,7 +22,7 @@ stand-ins named below (not pull requests yet). Own 1.0.2.1 copy, Windows 11, RTX
| 6 | `XMemAllocatePhysicalPages` unimplemented; the title asserts on FALSE | Local stand-in, §2 |
| 7 | `D3D12XboxCreateDevice` succeeds; device slot 26 is called with its arguments swapped | Local, §3.1 |
| 8 | Device slot 48 is forwarded to the PC slot 48 and fails | Local, §3.2 |
| 9 | Device slot 73 is forwarded to the PC slot 73; the title then reads through a null list | #2490's list proxy plus local routing, §3.3 |
| 9 | Device slot 73 is forwarded to the PC slot 73; the title then reads through a null list | #2490's list proxy plus local routing, now the runtime's own answer in #601, §3.3 |
| 10 | An `XMemVirtualAlloc` reserve of about 185 MiB with type `0x42000`, attribute 7 and `PAGE_NOACCESS` is refused with `ERROR_INVALID_PARAMETER`. `0x40000` is `MEM_RESERVE_PLACEHOLDER` on the PC, which `VirtualAlloc` refuses and only `VirtualAlloc2` accepts; stop 11 supports the same reading on the console | Local: reserve it with `VirtualAlloc2(MEM_RESERVE \| MEM_RESERVE_PLACEHOLDER)` |
| 11 | The title carves five sub-ranges out of that placeholder with `MEM_RESERVE \| MEM_REPLACE_PLACEHOLDER \| MEM_PHYSICAL \| MEM_LARGE_PAGES` (`0x20406000`) at addresses inside it, then allocates a second batch of physical pages | Local: a physical reserve inside a known placeholder stays a placeholder (the page maps split it); other `MEM_REPLACE_PLACEHOLDER` calls split the range and allocate it in place |
| 12 | Device slot 133 is called; the proxy table had 128 slots, so the call went through a null pointer | Local: a 192-slot table, and a slot 133 stand-in, §3.4 |
Expand Down Expand Up @@ -83,6 +83,11 @@ package doesn't export it). The shim's unknown-IID log names it on the player's
`ID3D12GraphicsCommandList` of that type and handing out #2490's console list
proxy gets all 581 lists created and closed.

#601 puts that answer in the runtime instead of a local tree: when the console interface is what was asked for, slot
73 builds the list as `ID3D12GraphicsCommandList` and the list proxy is handed back for the requested IID; any other
IID reaches the real device exactly as the title passed it. What that console interface's own method table adds is
still not established, and #601 does not guess at it.

### 3.4 Device slot 133 places a resource at a virtual address

Xbox device slot 133 is `(va, const D3D12_RESOURCE_DESC*, state, clear, riid, out)` with `riid = IID_ID3D12Resource`
Expand Down
45 changes: 42 additions & 3 deletions runtime/shims/d3d12_xs_device.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -983,6 +983,15 @@ inline void note_list_slot(unsigned slot, std::uint64_t a1 = 0, std::uint64_t a2
static_cast<unsigned long long>(a3), static_cast<unsigned long long>(a4));
}

// The command-list interface the retail title asks device slot 73 for. It is a constant of the title itself, one
// entry of the table of object IIDs its Create* calls pass to the device: the entry between IID_ID3D12CommandAllocator
// and the command-signature IID, at its .rdata rva 0x61e0668, found by searching the Data4 bytes through the mapped
// images. One instruction in the title names it, and it feeds the slot-73 call. It shares Data1 with
// IID_ID3D12GraphicsCommandList6, appears in no image of the package, and is not in the PC SDK. The call shape is
// docs/retail_boot_chain.md section 3.3; what that interface's own method table adds is not established, so the proxy
// answers it with the console list table it already models.
constexpr GUID kConsoleCommandListIid{0xc3827890, 0x4024, 0x474c, {0x98, 0xcf, 0x64, 0x5b, 0x51, 0xdc, 0x48, 0x74}};

inline bool is_list_iid(const IID& iid) {
return IsEqualIID(iid, __uuidof(IUnknown)) || IsEqualIID(iid, __uuidof(ID3D12Object)) ||
IsEqualIID(iid, __uuidof(ID3D12DeviceChild)) || IsEqualIID(iid, __uuidof(ID3D12CommandList)) ||
Expand All @@ -994,7 +1003,8 @@ inline bool is_list_iid(const IID& iid) {
IsEqualIID(iid, __uuidof(ID3D12GraphicsCommandList5)) ||
IsEqualIID(iid, __uuidof(ID3D12GraphicsCommandList6)) ||
IsEqualIID(iid, __uuidof(ID3D12GraphicsCommandList7)) ||
IsEqualIID(iid, __uuidof(ID3D12GraphicsCommandList8));
IsEqualIID(iid, __uuidof(ID3D12GraphicsCommandList8)) ||
IsEqualIID(iid, kConsoleCommandListIid);
}

inline unsigned long list_add_ref(ListProxy* self) { return self->refs.fetch_add(1, std::memory_order_relaxed) + 1; }
Expand Down Expand Up @@ -1022,6 +1032,13 @@ inline HRESULT list_query_interface(ListProxy* self, const IID* riid, void** out
if (supports_iid(self->real, *riid)) log_refused_iid("list", *riid);
return E_NOINTERFACE;
}
// The console command-list interface is the one this proxy's own slot table answers, and no PC object implements
// it, so the real object's capability is not consulted for it. Every PC interface still has to be implemented.
if (IsEqualIID(*riid, kConsoleCommandListIid)) {
*out = self;
list_add_ref(self);
return S_OK;
}
if (!supports_iid(self->real, *riid)) return E_NOINTERFACE;
*out = self;
list_add_ref(self);
Expand Down Expand Up @@ -1441,9 +1458,31 @@ HRESULT proxy_create_command_list_x(DeviceProxy* self, std::uint64_t desc_word,
auto* allocator = allocator_proxy_real_allocator(reinterpret_cast<void*>(allocator_word));
if (!allocator) allocator = reinterpret_cast<ID3D12CommandAllocator*>(allocator_word);
auto* initial_state = reinterpret_cast<ID3D12PipelineState*>(initial_state_word);
// The title asks for the console command-list interface, which no PC device answers: build the list through
// ID3D12GraphicsCommandList - the interface this proxy's real pointer is typed as, and what section 3.3 of
// docs/retail_boot_chain.md prescribes for the stand-in - and let wrap_list hand the console proxy back for the
// IID that was asked for. A PC IID a real device does answer keeps the direct path.
// The title asks for the console command-list interface, which no PC device answers: build the list through
// ID3D12GraphicsCommandList - the interface this proxy's real pointer is typed as, and what section 3.3 of
// docs/retail_boot_chain.md prescribes for the stand-in - and let wrap_list hand the console proxy back for the
// IID that was asked for. Any other IID goes to the real device exactly as the title passed it.
const bool asked_console = IsEqualIID(*riid, kConsoleCommandListIid);
if (asked_console) {
static std::atomic<bool> asked_logged{false};
if (first_call(asked_logged))
std::fprintf(stderr,
"[rt] d3d12_xs: slot 73 CreateCommandListX was asked for {%08lX-%04X-%04X-%02X%02X-%02X%02X%"
"02X%02X%02X%02X}: the list is built as ID3D12GraphicsCommandList and answered with the "
"console list proxy\n",
static_cast<unsigned long>(riid->Data1), riid->Data2, riid->Data3, riid->Data4[0],
riid->Data4[1], riid->Data4[2], riid->Data4[3], riid->Data4[4], riid->Data4[5],
riid->Data4[6], riid->Data4[7]);
}
const IID built_as = __uuidof(ID3D12GraphicsCommandList);
void* created = nullptr;
const HRESULT hr = self->real->CreateCommandList(0, type, allocator, initial_state,
*riid, &created);
const HRESULT hr =
asked_console ? self->real->CreateCommandList(0, type, allocator, initial_state, built_as, &created)
: self->real->CreateCommandList(0, type, allocator, initial_state, *riid, &created);
if (FAILED(hr)) return hr;
return wrap_list(static_cast<IUnknown*>(created), self, riid, out);
}
Expand Down
24 changes: 24 additions & 0 deletions runtime/test/xs_proxy_mock_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -964,6 +964,30 @@ int check_xbox_slots() {
EXPECT(hr_of(raw(device, 73, word(&desc), 0, 0, word(&list_iid), word(&list))) == E_INVALIDARG);
EXPECT(hr_of(raw(device, 73, word(&desc), word(allocator), 0, word(&list_iid), 0)) == E_POINTER);

// Asked for the console command-list interface - what the retail title's slot-73 call actually asks for, and an
// IID no PC device answers - the list is built as ID3D12GraphicsCommandList and the console proxy is handed back
// for the IID that was asked for. That IID is measured from the title and appears in no image of the package.
constexpr GUID kConsoleListIid{0xc3827890, 0x4024, 0x474c, {0x98, 0xcf, 0x64, 0x5b, 0x51, 0xdc, 0x48, 0x74}};
const IID build_iid = __uuidof(ID3D12GraphicsCommandList);
void* console_list = nullptr;
EXPECT(hr_of(raw(device, 73, word(&desc), word(allocator), 0, word(&kConsoleListIid), word(&console_list))) ==
S_OK);
EXPECT(xs::is_command_list_proxy(console_list) && console_list != nullptr);
EXPECT(mock->calls[12] == 2);
EXPECT(mock->args[12][4] != word(&kConsoleListIid) &&
IsEqualIID(*reinterpret_cast<const IID*>(mock->args[12][4]), build_iid));
// The object handed back answers the interface it was created as, from the console list table.
void* asked_again = nullptr;
EXPECT(hr_of(raw(console_list, 0, word(&kConsoleListIid), word(&asked_again))) == S_OK);
EXPECT(asked_again == console_list);
EXPECT(release(asked_again) == 1);
// An interface the proxy does not model stays refused, with the output nulled.
const IID resource_iid = __uuidof(ID3D12Resource);
void* not_a_list = nullptr;
EXPECT(hr_of(raw(console_list, 0, word(&resource_iid), word(&not_a_list))) == E_NOINTERFACE);
EXPECT(not_a_list == nullptr);
EXPECT(release(console_list) == 0);

EXPECT(xs::device_slot_overridden(48) && xs::device_slot_overridden(73) && xs::device_slot_overridden(78) &&
xs::device_slot_overridden(79) && xs::device_slot_overridden(80));

Expand Down
Loading