1
0
mirror of https://github.com/wine-mirror/wine synced 2024-07-08 03:45:57 +00:00

ntdll: Match Windows used block filling.

Test rewritten by Rémi Bernon.
This commit is contained in:
Paul Gofman 2023-07-21 19:24:45 -06:00 committed by Alexandre Julliard
parent 0c9e8e655b
commit c77642ec52
2 changed files with 33 additions and 2 deletions

View File

@ -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 );

View File

@ -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;
}
}