[PATCH 2/6] ntdll: Pass a block pointer to initialize_block.
Rémi Bernon
wine at gitlab.winehq.org
Fri Jun 3 03:14:24 CDT 2022
From: Rémi Bernon <rbernon at codeweavers.com>
Signed-off-by: Rémi Bernon <rbernon at codeweavers.com>
---
dlls/ntdll/heap.c | 20 ++++++++++++--------
1 file changed, 12 insertions(+), 8 deletions(-)
diff --git a/dlls/ntdll/heap.c b/dlls/ntdll/heap.c
index 3184ae43dab..3ac819a37ac 100644
--- a/dlls/ntdll/heap.c
+++ b/dlls/ntdll/heap.c
@@ -368,17 +368,21 @@ static inline void mark_block_tail( struct block *block, DWORD flags )
}
/* initialize contents of a newly created block of memory */
-static inline void initialize_block( void *ptr, SIZE_T size, DWORD flags )
+static inline void initialize_block( struct block *block, SIZE_T old_size, SIZE_T size, DWORD flags )
{
+ char *data = (char *)(block + 1);
+
+ if (size <= old_size) return;
+
if (flags & HEAP_ZERO_MEMORY)
{
- valgrind_make_writable( ptr, size );
- memset( ptr, 0, size );
+ valgrind_make_writable( data + old_size, size - old_size );
+ memset( data + old_size, 0, size - old_size );
}
else if (flags & HEAP_FREE_CHECKING_ENABLED)
{
- valgrind_make_writable( ptr, size );
- memset( ptr, ARENA_INUSE_FILLER, size );
+ valgrind_make_writable( data + old_size, size - old_size );
+ memset( data + old_size, ARENA_INUSE_FILLER, size - old_size );
}
}
@@ -840,7 +844,7 @@ static void *realloc_large_block( HEAP *heap, DWORD flags, void *ptr, SIZE_T siz
{
/* FIXME: we could remap zero-pages instead */
valgrind_notify_resize( arena + 1, old_size, size );
- if (size > old_size) initialize_block( (char *)ptr + old_size, size - old_size, flags );
+ initialize_block( &arena->block, old_size, size, flags );
arena->data_size = size;
valgrind_make_noaccess( (char *)arena + sizeof(*arena) + arena->data_size,
arena->block_size - sizeof(*arena) - arena->data_size );
@@ -1522,7 +1526,7 @@ static NTSTATUS heap_allocate( HEAP *heap, ULONG flags, SIZE_T size, void **ret
block_set_type( block, ARENA_INUSE_MAGIC );
shrink_used_block( subheap, block, 0, old_block_size, block_size, size );
- initialize_block( block + 1, size, flags );
+ initialize_block( block, 0, size, flags );
mark_block_tail( block, flags );
*ret = block + 1;
@@ -1643,7 +1647,7 @@ static NTSTATUS heap_reallocate( HEAP *heap, ULONG flags, void *ptr, SIZE_T size
valgrind_notify_resize( block + 1, old_size, size );
shrink_used_block( subheap, block, block_get_flags( block ), old_block_size, block_size, size );
- if (size > old_size) initialize_block( (char *)(block + 1) + old_size, size - old_size, flags );
+ initialize_block( block, old_size, size, flags );
mark_block_tail( block, flags );
/* Return the new arena */
--
GitLab
https://gitlab.winehq.org/wine/wine/-/merge_requests/178
More information about the wine-devel
mailing list