diff options
| author | hcristosm <hcristosm@gmail.com> | 2026-11-23 13:50:59 -0300 |
|---|---|---|
| committer | Mumogg <104529023+Mumogg@users.noreply.github.com> | 2026-11-23 21:09:28 -0600 |
| commit | 80ed5dd30438b507a03c6bb10e0adf0a0a403dea (patch) | |
| tree | 49169f564713d4ab94b8642295e4c4623c0bc860 /runtime/test/xmem_test.cpp | |
| parent | 84347bbb61ed406db10195f50d5911893b8b9a4b (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.
(cherry picked from commit 7e8e3c1db1dc3c4c44cc56e2e586f99de2e65ae2)
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 3ec621b0b..f552c5b6e 100644 --- a/runtime/test/xmem_test.cpp +++ b/runtime/test/xmem_test.cpp | |||
| @@ -694,6 +694,34 @@ void test_placeholders(const PhysicalApi& api) { | |||
| 694 | check(reserved_only(base), "the rest of the placeholder is still reserved"); | 694 | check(reserved_only(base), "the rest of the placeholder is still reserved"); |
| 695 | } | 695 | } |
| 696 | 696 | ||
| 697 | // Three of the retail executable's five physical-page windows carry 0x400 next to PAGE_READWRITE. That is | ||
| 698 | // PAGE_WRITECOMBINE on the PC, outside the PAGE_GRAPHICS_* range, and MapViewOfFile3 refuses a view with it, so the | ||
| 699 | // mapped pages take the window's protection without the cache modifier. | ||
| 700 | void test_write_combine_window(const PhysicalApi& api) { | ||
| 701 | auto* const window = static_cast<uint8_t*>( | ||
| 702 | api.virtual_alloc(nullptr, kPage64k, MEM_RESERVE | kXmem64kPages, 0x27, | ||
| 703 | PAGE_READWRITE | PAGE_WRITECOMBINE | PAGE_GRAPHICS_READWRITE)); | ||
| 704 | check(window != nullptr, "XMemVirtualAlloc reserves a window with PAGE_WRITECOMBINE in its protection"); | ||
| 705 | if (!window) return; | ||
| 706 | |||
| 707 | uint64_t page = 0; | ||
| 708 | uint64_t count = 1; | ||
| 709 | check(api.allocate(0x280, &count, &page) == TRUE && count == 1, "allocate a page for the write-combine window"); | ||
| 710 | SetLastError(ERROR_SUCCESS); | ||
| 711 | const bool mapped = api.map(window, 1, &page) == window; | ||
| 712 | check(mapped, "a page maps into a window reserved with PAGE_WRITECOMBINE"); | ||
| 713 | if (mapped) { | ||
| 714 | MEMORY_BASIC_INFORMATION info{}; | ||
| 715 | VirtualQuery(window, &info, sizeof(info)); | ||
| 716 | check(info.State == MEM_COMMIT && info.Protect == PAGE_READWRITE, | ||
| 717 | "the page mapped there is a plain read-write view"); | ||
| 718 | fill_page(window, 0x77000000u); | ||
| 719 | check(page_holds(window, 0x77000000u), "the page in the write-combine window holds data"); | ||
| 720 | } | ||
| 721 | check(api.map(window, 1, nullptr) == window, "unmap the write-combine window"); | ||
| 722 | check(api.free_pages(1, &page) == TRUE, "free the write-combine window's page"); | ||
| 723 | } | ||
| 724 | |||
| 697 | // gta6rt --trace: one "xmem_attributes" event per distinct raw attribute word and API, none with the trace off. | 725 | // gta6rt --trace: one "xmem_attributes" event per distinct raw attribute word and API, none with the trace off. |
| 698 | void test_attribute_trace(XMemAllocFn alloc, XMemFreeFn free_mem, XMemVirtualAllocFn virtual_alloc) { | 726 | void test_attribute_trace(XMemAllocFn alloc, XMemFreeFn free_mem, XMemVirtualAllocFn virtual_alloc) { |
| 699 | wchar_t temp[MAX_PATH]; | 727 | wchar_t temp[MAX_PATH]; |
| @@ -942,6 +970,7 @@ int main() { | |||
| 942 | test_commit_physical_pages(physical); | 970 | test_commit_physical_pages(physical); |
| 943 | test_first_touch_during_remap(physical); | 971 | test_first_touch_during_remap(physical); |
| 944 | test_placeholders(physical); | 972 | test_placeholders(physical); |
| 973 | test_write_combine_window(physical); | ||
| 945 | } | 974 | } |
| 946 | 975 | ||
| 947 | print_result(); | 976 | print_result(); |