diff options
| author | ItsNotRexed <300290919+ItsNotRexed@users.noreply.github.com> | 2026-11-22 22:09:51 -0500 |
|---|---|---|
| committer | ItsNotRexed <300290919+ItsNotRexed@users.noreply.github.com> | 2026-11-22 22:12:50 -0500 |
| commit | be8570ace18d3144d6cbfc2d57c60e736a1c1465 (patch) | |
| tree | 2aa5c100fb9b4ec22b819333194baeea5d3b7906 /runtime/shims/xmem.cpp | |
| parent | f99ff6cbdd23a2417af5494497f2f23da67c144a (diff) | |
| parent | d0835dd9f9ec0a88faee510126436f2427854c2e (diff) | |
Merge remote-tracking branch 'origin/main' into triage-r43
# Conflicts:
# docs/runtime_imports.md
# runtime/CMakeLists.txt
# runtime/shims/xgameruntime.cpp
# runtime/test/xmem_test.cpp
# tools/rdna2spirv.py
Diffstat (limited to 'runtime/shims/xmem.cpp')
| -rw-r--r-- | runtime/shims/xmem.cpp | 29 |
1 files changed, 29 insertions, 0 deletions
diff --git a/runtime/shims/xmem.cpp b/runtime/shims/xmem.cpp index 98c05d433..c7cfb76c0 100644 --- a/runtime/shims/xmem.cpp +++ b/runtime/shims/xmem.cpp | |||
| @@ -219,8 +219,37 @@ UINT WINAPI XMemResetWriteWatch(void* base_address, SIZE_T region_size) { | |||
| 219 | return ResetWriteWatch(base_address, region_size); | 219 | return ResetWriteWatch(base_address, region_size); |
| 220 | } | 220 | } |
| 221 | 221 | ||
| 222 | // kernel32!VirtualAlloc as a title calls it. The console's allocation type has two bits of its own, MEM_GRAPHICS | ||
| 223 | // (0x10000000, memory the GPU reads) and MEM_TITLE (0x40000000, the title's own heap). On a PC the host rejects both | ||
| 224 | // with ERROR_INVALID_PARAMETER (measured on Windows 11 26200: VirtualAlloc(NULL, 64 KiB, MEM_COMMIT | MEM_RESERVE | | ||
| 225 | // 0x10000000, PAGE_READWRITE) returns NULL; so does 0x40000000), so an engine allocating its heaps this way gets | ||
| 226 | // NULL at boot. Both are hints about where the memory lives; the host has no such split, so they are dropped and | ||
| 227 | // the rest is passed through. Not done: the console protection bits, and whether graphics memory has to come from | ||
| 228 | // an arena the D3D12 layer can see (#313). | ||
| 229 | constexpr DWORD kMemGraphics = 0x10000000; | ||
| 230 | constexpr DWORD kMemTitle = 0x40000000; | ||
| 231 | |||
| 232 | LPVOID WINAPI TitleVirtualAlloc(LPVOID address, SIZE_T size, DWORD allocation_type, DWORD protect) { | ||
| 233 | return VirtualAlloc(address, size, allocation_type & ~(kMemGraphics | kMemTitle), protect); | ||
| 234 | } | ||
| 235 | |||
| 222 | } // namespace | 236 | } // namespace |
| 223 | 237 | ||
| 238 | #define TITLE_VIRTUAL_ALLOC(dll) {dll, "VirtualAlloc", reinterpret_cast<void*>(&TitleVirtualAlloc)} | ||
| 239 | |||
| 240 | // The classic libraries and the memory api sets a title's imports name. | ||
| 241 | SHIM_TABLE(title_memory, | ||
| 242 | TITLE_VIRTUAL_ALLOC("kernel32.dll"), | ||
| 243 | TITLE_VIRTUAL_ALLOC("kernelbase.dll"), | ||
| 244 | TITLE_VIRTUAL_ALLOC("api-ms-win-core-memory-l1-1-0.dll"), | ||
| 245 | TITLE_VIRTUAL_ALLOC("api-ms-win-core-memory-l1-1-1.dll"), | ||
| 246 | TITLE_VIRTUAL_ALLOC("api-ms-win-core-memory-l1-1-2.dll"), | ||
| 247 | TITLE_VIRTUAL_ALLOC("api-ms-win-core-memory-l1-1-3.dll"), | ||
| 248 | TITLE_VIRTUAL_ALLOC("api-ms-win-core-memory-l1-1-4.dll"), | ||
| 249 | TITLE_VIRTUAL_ALLOC("api-ms-win-core-memory-l1-1-5.dll"), | ||
| 250 | TITLE_VIRTUAL_ALLOC("api-ms-win-core-memory-l1-1-6.dll"), | ||
| 251 | ); | ||
| 252 | |||
| 224 | SHIM_TABLE(xmem, | 253 | SHIM_TABLE(xmem, |
| 225 | {"xmem.dll", "XMemAlloc", reinterpret_cast<void*>(&XMemAlloc)}, | 254 | {"xmem.dll", "XMemAlloc", reinterpret_cast<void*>(&XMemAlloc)}, |
| 226 | {"xmem.dll", "XMemFree", reinterpret_cast<void*>(&XMemFree)}, | 255 | {"xmem.dll", "XMemFree", reinterpret_cast<void*>(&XMemFree)}, |