Commit a310c56b authored by marko's avatar marko

Merge r1815:1817 from branches/zip: Improve Valgrind instrumentation.

UNIV_MEM_ASSERT_RW(): New macro, to check that the contents of a memory
area is defined.

UNIV_MEM_ASSERT_W(): New macro, to check that a memory area is writable.

UNIV_MEM_ASSERT_AND_FREE(): New macro, to check that the memory is
writable before declaring it free (unwritable).  This replaces UNIV_MEM_FREE()
in many places.

mem_init_buf(): Check that the memory is writable, and declare it undefined.

mem_erase_buf(): Check that the memory is writable, and declare it freed.
parent 92b3d4a3
...@@ -881,7 +881,7 @@ buf_LRU_block_free_non_file_page( ...@@ -881,7 +881,7 @@ buf_LRU_block_free_non_file_page(
UT_LIST_ADD_FIRST(free, buf_pool->free, block); UT_LIST_ADD_FIRST(free, buf_pool->free, block);
block->in_free_list = TRUE; block->in_free_list = TRUE;
UNIV_MEM_FREE(block->frame, UNIV_PAGE_SIZE); UNIV_MEM_ASSERT_AND_FREE(block->frame, UNIV_PAGE_SIZE);
if (srv_use_awe && block->frame) { if (srv_use_awe && block->frame) {
/* Add to the list of mapped pages */ /* Add to the list of mapped pages */
......
...@@ -271,18 +271,14 @@ mem_heap_free_heap_top( ...@@ -271,18 +271,14 @@ mem_heap_free_heap_top(
ut_ad(mem_block_get_start(block) <= mem_block_get_free(block)); ut_ad(mem_block_get_start(block) <= mem_block_get_free(block));
/* In the debug version erase block from top up */ /* In the debug version erase block from top up */
{ mem_erase_buf(old_top, (byte*)block + block->len - old_top);
ulint len = (byte*)block + block->len - old_top;
mem_erase_buf(old_top, len);
UNIV_MEM_FREE(old_top, len);
}
/* Update allocated memory count */ /* Update allocated memory count */
mutex_enter(&mem_hash_mutex); mutex_enter(&mem_hash_mutex);
mem_current_allocated_memory -= (total_size - size); mem_current_allocated_memory -= (total_size - size);
mutex_exit(&mem_hash_mutex); mutex_exit(&mem_hash_mutex);
#else /* UNIV_MEM_DEBUG */ #else /* UNIV_MEM_DEBUG */
UNIV_MEM_FREE(old_top, (byte*)block + block->len - old_top); UNIV_MEM_ASSERT_AND_FREE(old_top, (byte*)block + block->len - old_top);
#endif /* UNIV_MEM_DEBUG */ #endif /* UNIV_MEM_DEBUG */
/* If free == start, we may free the block if it is not the first /* If free == start, we may free the block if it is not the first
...@@ -363,6 +359,7 @@ mem_heap_free_top( ...@@ -363,6 +359,7 @@ mem_heap_free_top(
/* Subtract the free field of block */ /* Subtract the free field of block */
mem_block_set_free(block, mem_block_get_free(block) mem_block_set_free(block, mem_block_get_free(block)
- MEM_SPACE_NEEDED(n)); - MEM_SPACE_NEEDED(n));
UNIV_MEM_ASSERT_W((byte*) block + mem_block_get_free(block), n);
#ifdef UNIV_MEM_DEBUG #ifdef UNIV_MEM_DEBUG
ut_ad(mem_block_get_start(block) <= mem_block_get_free(block)); ut_ad(mem_block_get_start(block) <= mem_block_get_free(block));
......
...@@ -308,11 +308,21 @@ typedef void* os_thread_ret_t; ...@@ -308,11 +308,21 @@ typedef void* os_thread_ret_t;
# define UNIV_MEM_INVALID(addr, size) VALGRIND_MAKE_MEM_UNDEFINED(addr, size) # define UNIV_MEM_INVALID(addr, size) VALGRIND_MAKE_MEM_UNDEFINED(addr, size)
# define UNIV_MEM_FREE(addr, size) VALGRIND_MAKE_MEM_NOACCESS(addr, size) # define UNIV_MEM_FREE(addr, size) VALGRIND_MAKE_MEM_NOACCESS(addr, size)
# define UNIV_MEM_ALLOC(addr, size) VALGRIND_MAKE_MEM_UNDEFINED(addr, size) # define UNIV_MEM_ALLOC(addr, size) VALGRIND_MAKE_MEM_UNDEFINED(addr, size)
# define UNIV_MEM_ASSERT_RW(addr, size) \
VALGRIND_CHECK_MEM_IS_DEFINED(addr, size)
# define UNIV_MEM_ASSERT_W(addr, size) \
VALGRIND_CHECK_MEM_IS_ADDRESSABLE(addr, size)
#else #else
# define UNIV_MEM_VALID(addr, size) do {} while(0) # define UNIV_MEM_VALID(addr, size) do {} while(0)
# define UNIV_MEM_INVALID(addr, size) do {} while(0) # define UNIV_MEM_INVALID(addr, size) do {} while(0)
# define UNIV_MEM_FREE(addr, size) do {} while(0) # define UNIV_MEM_FREE(addr, size) do {} while(0)
# define UNIV_MEM_ALLOC(addr, size) do {} while(0) # define UNIV_MEM_ALLOC(addr, size) do {} while(0)
# define UNIV_MEM_ASSERT_RW(addr, size) do {} while(0)
# define UNIV_MEM_ASSERT_W(addr, size) do {} while(0)
#endif #endif
#define UNIV_MEM_ASSERT_AND_FREE(addr, size) do { \
UNIV_MEM_ASSERT_RW(addr, size); \
UNIV_MEM_FREE(addr, size); \
} while (0)
#endif #endif
...@@ -223,6 +223,8 @@ mem_init_buf( ...@@ -223,6 +223,8 @@ mem_init_buf(
{ {
byte* ptr; byte* ptr;
UNIV_MEM_ASSERT_W(buf, n);
for (ptr = buf; ptr < buf + n; ptr++) { for (ptr = buf; ptr < buf + n; ptr++) {
if (ut_rnd_gen_ibool()) { if (ut_rnd_gen_ibool()) {
...@@ -231,6 +233,8 @@ mem_init_buf( ...@@ -231,6 +233,8 @@ mem_init_buf(
*ptr = 0xBE; *ptr = 0xBE;
} }
} }
UNIV_MEM_INVALID(buf, n);
} }
/******************************************************************* /*******************************************************************
...@@ -245,6 +249,8 @@ mem_erase_buf( ...@@ -245,6 +249,8 @@ mem_erase_buf(
{ {
byte* ptr; byte* ptr;
UNIV_MEM_ASSERT_W(buf, n);
for (ptr = buf; ptr < buf + n; ptr++) { for (ptr = buf; ptr < buf + n; ptr++) {
if (ut_rnd_gen_ibool()) { if (ut_rnd_gen_ibool()) {
*ptr = 0xDE; *ptr = 0xDE;
...@@ -252,6 +258,8 @@ mem_erase_buf( ...@@ -252,6 +258,8 @@ mem_erase_buf(
*ptr = 0xAD; *ptr = 0xAD;
} }
} }
UNIV_MEM_FREE(buf, n);
} }
/******************************************************************* /*******************************************************************
......
...@@ -512,9 +512,9 @@ mem_heap_block_free( ...@@ -512,9 +512,9 @@ mem_heap_block_free(
of hex 0xDE and 0xAD. */ of hex 0xDE and 0xAD. */
mem_erase_buf((byte*)block, len); mem_erase_buf((byte*)block, len);
#else /* UNIV_MEM_DEBUG */
#endif UNIV_MEM_ASSERT_AND_FREE(block, len);
UNIV_MEM_FREE(block, len); #endif /* UNIV_MEM_DEBUG */
if (init_block) { if (init_block) {
/* Do not have to free: do nothing */ /* Do not have to free: do nothing */
......
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