Commit c77642ec authored by Paul Gofman's avatar Paul Gofman Committed by Alexandre Julliard

ntdll: Match Windows used block filling.

Test rewritten by Rémi Bernon.
parent 0c9e8e65
......@@ -3270,6 +3270,35 @@ static void test_heap_checks( DWORD flags )
ret = HeapFree( GetProcessHeap(), 0, p );
ok( ret, "HeapFree failed\n" );
if (flags & HEAP_FREE_CHECKING_ENABLED)
{
UINT *p32, tmp = 0;
size = 4 + 3;
p = pHeapAlloc( GetProcessHeap(), 0, size );
ok( !!p, "HeapAlloc failed\n" );
p32 = (UINT *)p;
ok( p32[0] == 0xbaadf00d, "got %#x\n", p32[0] );
memcpy( &tmp, p + size - 3, 3 );
ok( tmp != 0xadf00d, "got %#x\n", tmp );
memset( p, 0xcc, size );
size += 2 * 4;
p = pHeapReAlloc( GetProcessHeap(), 0, p, size );
ok( !!p, "HeapReAlloc failed\n" );
p32 = (UINT *)p;
ok( p32[0] == 0xcccccccc, "got %#x\n", p32[0] );
ok( p32[1] << 8 == 0xcccccc00, "got %#x\n", p32[1] );
ok( p32[2] == 0xbaadf00d, "got %#x\n", p32[2] );
memcpy( &tmp, p + size - 3, 3 );
ok( tmp != 0xadf00d, "got %#x\n", tmp );
ret = pHeapFree( GetProcessHeap(), 0, p );
ok( ret, "failed.\n" );
}
p = HeapAlloc( GetProcessHeap(), 0, 37 );
ok( p != NULL, "HeapAlloc failed\n" );
memset( p, 0xcc, 37 );
......
......@@ -139,7 +139,7 @@ C_ASSERT( sizeof(ARENA_LARGE) == 4 * BLOCK_ALIGN );
#define BLOCK_TYPE_FREE 'F'
#define BLOCK_TYPE_LARGE 'L'
#define BLOCK_FILL_USED 0x55
#define BLOCK_FILL_USED 0xbaadf00d
#define BLOCK_FILL_TAIL 0xab
#define BLOCK_FILL_FREE 0xfeeefeee
......@@ -513,6 +513,7 @@ static inline void mark_block_tail( struct block *block, DWORD flags )
static inline void initialize_block( struct block *block, SIZE_T old_size, SIZE_T size, DWORD flags )
{
char *data = (char *)(block + 1);
SIZE_T i;
if (size <= old_size) return;
......@@ -524,7 +525,8 @@ static inline void initialize_block( struct block *block, SIZE_T old_size, SIZE_
else if (flags & HEAP_FREE_CHECKING_ENABLED)
{
valgrind_make_writable( data + old_size, size - old_size );
memset( data + old_size, BLOCK_FILL_USED, size - old_size );
i = ROUND_SIZE( old_size, sizeof(DWORD) - 1 ) / sizeof(DWORD);
for (; i < size / sizeof(DWORD); ++i) ((DWORD *)data)[i] = BLOCK_FILL_USED;
}
}
......
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