[PATCH 3/5] ntdll: Use a block member in the free list entry struct.

Rémi Bernon wine at gitlab.winehq.org
Fri May 27 02:20:48 CDT 2022


From: Rémi Bernon <rbernon at codeweavers.com>

And use ARENA_FLAG_FREE|ARENA_FLAG_PREV_FREE flag combination to mark
and ignore free list links.

Signed-off-by: Rémi Bernon <rbernon at codeweavers.com>
---
 dlls/ntdll/heap.c | 11 +++++------
 1 file changed, 5 insertions(+), 6 deletions(-)

diff --git a/dlls/ntdll/heap.c b/dlls/ntdll/heap.c
index 0f75ef1fe81..411bb26aa3d 100644
--- a/dlls/ntdll/heap.c
+++ b/dlls/ntdll/heap.c
@@ -94,9 +94,8 @@ C_ASSERT( sizeof(struct block) == 8 );
 
 typedef struct entry
 {
-    DWORD                 size;     /* Block size; must be the first field */
-    DWORD                 magic;    /* Magic number */
-    struct list           entry;    /* Entry in free list */
+    struct block block;
+    struct list entry;
 } ARENA_FREE;
 
 typedef struct
@@ -972,8 +971,8 @@ static SUBHEAP *HEAP_CreateSubHeap( HEAP *heap, LPVOID address, DWORD flags,
         list_init( &heap->freeList[0].arena.entry );
         for (i = 0, pEntry = heap->freeList; i < HEAP_NB_FREE_LISTS; i++, pEntry++)
         {
-            pEntry->arena.size = BLOCK_FLAG_FREE_LINK;
-            pEntry->arena.magic = ARENA_FREE_MAGIC;
+            block_set_size( &pEntry->arena.block, BLOCK_FLAG_FREE_LINK, 0 );
+            block_set_type( &pEntry->arena.block, ARENA_FREE_MAGIC );
             if (i) list_add_after( &pEntry[-1].arena.entry, &pEntry->arena.entry );
         }
 
@@ -1080,7 +1079,7 @@ static BOOL is_valid_free_block( const HEAP *heap, const struct block *block )
 
     if ((subheap = find_subheap( heap, block, FALSE ))) return TRUE;
     if (block_get_flags( block ) != BLOCK_FLAG_FREE_LINK) return FALSE;
-    for (i = 0; i < HEAP_NB_FREE_LISTS; i++) if (block == (struct block *)&heap->freeList[i].arena) return TRUE;
+    for (i = 0; i < HEAP_NB_FREE_LISTS; i++) if (block == &heap->freeList[i].arena.block) return TRUE;
     return FALSE;
 }
 
-- 
GitLab


https://gitlab.winehq.org/wine/wine/-/merge_requests/137



More information about the wine-devel mailing list