summaryrefslogtreecommitdiff
path: root/include/my_valgrind.h
diff options
context:
space:
mode:
authorSergei Golubchik <serg@mariadb.org>2018-02-06 14:50:50 +0100
committerSergei Golubchik <serg@mariadb.org>2018-02-06 14:50:50 +0100
commit4771ae4b22d2bdef0aafc563570c71d4636a2493 (patch)
treed115bd7c68b1e6feab68ff6fcd547e0c86c79296 /include/my_valgrind.h
parent60f51af755ea9d07c20a596ba21de184816fa265 (diff)
parent0c25e58db6b045df92c209d396031cac5b528bbf (diff)
downloadmariadb-git-4771ae4b22d2bdef0aafc563570c71d4636a2493.tar.gz
Merge branch 'github/10.1' into 10.2
Diffstat (limited to 'include/my_valgrind.h')
-rw-r--r--include/my_valgrind.h27
1 files changed, 19 insertions, 8 deletions
diff --git a/include/my_valgrind.h b/include/my_valgrind.h
index dbbc4fad5ab..870fb453179 100644
--- a/include/my_valgrind.h
+++ b/include/my_valgrind.h
@@ -13,6 +13,14 @@
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02111-1301 USA */
+/* clang -> gcc */
+#ifndef __has_feature
+# define __has_feature(x) 0
+#endif
+#if __has_feature(address_sanitizer)
+# define __SANITIZE_ADDRESS__ 1
+#endif
+
#ifdef HAVE_valgrind
#define IF_VALGRIND(A,B) A
#else
@@ -25,7 +33,13 @@
# 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)
-#else /* HAVE_VALGRIND_MEMCHECK_H */
+#elif defined(__SANITIZE_ADDRESS__)
+# include <sanitizer/asan_interface.h>
+# define MEM_UNDEFINED(a,len) ASAN_UNPOISON_MEMORY_REGION(a,len)
+# 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)
+#else
# define MEM_UNDEFINED(a,len) ((void) 0)
# define MEM_NOACCESS(a,len) ((void) 0)
# define MEM_CHECK_ADDRESSABLE(a,len) ((void) 0)
@@ -33,13 +47,10 @@
#endif /* HAVE_VALGRIND_MEMCHECK_H */
#ifndef DBUG_OFF
-#define TRASH_FILL(A,B,C) do { const size_t trash_tmp= (B); memset(A, C, trash_tmp); MEM_UNDEFINED(A, trash_tmp); } while (0)
+#define TRASH_FILL(A,B,C) do { const size_t trash_tmp= (B); MEM_UNDEFINED(A, trash_tmp); memset(A, C, trash_tmp); } while (0)
#else
-#define TRASH_FILL(A,B,C) do{ const size_t trash_tmp __attribute__((unused)) = (B) ; MEM_CHECK_ADDRESSABLE(A,trash_tmp);MEM_UNDEFINED(A,trash_tmp);} while (0)
+#define TRASH_FILL(A,B,C) do { const size_t trash_tmp __attribute__((unused))= (B); MEM_UNDEFINED(A,trash_tmp); } while (0)
#endif
-#define TRASH_ALLOC(A,B) TRASH_FILL(A,B,0xA5)
-#define TRASH_FREE(A,B) TRASH_FILL(A,(size_t) (B),0x8F)
-#define TRASH(A,B) TRASH_FREE(A,B)
-# define DBUG_ASSERT_DEFINED(x) \
- DBUG_ASSERT(!VALGRIND_CHECK_MEM_IS_DEFINED(&(x), sizeof(x)))
+#define TRASH_ALLOC(A,B) do { TRASH_FILL(A,B,0xA5); MEM_UNDEFINED(A,B); } while(0)
+#define TRASH_FREE(A,B) do { TRASH_FILL(A,B,0x8F); MEM_NOACCESS(A,B); } while(0)