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

ntdll: Use a fixed block tail size.

parent 36d32eb8
...@@ -349,14 +349,15 @@ static inline void mark_block_free( void *ptr, SIZE_T size, DWORD flags ) ...@@ -349,14 +349,15 @@ static inline void mark_block_free( void *ptr, SIZE_T size, DWORD flags )
} }
/* mark a block of memory as a tail block */ /* mark a block of memory as a tail block */
static inline void mark_block_tail( void *ptr, SIZE_T size, DWORD flags ) static inline void mark_block_tail( struct block *block, DWORD flags )
{ {
char *tail = (char *)block + block_get_size( block ) - block->unused_bytes;
if (flags & HEAP_TAIL_CHECKING_ENABLED) if (flags & HEAP_TAIL_CHECKING_ENABLED)
{ {
valgrind_make_writable( ptr, size ); valgrind_make_writable( tail, ALIGNMENT );
memset( ptr, ARENA_TAIL_FILLER, size ); memset( tail, ARENA_TAIL_FILLER, ALIGNMENT );
} }
valgrind_make_noaccess( ptr, size ); valgrind_make_noaccess( tail, ALIGNMENT );
} }
/* initialize contents of a newly created block of memory */ /* initialize contents of a newly created block of memory */
...@@ -1161,7 +1162,7 @@ static BOOL validate_used_block( const SUBHEAP *subheap, const struct block *blo ...@@ -1161,7 +1162,7 @@ static BOOL validate_used_block( const SUBHEAP *subheap, const struct block *blo
else if (!err && (flags & HEAP_TAIL_CHECKING_ENABLED)) else if (!err && (flags & HEAP_TAIL_CHECKING_ENABLED))
{ {
const unsigned char *tail = (unsigned char *)block + block_get_size( block ) - block->unused_bytes; const unsigned char *tail = (unsigned char *)block + block_get_size( block ) - block->unused_bytes;
for (i = 0; !err && i < block->unused_bytes; i++) if (tail[i] != ARENA_TAIL_FILLER) err = "invalid block tail"; for (i = 0; !err && i < ALIGNMENT; i++) if (tail[i] != ARENA_TAIL_FILLER) err = "invalid block tail";
} }
if (err) if (err)
...@@ -1328,7 +1329,7 @@ static void heap_set_debug_flags( HANDLE handle ) ...@@ -1328,7 +1329,7 @@ static void heap_set_debug_flags( HANDLE handle )
else else
{ {
if (block_get_type( block ) == ARENA_PENDING_MAGIC) mark_block_free( block + 1, block_get_size( block ) - sizeof(*block), flags ); if (block_get_type( block ) == ARENA_PENDING_MAGIC) mark_block_free( block + 1, block_get_size( block ) - sizeof(*block), flags );
else mark_block_tail( (char *)block + block_get_size( block ) - block->unused_bytes, block->unused_bytes, flags ); else mark_block_tail( block, flags );
} }
} }
} }
...@@ -1493,7 +1494,7 @@ static NTSTATUS heap_allocate( HEAP *heap, ULONG flags, SIZE_T size, void **ret ...@@ -1493,7 +1494,7 @@ static NTSTATUS heap_allocate( HEAP *heap, ULONG flags, SIZE_T size, void **ret
block_set_type( block, ARENA_INUSE_MAGIC ); block_set_type( block, ARENA_INUSE_MAGIC );
shrink_used_block( subheap, block, 0, old_block_size, block_size, size ); shrink_used_block( subheap, block, 0, old_block_size, block_size, size );
initialize_block( block + 1, size, flags ); initialize_block( block + 1, size, flags );
mark_block_tail( (char *)(block + 1) + size, block->unused_bytes, flags ); mark_block_tail( block, flags );
*ret = block + 1; *ret = block + 1;
return STATUS_SUCCESS; return STATUS_SUCCESS;
...@@ -1614,7 +1615,7 @@ static NTSTATUS heap_reallocate( HEAP *heap, ULONG flags, void *ptr, SIZE_T size ...@@ -1614,7 +1615,7 @@ static NTSTATUS heap_reallocate( HEAP *heap, ULONG flags, void *ptr, SIZE_T size
shrink_used_block( subheap, block, block_get_flags( block ), old_block_size, block_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 ); if (size > old_size) initialize_block( (char *)(block + 1) + old_size, size - old_size, flags );
mark_block_tail( (char *)(block + 1) + size, block->unused_bytes, flags ); mark_block_tail( block, flags );
/* Return the new arena */ /* Return the new arena */
......
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