Skip to content

Commit

Permalink
ntdll: HACK: Introduce WINE_HEAP_TOP_DOWN hack.
Browse files Browse the repository at this point in the history
CW-Bug-Id: #24362
  • Loading branch information
Paul Gofman authored and ivyl committed Oct 16, 2024
1 parent e63117c commit f38cf7e
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 1 deletion.
6 changes: 5 additions & 1 deletion dlls/ntdll/heap.c
Original file line number Diff line number Diff line change
Expand Up @@ -330,6 +330,7 @@ C_ASSERT( HEAP_MIN_LARGE_BLOCK_SIZE <= HEAP_INITIAL_GROW_SIZE );

BOOL delay_heap_free = FALSE;
BOOL heap_zero_hack = FALSE;
BOOL heap_top_down_hack = FALSE;

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

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

static void *allocate_region( struct heap *heap, ULONG flags, SIZE_T *region_size, SIZE_T *commit_size )
{
ULONG reserve_flags = MEM_RESERVE;
void *addr = NULL;
NTSTATUS status;

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

if (heap_top_down_hack) reserve_flags |= MEM_TOP_DOWN;

/* allocate the memory block */
if ((status = NtAllocateVirtualMemory( NtCurrentProcess(), &addr, 0, region_size, MEM_RESERVE,
if ((status = NtAllocateVirtualMemory( NtCurrentProcess(), &addr, 0, region_size, reserve_flags,
get_protection_type( flags ) )))
{
WARN( "Could not allocate %#Ix bytes, status %#lx\n", *region_size, status );
Expand Down
5 changes: 5 additions & 0 deletions dlls/ntdll/loader.c
Original file line number Diff line number Diff line change
Expand Up @@ -4651,6 +4651,11 @@ void loader_init( CONTEXT *context, void **entry )
ERR( "Enabling heap zero hack.\n" );
heap_zero_hack = TRUE;
}
if (get_env( L"WINE_HEAP_TOP_DOWN", env_str, sizeof(env_str)) && env_str[0] == L'1')
{
ERR( "Enabling heap top down hack.\n" );
heap_top_down_hack = TRUE;
}

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

Expand Down
1 change: 1 addition & 0 deletions dlls/ntdll/ntdll_misc.h
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ extern UINT_PTR page_size;

extern BOOL delay_heap_free;
extern BOOL heap_zero_hack;
extern BOOL heap_top_down_hack;

/* exceptions */
extern LONG call_vectored_handlers( EXCEPTION_RECORD *rec, CONTEXT *context );
Expand Down

0 comments on commit f38cf7e

Please sign in to comment.