Commit 3728b2b7 authored by Rémi Bernon's avatar Rémi Bernon Committed by Alexandre Julliard

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: 's avatarRémi Bernon <rbernon@codeweavers.com> Signed-off-by: 's avatarAlexandre Julliard <julliard@winehq.org>
parent 69c75b2b
...@@ -456,7 +456,7 @@ static void test_HeapCreate(void) ...@@ -456,7 +456,7 @@ static void test_HeapCreate(void)
ok( ret, "HeapDestroy failed, error %lu\n", GetLastError() ); 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( !!heap, "HeapCreate failed, error %lu\n", GetLastError() );
ok( !((ULONG_PTR)heap & 0xffff), "wrong heap alignment\n" ); ok( !((ULONG_PTR)heap & 0xffff), "wrong heap alignment\n" );
...@@ -470,10 +470,8 @@ static void test_HeapCreate(void) ...@@ -470,10 +470,8 @@ static void test_HeapCreate(void)
/* cannot allocate large blocks from fixed size heap */ /* cannot allocate large blocks from fixed size heap */
SetLastError( 0xdeadbeef ); SetLastError( 0xdeadbeef );
ptr1 = HeapAlloc( heap, 0, 3 * alloc_size ); ptr1 = HeapAlloc( heap, 0, 4 * alloc_size );
todo_wine
ok( !ptr1, "HeapAlloc succeeded\n" ); ok( !ptr1, "HeapAlloc succeeded\n" );
todo_wine
ok( GetLastError() == ERROR_NOT_ENOUGH_MEMORY, "got error %lu\n", GetLastError() ); ok( GetLastError() == ERROR_NOT_ENOUGH_MEMORY, "got error %lu\n", GetLastError() );
ret = HeapFree( heap, 0, ptr1 ); ret = HeapFree( heap, 0, ptr1 );
ok( ret, "HeapFree failed, error %lu\n", GetLastError() ); ok( ret, "HeapFree failed, error %lu\n", GetLastError() );
......
...@@ -841,6 +841,7 @@ static void *allocate_large_block( HEAP *heap, DWORD flags, SIZE_T size ) ...@@ -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); SIZE_T block_size = sizeof(*arena) + ROUND_SIZE(size) + HEAP_TAIL_EXTRA_SIZE(flags);
LPVOID address = NULL; LPVOID address = NULL;
if (!(flags & HEAP_GROWABLE)) return NULL;
if (block_size < size) return NULL; /* overflow */ if (block_size < size) return NULL; /* overflow */
if (NtAllocateVirtualMemory( NtCurrentProcess(), &address, 0, &block_size, if (NtAllocateVirtualMemory( NtCurrentProcess(), &address, 0, &block_size,
MEM_COMMIT, get_protection_type( flags ))) MEM_COMMIT, get_protection_type( flags )))
...@@ -1561,7 +1562,7 @@ static NTSTATUS heap_allocate( HEAP *heap, ULONG flags, SIZE_T size, void **ret ...@@ -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 < size) return STATUS_NO_MEMORY; /* overflow */
if (rounded_size < HEAP_MIN_DATA_SIZE) rounded_size = HEAP_MIN_DATA_SIZE; 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; if (!(*ret = allocate_large_block( heap, flags, size ))) return STATUS_NO_MEMORY;
return STATUS_SUCCESS; return STATUS_SUCCESS;
...@@ -1685,7 +1686,7 @@ static NTSTATUS heap_reallocate( HEAP *heap, ULONG flags, void *ptr, SIZE_T size ...@@ -1685,7 +1686,7 @@ static NTSTATUS heap_reallocate( HEAP *heap, ULONG flags, void *ptr, SIZE_T size
{ {
struct block *next; 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 (flags & HEAP_REALLOC_IN_PLACE_ONLY) return STATUS_NO_MEMORY;
if (!(*ret = allocate_large_block( heap, flags, size ))) return STATUS_NO_MEMORY; if (!(*ret = allocate_large_block( heap, flags, size ))) return STATUS_NO_MEMORY;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment