From: Jactry Zeng <jzeng@codeweavers.com> This is to prove that the previous PagefileUsage implementation for macOS (PagefileUsage = mach_task_basic_info.virtual_size) is wrong. Some Windows applications query PagefileUsage to determine how much memory the application is using. Returning an oversized number will cause the application to think that memory is out of space. --- dlls/ntdll/tests/info.c | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/dlls/ntdll/tests/info.c b/dlls/ntdll/tests/info.c index 3d4c7d956f8..bcf2b8f3acd 100644 --- a/dlls/ntdll/tests/info.c +++ b/dlls/ntdll/tests/info.c @@ -1905,7 +1905,7 @@ static void test_query_process_vm(void) ULONG ReturnLength; VM_COUNTERS_EX pvi; HANDLE process; - SIZE_T prev_size; + SIZE_T prev_size, reserve_size; const SIZE_T alloc_size = 16 * 1024 * 1024; void *ptr; @@ -2002,6 +2002,17 @@ static void test_query_process_vm(void) ok( pvi.VirtualSize == prev_size, "Expected to equal to %Iu, got %Iu\n", prev_size, pvi.VirtualSize); VirtualFree( ptr, 0, MEM_RELEASE); + + /* Reserving memory shouldn't significantly increase PageFileUsage. */ + status = NtQueryInformationProcess(GetCurrentProcess(), ProcessVmCounters, &pvi, sizeof(pvi), NULL); + ok(status == STATUS_SUCCESS, "Got %#lx.\n", status); + reserve_size = pvi.PagefileUsage * 2; + ptr = VirtualAlloc(NULL, reserve_size, MEM_RESERVE, PAGE_READWRITE); + ok(!!ptr, "VirtualAlloc failed: %#lx.\n", GetLastError()); + status = NtQueryInformationProcess(GetCurrentProcess(), ProcessVmCounters, &pvi, sizeof(pvi), NULL); + ok(status == STATUS_SUCCESS, "Got %#lx.\n", status); + ok(pvi.PagefileUsage < reserve_size, "Wrong value %Iu/%Iu.\n", pvi.PagefileUsage, reserve_size ); + VirtualFree(ptr, 0, MEM_RELEASE); } static void test_query_process_io(void) -- GitLab https://gitlab.winehq.org/wine/wine/-/merge_requests/9857