Rémi Bernon : ntdll: Fail to allocate large blocks if heap isn't growable.

Alexandre Julliard julliard at winehq.org
Wed May 18 15:38:30 CDT 2022


Module: wine
Branch: master
Commit: 3728b2b7d280f2bcfb44ef50c13e248162a36787
URL:    https://source.winehq.org/git/wine.git/?a=commit;h=3728b2b7d280f2bcfb44ef50c13e248162a36787

Author: Rémi Bernon <rbernon at codeweavers.com>
Date:   Mon May  2 13:27:58 2022 +0200

ntdll: Fail to allocate large blocks if heap isn't growable.

This tweaks the test sizes so that it passes on Wine too. The created
heap should be large enough to hold the requested alloc size, but the
allocation still fails.

Windows seems to have a specific lower threshold for large blocks with
non growable heaps, but it's probably not very useful to match it.

Signed-off-by: Rémi Bernon <rbernon at codeweavers.com>
Signed-off-by: Alexandre Julliard <julliard at winehq.org>

---

 dlls/kernel32/tests/heap.c | 6 ++----
 dlls/ntdll/heap.c          | 5 +++--
 2 files changed, 5 insertions(+), 6 deletions(-)

diff --git a/dlls/kernel32/tests/heap.c b/dlls/kernel32/tests/heap.c
index 1b8e019c0ec..d9cae9f723b 100644
--- a/dlls/kernel32/tests/heap.c
+++ b/dlls/kernel32/tests/heap.c
@@ -456,7 +456,7 @@ static void test_HeapCreate(void)
     ok( ret, "HeapDestroy failed, error %lu\n", GetLastError() );
 
 
-    heap = HeapCreate( 0, 2 * alloc_size, 5 * alloc_size );
+    heap = HeapCreate( 0, 8 * alloc_size, 8 * alloc_size );
     ok( !!heap, "HeapCreate failed, error %lu\n", GetLastError() );
     ok( !((ULONG_PTR)heap & 0xffff), "wrong heap alignment\n" );
 
@@ -470,10 +470,8 @@ static void test_HeapCreate(void)
     /* cannot allocate large blocks from fixed size heap */
 
     SetLastError( 0xdeadbeef );
-    ptr1 = HeapAlloc( heap, 0, 3 * alloc_size );
-    todo_wine
+    ptr1 = HeapAlloc( heap, 0, 4 * alloc_size );
     ok( !ptr1, "HeapAlloc succeeded\n" );
-    todo_wine
     ok( GetLastError() == ERROR_NOT_ENOUGH_MEMORY, "got error %lu\n", GetLastError() );
     ret = HeapFree( heap, 0, ptr1 );
     ok( ret, "HeapFree failed, error %lu\n", GetLastError() );
diff --git a/dlls/ntdll/heap.c b/dlls/ntdll/heap.c
index 75622da7a6a..fa9f617f482 100644
--- a/dlls/ntdll/heap.c
+++ b/dlls/ntdll/heap.c
@@ -841,6 +841,7 @@ static void *allocate_large_block( HEAP *heap, DWORD flags, SIZE_T size )
     SIZE_T block_size = sizeof(*arena) + ROUND_SIZE(size) + HEAP_TAIL_EXTRA_SIZE(flags);
     LPVOID address = NULL;
 
+    if (!(flags & HEAP_GROWABLE)) return NULL;
     if (block_size < size) return NULL;  /* overflow */
     if (NtAllocateVirtualMemory( NtCurrentProcess(), &address, 0, &block_size,
                                  MEM_COMMIT, get_protection_type( flags )))
@@ -1561,7 +1562,7 @@ static NTSTATUS heap_allocate( HEAP *heap, ULONG flags, SIZE_T size, void **ret
     if (rounded_size < size) return STATUS_NO_MEMORY;  /* overflow */
     if (rounded_size < HEAP_MIN_DATA_SIZE) rounded_size = HEAP_MIN_DATA_SIZE;
 
-    if (rounded_size >= HEAP_MIN_LARGE_BLOCK_SIZE && (flags & HEAP_GROWABLE))
+    if (rounded_size >= HEAP_MIN_LARGE_BLOCK_SIZE)
     {
         if (!(*ret = allocate_large_block( heap, flags, size ))) return STATUS_NO_MEMORY;
         return STATUS_SUCCESS;
@@ -1685,7 +1686,7 @@ static NTSTATUS heap_reallocate( HEAP *heap, ULONG flags, void *ptr, SIZE_T size
     {
         struct block *next;
 
-        if (rounded_size >= HEAP_MIN_LARGE_BLOCK_SIZE && (flags & HEAP_GROWABLE))
+        if (rounded_size >= HEAP_MIN_LARGE_BLOCK_SIZE)
         {
             if (flags & HEAP_REALLOC_IN_PLACE_ONLY) return STATUS_NO_MEMORY;
             if (!(*ret = allocate_large_block( heap, flags, size ))) return STATUS_NO_MEMORY;




More information about the wine-cvs mailing list