Rémi Bernon : ntdll: Introduce new helper to update block type.
Alexandre Julliard
julliard at winehq.org
Mon May 23 15:51:52 CDT 2022
Module: wine
Branch: master
Commit: 8c8e1638c95f3f519359009e4a5b0e3df2cc894e
URL: https://source.winehq.org/git/wine.git/?a=commit;h=8c8e1638c95f3f519359009e4a5b0e3df2cc894e
Author: Rémi Bernon <rbernon at codeweavers.com>
Date: Wed May 4 10:53:44 2022 +0200
ntdll: Introduce new helper to update block type.
Signed-off-by: Rémi Bernon <rbernon at codeweavers.com>
---
dlls/ntdll/heap.c | 12 +++++++++---
1 file changed, 9 insertions(+), 3 deletions(-)
diff --git a/dlls/ntdll/heap.c b/dlls/ntdll/heap.c
index 0983dc9d2b4..7e21593cd56 100644
--- a/dlls/ntdll/heap.c
+++ b/dlls/ntdll/heap.c
@@ -231,6 +231,12 @@ static inline UINT block_get_type( const struct block *block )
return block->magic;
}
+static inline void block_set_type( struct block *block, UINT type )
+{
+ if (type >> 24) block->unused_bytes = type >> 24;
+ block->magic = type;
+}
+
static inline UINT block_get_overhead( const struct block *block )
{
if (block_get_flags( block ) & ARENA_FLAG_FREE) return sizeof(struct entry);
@@ -685,7 +691,7 @@ static void create_free_block( SUBHEAP *subheap, struct block *block, SIZE_T blo
BOOL last;
mark_block_uninitialized( block, sizeof(*entry) );
- entry->magic = ARENA_FREE_MAGIC;
+ block_set_type( block, ARENA_FREE_MAGIC );
/* If debugging, erase the freed block content */
@@ -737,7 +743,7 @@ static void HEAP_MakeInUseBlockFree( SUBHEAP *subheap, ARENA_INUSE *pArena )
ARENA_INUSE *prev = heap->pending_free[heap->pending_pos];
heap->pending_free[heap->pending_pos] = pArena;
heap->pending_pos = (heap->pending_pos + 1) % MAX_FREE_PENDING;
- pArena->magic = ARENA_PENDING_MAGIC;
+ block_set_type( pArena, ARENA_PENDING_MAGIC );
mark_block_free( pArena + 1, pArena->size & ARENA_SIZE_MASK, heap->flags );
if (!prev) return;
pArena = prev;
@@ -1536,7 +1542,7 @@ static NTSTATUS heap_allocate( HEAP *heap, ULONG flags, SIZE_T size, void **ret
/* in-use arena is smaller than free arena,
* so we have to add the difference to the size */
block->size = (block->size & ~ARENA_FLAG_FREE) + sizeof(struct entry) - sizeof(*block);
- block->magic = ARENA_INUSE_MAGIC;
+ block_set_type( block, ARENA_INUSE_MAGIC );
/* Shrink the block */
More information about the wine-cvs
mailing list