I noticed these while trying to debug heap corruption. Rémi, if you have queued heap patches, please feel free to defer these until those are done.
From: Zebediah Figura zfigura@codeweavers.com
--- dlls/ntdll/heap.c | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-)
diff --git a/dlls/ntdll/heap.c b/dlls/ntdll/heap.c index 11c07d2e332..a6db3444374 100644 --- a/dlls/ntdll/heap.c +++ b/dlls/ntdll/heap.c @@ -488,26 +488,28 @@ static void heap_set_status( const struct heap *heap, ULONG flags, NTSTATUS stat if (status) RtlSetLastWin32ErrorAndNtStatusFromNtStatus( status ); }
+static size_t get_free_list_block_size( unsigned int index ) +{ + if (index < HEAP_NB_SMALL_FREE_LISTS) + return index * ALIGNMENT + HEAP_MIN_BLOCK_SIZE; + return free_list_sizes[index - HEAP_NB_SMALL_FREE_LISTS]; +} + static void heap_dump( const struct heap *heap ) { const struct block *block; const ARENA_LARGE *large; const SUBHEAP *subheap; unsigned int i; - SIZE_T size;
TRACE( "heap: %p\n", heap ); TRACE( " next %p\n", LIST_ENTRY( heap->entry.next, struct heap, entry ) );
TRACE( " free_lists: %p\n", heap->free_lists ); for (i = 0; i < HEAP_NB_FREE_LISTS; i++) - { - if (i < HEAP_NB_SMALL_FREE_LISTS) size = HEAP_MIN_BLOCK_SIZE + i * ALIGNMENT; - else size = free_list_sizes[i - HEAP_NB_SMALL_FREE_LISTS]; - TRACE( " %p: size %8Ix, prev %p, next %p\n", heap->free_lists + i, size, + TRACE( " %p: size %8Ix, prev %p, next %p\n", heap->free_lists + i, get_free_list_block_size( i ), LIST_ENTRY( heap->free_lists[i].entry.prev, struct entry, entry ), LIST_ENTRY( heap->free_lists[i].entry.next, struct entry, entry ) ); - }
TRACE( " subheaps: %p\n", &heap->subheap_list ); LIST_FOR_EACH_ENTRY( subheap, &heap->subheap_list, SUBHEAP, entry )
From: Zebediah Figura zfigura@codeweavers.com
--- dlls/ntdll/heap.c | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-)
diff --git a/dlls/ntdll/heap.c b/dlls/ntdll/heap.c index a6db3444374..014851c0dae 100644 --- a/dlls/ntdll/heap.c +++ b/dlls/ntdll/heap.c @@ -507,7 +507,7 @@ static void heap_dump( const struct heap *heap )
TRACE( " free_lists: %p\n", heap->free_lists ); for (i = 0; i < HEAP_NB_FREE_LISTS; i++) - TRACE( " %p: size %8Ix, prev %p, next %p\n", heap->free_lists + i, get_free_list_block_size( i ), + TRACE( " %p: size %#8Ix, prev %p, next %p\n", heap->free_lists + i, get_free_list_block_size( i ), LIST_ENTRY( heap->free_lists[i].entry.prev, struct entry, entry ), LIST_ENTRY( heap->free_lists[i].entry.next, struct entry, entry ) );
@@ -801,7 +801,7 @@ static struct block *allocate_large_block( struct heap *heap, DWORD flags, SIZE_ if (NtAllocateVirtualMemory( NtCurrentProcess(), &address, 0, &total_size, MEM_COMMIT, get_protection_type( flags ))) { - WARN("Could not allocate block for %08Ix bytes\n", size ); + WARN( "Could not allocate block for %#Ix bytes\n", size ); return NULL; }
@@ -860,7 +860,7 @@ static struct block *realloc_large_block( struct heap *heap, DWORD flags, struct if (flags & HEAP_REALLOC_IN_PLACE_ONLY) return NULL; if (!(block = allocate_large_block( heap, flags, size ))) { - WARN("Could not allocate block for %08Ix bytes\n", size ); + WARN( "Could not allocate block for %#Ix bytes\n", size ); return NULL; }
@@ -934,13 +934,13 @@ static SUBHEAP *HEAP_CreateSubHeap( struct heap **heap_ptr, LPVOID address, DWOR if (NtAllocateVirtualMemory( NtCurrentProcess(), &address, 0, &totalSize, MEM_RESERVE, get_protection_type( flags ) )) { - WARN("Could not allocate %08Ix bytes\n", totalSize ); + WARN( "Could not allocate %#Ix bytes\n", totalSize ); return NULL; } if (NtAllocateVirtualMemory( NtCurrentProcess(), &address, 0, &commitSize, MEM_COMMIT, get_protection_type( flags ) )) { - WARN("Could not commit %08Ix bytes for sub-heap %p\n", commitSize, address ); + WARN( "Could not commit %#Ix bytes for sub-heap %p\n", commitSize, address ); return NULL; } } @@ -1037,7 +1037,7 @@ static struct block *find_free_block( struct heap *heap, SIZE_T block_size, SUBH
if (!(heap->flags & HEAP_GROWABLE)) { - WARN("Not enough space in heap %p for %08Ix bytes\n", heap, block_size ); + WARN( "Not enough space in heap %p for %#Ix bytes\n", heap, block_size ); return NULL; }
@@ -1058,7 +1058,7 @@ static struct block *find_free_block( struct heap *heap, SIZE_T block_size, SUBH max( heap->grow_size, total_size ) ); }
- TRACE( "created new sub-heap %p of %08Ix bytes for heap %p\n", *subheap, subheap_size( *subheap ), heap ); + TRACE( "created new sub-heap %p of %#Ix bytes for heap %p\n", *subheap, subheap_size( *subheap ), heap );
entry = first_block( *subheap ); list_remove( &entry->entry );
From: Zebediah Figura zfigura@codeweavers.com
--- dlls/ntdll/heap.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-)
diff --git a/dlls/ntdll/heap.c b/dlls/ntdll/heap.c index 014851c0dae..fd761215c5a 100644 --- a/dlls/ntdll/heap.c +++ b/dlls/ntdll/heap.c @@ -1022,7 +1022,7 @@ static struct block *find_free_block( struct heap *heap, SIZE_T block_size, SUBH while ((ptr = list_next( &heap->free_lists[0].entry, ptr ))) { entry = LIST_ENTRY( ptr, struct entry, entry ); - block = (struct block *)entry; + block = &entry->block; if (block_get_flags( block ) == BLOCK_FLAG_FREE_LINK) continue; if (block_get_size( block ) >= block_size) { @@ -1062,7 +1062,7 @@ static struct block *find_free_block( struct heap *heap, SIZE_T block_size, SUBH
entry = first_block( *subheap ); list_remove( &entry->entry ); - return (struct block *)entry; + return &entry->block; }
@@ -1091,11 +1091,11 @@ static BOOL validate_free_block( const struct heap *heap, const SUBHEAP *subheap err = "invalid block flags"; else if (!contains( base, subheap_size( subheap ), block, block_get_size( block ) )) err = "invalid block size"; - else if (!is_valid_free_block( heap, (next = (struct block *)LIST_ENTRY( entry->entry.next, struct entry, entry )) )) + else if (!is_valid_free_block( heap, (next = &LIST_ENTRY( entry->entry.next, struct entry, entry )->block) )) err = "invalid next free block pointer"; else if (!(block_get_flags( next ) & BLOCK_FLAG_FREE) || block_get_type( next ) != BLOCK_TYPE_FREE) err = "invalid next free block header"; - else if (!is_valid_free_block( heap, (prev = (struct block *)LIST_ENTRY( entry->entry.prev, struct entry, entry )) )) + else if (!is_valid_free_block( heap, (prev = &LIST_ENTRY( entry->entry.prev, struct entry, entry )->block) )) err = "invalid previous free block pointer"; else if (!(block_get_flags( prev ) & BLOCK_FLAG_FREE) || block_get_type( prev ) != BLOCK_TYPE_FREE) err = "invalid previous free block header";
From: Zebediah Figura zfigura@codeweavers.com
--- dlls/ntdll/heap.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/dlls/ntdll/heap.c b/dlls/ntdll/heap.c index fd761215c5a..048fc0e5264 100644 --- a/dlls/ntdll/heap.c +++ b/dlls/ntdll/heap.c @@ -1099,7 +1099,7 @@ static BOOL validate_free_block( const struct heap *heap, const SUBHEAP *subheap err = "invalid previous free block pointer"; else if (!(block_get_flags( prev ) & BLOCK_FLAG_FREE) || block_get_type( prev ) != BLOCK_TYPE_FREE) err = "invalid previous free block header"; - else if ((next = next_block( subheap, (struct block *)block ))) + else if ((next = next_block( subheap, block ))) { if (!(block_get_flags( next ) & BLOCK_FLAG_PREV_FREE)) err = "invalid next block flags";
This merge request was approved by Rémi Bernon.