[PATCH v2] ntdll: Avoid the lower 2GB region for large allocations on win64.

Elaine Lefler elaineclefler at gmail.com
Wed Mar 23 00:37:23 CDT 2022


Fixes a crash in PaintTool SAI when allocating more than 2GB of memory.

Signed-off-by: Elaine Lefler <elaineclefler at gmail.com>
---

v2: Removed todo_wine from appropriate tests, along with a note about
why that test is broken on win32.
---
 dlls/ntdll/tests/info.c   | 16 ++++++++++++----
 dlls/ntdll/unix/virtual.c |  6 +++++-
 2 files changed, 17 insertions(+), 5 deletions(-)

diff --git a/dlls/ntdll/tests/info.c b/dlls/ntdll/tests/info.c
index d3e70842b00..3652d907db5 100644
--- a/dlls/ntdll/tests/info.c
+++ b/dlls/ntdll/tests/info.c
@@ -1840,8 +1840,13 @@ static void test_query_process_vm(void)
     ok( pvi.PrivateUsage == pvi.PagefileUsage, "wrong value %Iu/%Iu\n", pvi.PrivateUsage, pvi.PagefileUsage );
     if (winetest_debug > 1)
         dump_vm_counters("VM counters after VirtualAlloc", &pvi);
-    todo_wine ok( pvi.VirtualSize >= prev_size + alloc_size,
-        "Expected to be greater than %Iu, got %Iu\n", prev_size + alloc_size, pvi.VirtualSize);
+#ifndef _WIN64
+    /* Fails on win32 due to mapping in reserved areas. The unused regions
+     * should be subtracted from VirtualSize for it to succeed. */
+    todo_wine
+#endif
+        ok( pvi.VirtualSize >= prev_size + alloc_size,
+            "Expected to be at least %Iu, got %Iu\n", prev_size + alloc_size, pvi.VirtualSize);
     VirtualFree( ptr, 0, MEM_RELEASE);
 
     status = pNtQueryInformationProcess(GetCurrentProcess(), ProcessVmCounters, &pvi, sizeof(pvi), NULL);
@@ -1857,8 +1862,11 @@ static void test_query_process_vm(void)
     ok( pvi.PrivateUsage == pvi.PagefileUsage, "wrong value %Iu/%Iu\n", pvi.PrivateUsage, pvi.PagefileUsage );
     if (winetest_debug > 1)
         dump_vm_counters("VM counters after VirtualAlloc(MEM_RESERVE)", &pvi);
-    todo_wine ok( pvi.VirtualSize >= prev_size + alloc_size,
-        "Expected to be greater than %Iu, got %Iu\n", prev_size + alloc_size, pvi.VirtualSize);
+#ifndef _WIN64
+    todo_wine
+#endif
+        ok( pvi.VirtualSize >= prev_size + alloc_size,
+            "Expected to be at least %Iu, got %Iu\n", prev_size + alloc_size, pvi.VirtualSize);
     prev_size = pvi.VirtualSize;
 
     ptr = VirtualAlloc(ptr, alloc_size, MEM_COMMIT, PAGE_READWRITE);
diff --git a/dlls/ntdll/unix/virtual.c b/dlls/ntdll/unix/virtual.c
index 94b300c5057..eac9bcb1f83 100644
--- a/dlls/ntdll/unix/virtual.c
+++ b/dlls/ntdll/unix/virtual.c
@@ -1917,7 +1917,11 @@ static NTSTATUS map_view( struct file_view **view_ret, void *base, size_t size,
         alloc.top_down = top_down;
         alloc.limit = (void*)(get_zero_bits_mask( zero_bits ) & (UINT_PTR)user_space_limit);
 
-        if (mmap_enum_reserved_areas( alloc_reserved_area_callback, &alloc, top_down ))
+        if (
+#ifdef _WIN64
+                size < 2 * 1024 * 1024 &&
+#endif
+                mmap_enum_reserved_areas( alloc_reserved_area_callback, &alloc, top_down ))
         {
             ptr = alloc.result;
             TRACE( "got mem in reserved area %p-%p\n", ptr, (char *)ptr + size );
-- 
2.32.0 (Apple Git-132)




More information about the wine-devel mailing list