Commit 372a2524 authored by marko's avatar marko

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(): Declare the memory undefined.

mem_erase_buf(): Declare the memory freed.
parent 94e707cf
...@@ -77,7 +77,7 @@ buf_buddy_add_to_free( ...@@ -77,7 +77,7 @@ buf_buddy_add_to_free(
#ifdef UNIV_DEBUG_VALGRIND #ifdef UNIV_DEBUG_VALGRIND
if (b) UNIV_MEM_FREE(b, BUF_BUDDY_LOW << i); if (b) UNIV_MEM_FREE(b, BUF_BUDDY_LOW << i);
UNIV_MEM_FREE(bpage, BUF_BUDDY_LOW << i); UNIV_MEM_ASSERT_AND_FREE(bpage, BUF_BUDDY_LOW << i);
#endif /* UNIV_DEBUG_VALGRIND */ #endif /* UNIV_DEBUG_VALGRIND */
} }
...@@ -682,7 +682,7 @@ buddy_free2: ...@@ -682,7 +682,7 @@ buddy_free2:
{ {
buf_page_t* next = UT_LIST_GET_NEXT(list, bpage); buf_page_t* next = UT_LIST_GET_NEXT(list, bpage);
UNIV_MEM_FREE(bpage, BUF_BUDDY_LOW << i); UNIV_MEM_ASSERT_AND_FREE(bpage, BUF_BUDDY_LOW << i);
bpage = next; bpage = next;
} }
} }
......
...@@ -1154,7 +1154,7 @@ buf_LRU_block_free_non_file_page( ...@@ -1154,7 +1154,7 @@ buf_LRU_block_free_non_file_page(
UT_LIST_ADD_FIRST(list, buf_pool->free, (&block->page)); UT_LIST_ADD_FIRST(list, buf_pool->free, (&block->page));
ut_d(block->page.in_free_list = TRUE); ut_d(block->page.in_free_list = TRUE);
UNIV_MEM_FREE(block->frame, UNIV_PAGE_SIZE); UNIV_MEM_ASSERT_AND_FREE(block->frame, UNIV_PAGE_SIZE);
} }
/********************************************************************** /**********************************************************************
......
...@@ -285,18 +285,14 @@ mem_heap_free_heap_top( ...@@ -285,18 +285,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
...@@ -377,6 +373,7 @@ mem_heap_free_top( ...@@ -377,6 +373,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));
......
...@@ -86,6 +86,7 @@ memory is read outside the allocated blocks. */ ...@@ -86,6 +86,7 @@ memory is read outside the allocated blocks. */
#if 0 #if 0
#define UNIV_DEBUG_VALGRIND /* Enable extra #define UNIV_DEBUG_VALGRIND /* Enable extra
Valgrind instrumentation */ Valgrind instrumentation */
#define UNIV_MEM_DEBUG /* detect memory leaks etc */
#define UNIV_DEBUG_PRINT /* Enable the compilation of #define UNIV_DEBUG_PRINT /* Enable the compilation of
some debug print functions */ some debug print functions */
#define UNIV_BUF_DEBUG /* Enable buffer pool #define UNIV_BUF_DEBUG /* Enable buffer pool
...@@ -328,6 +329,10 @@ typedef void* os_thread_ret_t; ...@@ -328,6 +329,10 @@ typedef void* os_thread_ret_t;
# 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_DESC(addr, size, b) VALGRIND_CREATE_BLOCK(addr, size, b) # define UNIV_MEM_DESC(addr, size, b) VALGRIND_CREATE_BLOCK(addr, size, b)
# define UNIV_MEM_UNDESC(b) VALGRIND_DISCARD(b) # define UNIV_MEM_UNDESC(b) VALGRIND_DISCARD(b)
# 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)
...@@ -335,6 +340,12 @@ typedef void* os_thread_ret_t; ...@@ -335,6 +340,12 @@ typedef void* os_thread_ret_t;
# define UNIV_MEM_ALLOC(addr, size) do {} while(0) # define UNIV_MEM_ALLOC(addr, size) do {} while(0)
# define UNIV_MEM_DESC(addr, size, b) do {} while(0) # define UNIV_MEM_DESC(addr, size, b) do {} while(0)
# define UNIV_MEM_UNDESC(b) do {} while(0) # define UNIV_MEM_UNDESC(b) 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
...@@ -231,6 +231,8 @@ mem_init_buf( ...@@ -231,6 +231,8 @@ mem_init_buf(
*ptr = 0xBE; *ptr = 0xBE;
} }
} }
UNIV_MEM_INVALID(buf, n);
} }
/******************************************************************* /*******************************************************************
...@@ -252,6 +254,8 @@ mem_erase_buf( ...@@ -252,6 +254,8 @@ mem_erase_buf(
*ptr = 0xAD; *ptr = 0xAD;
} }
} }
UNIV_MEM_FREE(buf, n);
} }
/******************************************************************* /*******************************************************************
......
...@@ -488,8 +488,9 @@ mem_heap_block_free( ...@@ -488,8 +488,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);
#endif #else /* UNIV_MEM_DEBUG */
UNIV_MEM_FREE(block, len); UNIV_MEM_ASSERT_AND_FREE(block, len);
#endif /* UNIV_MEM_DEBUG */
if (type == MEM_HEAP_DYNAMIC) { if (type == MEM_HEAP_DYNAMIC) {
......
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