Skip to content

Commit f38cf7e

Browse files
Paul Gofmanivyl
authored andcommitted
ntdll: HACK: Introduce WINE_HEAP_TOP_DOWN hack.
CW-Bug-Id: #24362
1 parent e63117c commit f38cf7e

File tree

3 files changed

+11
-1
lines changed

3 files changed

+11
-1
lines changed

dlls/ntdll/heap.c

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -330,6 +330,7 @@ C_ASSERT( HEAP_MIN_LARGE_BLOCK_SIZE <= HEAP_INITIAL_GROW_SIZE );
330330

331331
BOOL delay_heap_free = FALSE;
332332
BOOL heap_zero_hack = FALSE;
333+
BOOL heap_top_down_hack = FALSE;
333334

334335
static struct heap *process_heap; /* main process heap */
335336

@@ -971,6 +972,7 @@ static struct block *split_block( struct heap *heap, ULONG flags, struct block *
971972

972973
static void *allocate_region( struct heap *heap, ULONG flags, SIZE_T *region_size, SIZE_T *commit_size )
973974
{
975+
ULONG reserve_flags = MEM_RESERVE;
974976
void *addr = NULL;
975977
NTSTATUS status;
976978

@@ -980,8 +982,10 @@ static void *allocate_region( struct heap *heap, ULONG flags, SIZE_T *region_siz
980982
return NULL;
981983
}
982984

985+
if (heap_top_down_hack) reserve_flags |= MEM_TOP_DOWN;
986+
983987
/* allocate the memory block */
984-
if ((status = NtAllocateVirtualMemory( NtCurrentProcess(), &addr, 0, region_size, MEM_RESERVE,
988+
if ((status = NtAllocateVirtualMemory( NtCurrentProcess(), &addr, 0, region_size, reserve_flags,
985989
get_protection_type( flags ) )))
986990
{
987991
WARN( "Could not allocate %#Ix bytes, status %#lx\n", *region_size, status );

dlls/ntdll/loader.c

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4651,6 +4651,11 @@ void loader_init( CONTEXT *context, void **entry )
46514651
ERR( "Enabling heap zero hack.\n" );
46524652
heap_zero_hack = TRUE;
46534653
}
4654+
if (get_env( L"WINE_HEAP_TOP_DOWN", env_str, sizeof(env_str)) && env_str[0] == L'1')
4655+
{
4656+
ERR( "Enabling heap top down hack.\n" );
4657+
heap_top_down_hack = TRUE;
4658+
}
46544659

46554660
peb->ProcessHeap = RtlCreateHeap( heap_flags, NULL, 0, 0, NULL, NULL );
46564661

dlls/ntdll/ntdll_misc.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@ extern UINT_PTR page_size;
4949

5050
extern BOOL delay_heap_free;
5151
extern BOOL heap_zero_hack;
52+
extern BOOL heap_top_down_hack;
5253

5354
/* exceptions */
5455
extern LONG call_vectored_handlers( EXCEPTION_RECORD *rec, CONTEXT *context );

0 commit comments

Comments
 (0)