upleb.uk

Public git repos — served from a NIP-34 GRASP relay at git.upleb.uk

summaryrefslogtreecommitdiff
path: root/runtime/test/xmem_test.cpp
diff options
context:
space:
mode:
authorJan Trencansky <jan.trencansky@protonmail.com>2026-11-24 20:18:35 -0500
committerJan Trencansky <jan.trencansky@protonmail.com>2026-11-24 20:18:35 -0500
commit2deadb0763b82898a15d161be27962a7a3596bce (patch)
tree1a6aedf8fd1e89e8e2d631cf2f2a3fdb7ba8f8aa /runtime/test/xmem_test.cpp
parent8223f2825679d5c7025b41de92704bd61b71c52e (diff)
xmem_test: view checks that hold under Wine, and say what Wine cannot show
Three checks of the physical-page views fail under Wine, two of them on main as well (xmem is a known Wine failure there) and one that #984 adds; with #984 registering the test twice more (xmem_write_watch, xmem_no_write_watch) that made three red tests. Measured under Wine 11: a page of a reserved section view that has been written and reads back is still reported by VirtualQuery as MEM_RESERVE with protection 0 (type MEM_MAPPED, allocation protection PAGE_READWRITE), where Windows reports MEM_COMMIT and PAGE_READWRITE. - 'unmapping one of them afterwards keeps the others' memory' (#984) asked whether the neighbours were still mapped through reserved_only(), which is the reported state. It asks for the view itself now (in_view: the region's type is MEM_MAPPED), which is what the check is about, and also that the unmapped page is no longer in one. Same on both hosts. - The two checks of the reported state and protection of a written view page print SKIP with the reason when the host is Wine and gives exactly that answer; the first then still checks that the page is a read-write view holding what was written. On Windows both run as before. Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
Diffstat (limited to 'runtime/test/xmem_test.cpp')
-rw-r--r--runtime/test/xmem_test.cpp42
1 files changed, 36 insertions, 6 deletions
diff --git a/runtime/test/xmem_test.cpp b/runtime/test/xmem_test.cpp
index 3560c02a3..f7d766d4e 100644
--- a/runtime/test/xmem_test.cpp
+++ b/runtime/test/xmem_test.cpp
@@ -399,6 +399,24 @@ bool reserved_only(const void* address) {
399 return VirtualQuery(address, &info, sizeof(info)) && info.State == MEM_RESERVE; 399 return VirtualQuery(address, &info, sizeof(info)) && info.State == MEM_RESERVE;
400} 400}
401 401
402// The address is inside a section view (whatever state the host reports for its pages), not a bare reservation.
403bool in_view(const void* address) {
404 MEMORY_BASIC_INFORMATION info{};
405 return VirtualQuery(address, &info, sizeof(info)) && info.Type == MEM_MAPPED;
406}
407
408// Physical pages are views of a reserved section and are committed on first touch. Windows then reports the page as
409// MEM_COMMIT with its protection. Wine's VirtualQuery keeps reporting MEM_RESERVE and no protection for a view page
410// that has been written and reads back, so a check of the reported state and protection has nothing to look at
411// there. True for exactly that answer on that host; the caller says what it skips.
412bool touched_view_reported_reserved(const MEMORY_BASIC_INFORMATION& info) {
413 static const bool wine = [] {
414 const HMODULE ntdll = GetModuleHandleW(L"ntdll.dll");
415 return ntdll && GetProcAddress(ntdll, "wine_get_version") != nullptr;
416 }();
417 return wine && info.Type == MEM_MAPPED && info.State == MEM_RESERVE && info.Protect == 0;
418}
419
402struct PhysicalApi { 420struct PhysicalApi {
403 XMemVirtualAllocFn virtual_alloc; 421 XMemVirtualAllocFn virtual_alloc;
404 XMemAllocatePhysicalPagesFn allocate; 422 XMemAllocatePhysicalPagesFn allocate;
@@ -438,8 +456,16 @@ void test_physical_pages(const PhysicalApi& api) {
438 { 456 {
439 MEMORY_BASIC_INFORMATION info{}; 457 MEMORY_BASIC_INFORMATION info{};
440 VirtualQuery(window, &info, sizeof(info)); 458 VirtualQuery(window, &info, sizeof(info));
441 check(info.State == MEM_COMMIT && info.Type == MEM_MAPPED && info.Protect == PAGE_READWRITE, 459 if (touched_view_reported_reserved(info)) {
442 "a mapped page is a read-write view with the window's protection"); 460 std::printf("SKIP the mapped page's reported state and protection: this host's VirtualQuery shows a "
461 "written view page as reserved (Wine)\n");
462 check(info.Type == MEM_MAPPED && info.AllocationProtect == PAGE_READWRITE &&
463 page_holds(window, 0x1000u),
464 "a mapped page is a read-write view that holds what was written");
465 } else {
466 check(info.State == MEM_COMMIT && info.Type == MEM_MAPPED && info.Protect == PAGE_READWRITE,
467 "a mapped page is a read-write view with the window's protection");
468 }
443 check(info.AllocationBase == window && info.RegionSize == kPages * kPage64k, 469 check(info.AllocationBase == window && info.RegionSize == kPages * kPage64k,
444 "consecutive pages of one allocation are mapped as one view"); 470 "consecutive pages of one allocation are mapped as one view");
445 } 471 }
@@ -841,8 +867,8 @@ void test_long_run(const PhysicalApi& api) {
841 for (uint64_t i = 0; i < 4; ++i) fill_page(window + i * kPage64k, static_cast<uint32_t>(i + 1)); 867 for (uint64_t i = 0; i < 4; ++i) fill_page(window + i * kPage64k, static_cast<uint32_t>(i + 1));
842 check(api.free_pages(4, pages.data()) == TRUE, "they are freed while mapped"); 868 check(api.free_pages(4, pages.data()) == TRUE, "they are freed while mapped");
843 void* const second = window + kPage64k; 869 void* const second = window + kPage64k;
844 check(api.scatter(&second, 1, nullptr) == TRUE && !reserved_only(window) && 870 check(api.scatter(&second, 1, nullptr) == TRUE && in_view(window) && !in_view(second) &&
845 !reserved_only(window + 2 * kPage64k) && page_holds(window, 1u) && 871 in_view(window + 2 * kPage64k) && page_holds(window, 1u) &&
846 page_holds(window + 2 * kPage64k, 3u) && page_holds(window + 3 * kPage64k, 4u), 872 page_holds(window + 2 * kPage64k, 3u) && page_holds(window + 3 * kPage64k, 4u),
847 "unmapping one of them afterwards keeps the others' memory"); 873 "unmapping one of them afterwards keeps the others' memory");
848 api.map(window, 4, nullptr); 874 api.map(window, 4, nullptr);
@@ -903,8 +929,12 @@ void test_write_combine_window(const PhysicalApi& api) {
903 *static_cast<volatile unsigned char*>(window) = 1; 929 *static_cast<volatile unsigned char*>(window) = 1;
904 MEMORY_BASIC_INFORMATION info{}; 930 MEMORY_BASIC_INFORMATION info{};
905 VirtualQuery(window, &info, sizeof(info)); 931 VirtualQuery(window, &info, sizeof(info));
906 check(info.State == MEM_COMMIT && info.Protect == PAGE_READWRITE, 932 if (touched_view_reported_reserved(info))
907 "the page mapped there is a plain read-write view"); 933 std::printf("SKIP the write-combine window page's reported state and protection: this host's "
934 "VirtualQuery shows a written view page as reserved (Wine)\n");
935 else
936 check(info.State == MEM_COMMIT && info.Protect == PAGE_READWRITE,
937 "the page mapped there is a plain read-write view");
908 fill_page(window, 0x77000000u); 938 fill_page(window, 0x77000000u);
909 check(page_holds(window, 0x77000000u), "the page in the write-combine window holds data"); 939 check(page_holds(window, 0x77000000u), "the page in the write-combine window holds data");
910 } 940 }