diff options
| author | hcristosm <hcristosm@gmail.com> | 2026-11-23 13:50:59 -0300 |
|---|---|---|
| committer | hcristosm <hcristosm@gmail.com> | 2026-11-23 13:50:59 -0300 |
| commit | 7e8e3c1db1dc3c4c44cc56e2e586f99de2e65ae2 (patch) | |
| tree | 47dd9d8beb005b14fd1f3ea13b90bc53b276a0e6 /runtime/test/xmem_test.cpp | |
| parent | 37f2151079c9105e177607e548423d02670fe2d4 (diff) | |
xmem: map physical pages without a cache modifier in the view protection
Three of the retail executable's five physical-page windows carry 0x400
(PAGE_WRITECOMBINE on the PC) next to PAGE_READWRITE. host_protect drops only the
PAGE_GRAPHICS_* range, so map_page passed PAGE_READWRITE | PAGE_WRITECOMBINE to
MapViewOfFile3, which refuses it with ERROR_INVALID_PARAMETER: the first
XMemMapPhysicalPages into such a window failed and the title's descriptor-heap
setup returned false.
view_protect now drops PAGE_WRITECOMBINE, PAGE_NOCACHE and PAGE_GUARD.
xmem_test maps a page into a window reserved with that protection.
AI-assisted.
Diffstat (limited to 'runtime/test/xmem_test.cpp')
| -rw-r--r-- | runtime/test/xmem_test.cpp | 29 |
1 files changed, 29 insertions, 0 deletions
diff --git a/runtime/test/xmem_test.cpp b/runtime/test/xmem_test.cpp index eed030c12..53df7fcc5 100644 --- a/runtime/test/xmem_test.cpp +++ b/runtime/test/xmem_test.cpp | |||
| @@ -474,6 +474,34 @@ void test_placeholders(const PhysicalApi& api) { | |||
| 474 | check(reserved_only(base), "the rest of the placeholder is still reserved"); | 474 | check(reserved_only(base), "the rest of the placeholder is still reserved"); |
| 475 | } | 475 | } |
| 476 | 476 | ||
| 477 | // Three of the retail executable's five physical-page windows carry 0x400 next to PAGE_READWRITE. That is | ||
| 478 | // PAGE_WRITECOMBINE on the PC, outside the PAGE_GRAPHICS_* range, and MapViewOfFile3 refuses a view with it, so the | ||
| 479 | // mapped pages take the window's protection without the cache modifier. | ||
| 480 | void test_write_combine_window(const PhysicalApi& api) { | ||
| 481 | auto* const window = static_cast<uint8_t*>( | ||
| 482 | api.virtual_alloc(nullptr, kPage64k, MEM_RESERVE | kXmem64kPages, 0x27, | ||
| 483 | PAGE_READWRITE | PAGE_WRITECOMBINE | PAGE_GRAPHICS_READWRITE)); | ||
| 484 | check(window != nullptr, "XMemVirtualAlloc reserves a window with PAGE_WRITECOMBINE in its protection"); | ||
| 485 | if (!window) return; | ||
| 486 | |||
| 487 | uint64_t page = 0; | ||
| 488 | uint64_t count = 1; | ||
| 489 | check(api.allocate(0x280, &count, &page) == TRUE && count == 1, "allocate a page for the write-combine window"); | ||
| 490 | SetLastError(ERROR_SUCCESS); | ||
| 491 | const bool mapped = api.map(window, 1, &page) == window; | ||
| 492 | check(mapped, "a page maps into a window reserved with PAGE_WRITECOMBINE"); | ||
| 493 | if (mapped) { | ||
| 494 | MEMORY_BASIC_INFORMATION info{}; | ||
| 495 | VirtualQuery(window, &info, sizeof(info)); | ||
| 496 | check(info.State == MEM_COMMIT && info.Protect == PAGE_READWRITE, | ||
| 497 | "the page mapped there is a plain read-write view"); | ||
| 498 | fill_page(window, 0x77000000u); | ||
| 499 | check(page_holds(window, 0x77000000u), "the page in the write-combine window holds data"); | ||
| 500 | } | ||
| 501 | check(api.map(window, 1, nullptr) == window, "unmap the write-combine window"); | ||
| 502 | check(api.free_pages(1, &page) == TRUE, "free the write-combine window's page"); | ||
| 503 | } | ||
| 504 | |||
| 477 | // gta6rt --trace: one "xmem_attributes" event per distinct raw attribute word and API, none with the trace off. | 505 | // gta6rt --trace: one "xmem_attributes" event per distinct raw attribute word and API, none with the trace off. |
| 478 | void test_attribute_trace(XMemAllocFn alloc, XMemFreeFn free_mem, XMemVirtualAllocFn virtual_alloc) { | 506 | void test_attribute_trace(XMemAllocFn alloc, XMemFreeFn free_mem, XMemVirtualAllocFn virtual_alloc) { |
| 479 | wchar_t temp[MAX_PATH]; | 507 | wchar_t temp[MAX_PATH]; |
| @@ -719,6 +747,7 @@ int main() { | |||
| 719 | if (virtual_alloc && physical.allocate && physical.free_pages && physical.map && physical.scatter) { | 747 | if (virtual_alloc && physical.allocate && physical.free_pages && physical.map && physical.scatter) { |
| 720 | test_physical_pages(physical); | 748 | test_physical_pages(physical); |
| 721 | test_placeholders(physical); | 749 | test_placeholders(physical); |
| 750 | test_write_combine_window(physical); | ||
| 722 | } | 751 | } |
| 723 | 752 | ||
| 724 | print_result(); | 753 | print_result(); |