diff options
| author | Jan Trencansky <jan.trencansky@protonmail.com> | 2026-11-24 20:37:26 -0500 |
|---|---|---|
| committer | Jan Trencansky <jan.trencansky@protonmail.com> | 2026-11-24 20:37:26 -0500 |
| commit | 38bd89d44e6a790010de5ad22a6b891e7869fdd8 (patch) | |
| tree | bd525ee65267496f1b201fa3d5c138847e7f1c1b /runtime/test/xmem_test.cpp | |
| parent | 545e8d51f148ad2c2b26c16b9e1630c634cf5270 (diff) | |
| parent | 71a783e56fb6eb591849b5c9fb6618ed3af3f595 (diff) | |
Merge the #984 result as of 71a783e56 into the #939 merge
Fourteen commits the #984 merge gained after 8a242efeb: its own failing tests (xmem_test under Wine, check_tls_index0, vk_bindless_grow, xs_present_lazy_test), the console-heap probe and the poke experiment behind their switches, Python tool fixes, and the title watchdog default. No conflicts.
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.cpp | 42 |
1 files changed, 36 insertions, 6 deletions
diff --git a/runtime/test/xmem_test.cpp b/runtime/test/xmem_test.cpp index 638100414..7b9d8d7ae 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. | ||
| 403 | bool 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. | ||
| 412 | bool 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 | |||
| 402 | struct PhysicalApi { | 420 | struct 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 | } |