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

ntdll: Return the old data size from heap_reallocate.

parent 4334c5b0
...@@ -1623,11 +1623,11 @@ BOOLEAN WINAPI DECLSPEC_HOTPATCH RtlFreeHeap( HANDLE handle, ULONG flags, void * ...@@ -1623,11 +1623,11 @@ BOOLEAN WINAPI DECLSPEC_HOTPATCH RtlFreeHeap( HANDLE handle, ULONG flags, void *
} }
static NTSTATUS heap_reallocate( struct heap *heap, ULONG flags, struct block *block, static NTSTATUS heap_reallocate( struct heap *heap, ULONG flags, struct block *block, SIZE_T block_size,
SIZE_T block_size, SIZE_T size, void **ret ) SIZE_T size, SIZE_T *old_size, void **ret )
{ {
SUBHEAP *subheap = block_get_subheap( heap, block ); SUBHEAP *subheap = block_get_subheap( heap, block );
SIZE_T old_block_size, old_size; SIZE_T old_block_size;
struct entry *entry; struct entry *entry;
struct block *next; struct block *next;
NTSTATUS status; NTSTATUS status;
...@@ -1636,7 +1636,7 @@ static NTSTATUS heap_reallocate( struct heap *heap, ULONG flags, struct block *b ...@@ -1636,7 +1636,7 @@ static NTSTATUS heap_reallocate( struct heap *heap, ULONG flags, struct block *b
{ {
ARENA_LARGE *large = CONTAINING_RECORD( block, ARENA_LARGE, block ); ARENA_LARGE *large = CONTAINING_RECORD( block, ARENA_LARGE, block );
old_block_size = large->block_size; old_block_size = large->block_size;
old_size = large->data_size; *old_size = large->data_size;
if (old_block_size - sizeof(*block) < size) if (old_block_size - sizeof(*block) < size)
{ {
...@@ -1646,8 +1646,8 @@ static NTSTATUS heap_reallocate( struct heap *heap, ULONG flags, struct block *b ...@@ -1646,8 +1646,8 @@ static NTSTATUS heap_reallocate( struct heap *heap, ULONG flags, struct block *b
} }
/* FIXME: we could remap zero-pages instead */ /* FIXME: we could remap zero-pages instead */
valgrind_notify_resize( block + 1, old_size, size ); valgrind_notify_resize( block + 1, *old_size, size );
initialize_block( block, old_size, size, flags ); initialize_block( block, *old_size, size, flags );
large->data_size = size; large->data_size = size;
valgrind_make_noaccess( (char *)block + sizeof(*block) + large->data_size, valgrind_make_noaccess( (char *)block + sizeof(*block) + large->data_size,
...@@ -1660,7 +1660,7 @@ static NTSTATUS heap_reallocate( struct heap *heap, ULONG flags, struct block *b ...@@ -1660,7 +1660,7 @@ static NTSTATUS heap_reallocate( struct heap *heap, ULONG flags, struct block *b
/* Check if we need to grow the block */ /* Check if we need to grow the block */
old_block_size = block_get_size( block ); old_block_size = block_get_size( block );
old_size = old_block_size - block_get_overhead( block ); *old_size = old_block_size - block_get_overhead( block );
if (block_size > old_block_size) if (block_size > old_block_size)
{ {
...@@ -1671,8 +1671,8 @@ static NTSTATUS heap_reallocate( struct heap *heap, ULONG flags, struct block *b ...@@ -1671,8 +1671,8 @@ static NTSTATUS heap_reallocate( struct heap *heap, ULONG flags, struct block *b
if (flags & HEAP_REALLOC_IN_PLACE_ONLY) return STATUS_NO_MEMORY; if (flags & HEAP_REALLOC_IN_PLACE_ONLY) return STATUS_NO_MEMORY;
if ((status = heap_allocate( heap, flags & ~HEAP_ZERO_MEMORY, block_size, size, ret ))) return status; if ((status = heap_allocate( heap, flags & ~HEAP_ZERO_MEMORY, block_size, size, ret ))) return status;
valgrind_notify_alloc( *ret, size, 0 ); valgrind_notify_alloc( *ret, size, 0 );
memcpy( *ret, block + 1, old_size ); memcpy( *ret, block + 1, *old_size );
if (flags & HEAP_ZERO_MEMORY) memset( (char *)*ret + old_size, 0, size - old_size ); if (flags & HEAP_ZERO_MEMORY) memset( (char *)*ret + *old_size, 0, size - *old_size );
valgrind_notify_free( block + 1 ); valgrind_notify_free( block + 1 );
free_used_block( heap, flags, block ); free_used_block( heap, flags, block );
return STATUS_SUCCESS; return STATUS_SUCCESS;
...@@ -1687,11 +1687,11 @@ static NTSTATUS heap_reallocate( struct heap *heap, ULONG flags, struct block *b ...@@ -1687,11 +1687,11 @@ static NTSTATUS heap_reallocate( struct heap *heap, ULONG flags, struct block *b
old_block_size += block_get_size( next ); old_block_size += block_get_size( next );
} }
valgrind_notify_resize( block + 1, old_size, size ); valgrind_notify_resize( block + 1, *old_size, size );
block_set_flags( block, BLOCK_FLAG_USER_MASK & ~BLOCK_FLAG_USER_INFO, BLOCK_USER_FLAGS( flags ) ); block_set_flags( block, BLOCK_FLAG_USER_MASK & ~BLOCK_FLAG_USER_INFO, BLOCK_USER_FLAGS( flags ) );
shrink_used_block( heap, flags, block, old_block_size, block_size, size ); shrink_used_block( heap, flags, block, old_block_size, block_size, size );
initialize_block( block, old_size, size, flags ); initialize_block( block, *old_size, size, flags );
mark_block_tail( block, flags ); mark_block_tail( block, flags );
*ret = block + 1; *ret = block + 1;
...@@ -1703,9 +1703,9 @@ static NTSTATUS heap_reallocate( struct heap *heap, ULONG flags, struct block *b ...@@ -1703,9 +1703,9 @@ static NTSTATUS heap_reallocate( struct heap *heap, ULONG flags, struct block *b
*/ */
void *WINAPI RtlReAllocateHeap( HANDLE handle, ULONG flags, void *ptr, SIZE_T size ) void *WINAPI RtlReAllocateHeap( HANDLE handle, ULONG flags, void *ptr, SIZE_T size )
{ {
SIZE_T block_size, old_size;
struct block *block; struct block *block;
struct heap *heap; struct heap *heap;
SIZE_T block_size;
ULONG heap_flags; ULONG heap_flags;
void *ret = NULL; void *ret = NULL;
NTSTATUS status; NTSTATUS status;
...@@ -1721,7 +1721,7 @@ void *WINAPI RtlReAllocateHeap( HANDLE handle, ULONG flags, void *ptr, SIZE_T si ...@@ -1721,7 +1721,7 @@ void *WINAPI RtlReAllocateHeap( HANDLE handle, ULONG flags, void *ptr, SIZE_T si
else else
{ {
heap_lock( heap, heap_flags ); heap_lock( heap, heap_flags );
status = heap_reallocate( heap, heap_flags, block, block_size, size, &ret ); status = heap_reallocate( heap, heap_flags, block, block_size, size, &old_size, &ret );
heap_unlock( heap, heap_flags ); heap_unlock( heap, heap_flags );
} }
......
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