Skip to content

Commit

Permalink
MDEV-22911: Fix the valgrind & MSAN instrumentation of MDEV-8139
Browse files Browse the repository at this point in the history
MEM_GET_VBITS(): Save information about uninitialized data.

MEM_SET_VBITS(): Restore information about uninitialized data.
  • Loading branch information
Thirunarayanan committed Jun 16, 2020
1 parent 72fc4f3 commit d0c69cc
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 2 deletions.
8 changes: 8 additions & 0 deletions include/my_valgrind.h
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,8 @@
# define MEM_NOACCESS(a,len) VALGRIND_MAKE_MEM_NOACCESS(a,len)
# define MEM_CHECK_ADDRESSABLE(a,len) VALGRIND_CHECK_MEM_IS_ADDRESSABLE(a,len)
# define MEM_CHECK_DEFINED(a,len) VALGRIND_CHECK_MEM_IS_DEFINED(a,len)
# define MEM_GET_VBITS(a,b,len) VALGRIND_GET_VBITS(a,b,len)
# define MEM_SET_VBITS(a,b,len) VALGRIND_SET_VBITS(a,b,len)
# define REDZONE_SIZE 8
#elif defined(__SANITIZE_ADDRESS__)
# include <sanitizer/asan_interface.h>
Expand All @@ -48,6 +50,8 @@
# define MEM_NOACCESS(a,len) ASAN_POISON_MEMORY_REGION(a,len)
# define MEM_CHECK_ADDRESSABLE(a,len) ((void) 0)
# define MEM_CHECK_DEFINED(a,len) ((void) 0)
# define MEM_GET_VBITS(a,b,len) ((void) 0)
# define MEM_SET_VBITS(a,b,len) ((void) 0)
# define REDZONE_SIZE 8
#elif __has_feature(memory_sanitizer)
# include <sanitizer/msan_interface.h>
Expand All @@ -57,13 +61,17 @@
# define MEM_NOACCESS(a,len) ((void) 0)
# define MEM_CHECK_ADDRESSABLE(a,len) ((void) 0)
# define MEM_CHECK_DEFINED(a,len) __msan_check_mem_is_initialized(a,len)
# define MEM_GET_VBITS(a,b,len) __msan_copy_shadow(b,a,len)
# define MEM_SET_VBITS(a,b,len) __msan_copy_shadow(a,b,len)
# define REDZONE_SIZE 8
#else
# define MEM_UNDEFINED(a,len) ((void) (a), (void) (len))
# define MEM_MAKE_DEFINED(a,len) ((void) 0)
# define MEM_NOACCESS(a,len) ((void) 0)
# define MEM_CHECK_ADDRESSABLE(a,len) ((void) 0)
# define MEM_CHECK_DEFINED(a,len) ((void) 0)
# define MEM_GET_VBITS(a,b,len) ((void) 0)
# define MEM_SET_VBITS(a,b,len) ((void) 0)
# define REDZONE_SIZE 0
#endif /* HAVE_VALGRIND_MEMCHECK_H */

Expand Down
7 changes: 5 additions & 2 deletions storage/innobase/mtr/mtr0mtr.cc
Original file line number Diff line number Diff line change
Expand Up @@ -354,9 +354,12 @@ struct mtr_write_log_t {
/** Start a mini-transaction. */
void mtr_t::start()
{
MEM_CHECK_DEFINED(&m_freed_ranges, sizeof m_freed_ranges);
#ifdef HAVE_valgrind_or_MSAN
char m_freed_ranges_vbits[sizeof m_freed_ranges];
#endif
MEM_GET_VBITS(&m_freed_ranges, m_freed_ranges_vbits, sizeof m_freed_ranges);
UNIV_MEM_INVALID(this, sizeof *this);
UNIV_MEM_VALID(&m_freed_ranges, sizeof m_freed_ranges);
MEM_SET_VBITS(&m_freed_ranges, m_freed_ranges_vbits, sizeof m_freed_ranges);

ut_d(m_start= true);
ut_d(m_commit= false);
Expand Down

0 comments on commit d0c69cc

Please sign in to comment.