[Bf-blender-cvs] [b5d87f80280] master: BLI_memarena: use ASAN memory poison
Campbell Barton
noreply at git.blender.org
Sat Mar 2 01:51:13 CET 2019
Commit: b5d87f802806df6f19d53213d31acbc6f26864b6
Author: Campbell Barton
Date: Sat Mar 2 11:41:55 2019 +1100
Branches: master
https://developer.blender.org/rBb5d87f802806df6f19d53213d31acbc6f26864b6
BLI_memarena: use ASAN memory poison
Detects invalid memory use when WITH_COMPILER_ASAN is enabled.
===================================================================
M source/blender/blenlib/intern/BLI_memarena.c
===================================================================
diff --git a/source/blender/blenlib/intern/BLI_memarena.c b/source/blender/blenlib/intern/BLI_memarena.c
index 4461e999b0b..2521320da97 100644
--- a/source/blender/blenlib/intern/BLI_memarena.c
+++ b/source/blender/blenlib/intern/BLI_memarena.c
@@ -47,6 +47,17 @@
# define VALGRIND_MEMPOOL_ALLOC(pool, addr, size) UNUSED_VARS(pool, addr, size)
#endif
+/* Clang defines this. */
+#ifndef __has_feature
+# define __has_feature(x) 0
+#endif
+#if defined(__SANITIZE_ADDRESS__) || __has_feature(address_sanitizer)
+# include "sanitizer/asan_interface.h"
+#else
+# define ASAN_POISON_MEMORY_REGION(addr, size) ((void)(addr), (void)(size))
+# define ASAN_UNPOISON_MEMORY_REGION(addr, size) ((void)(addr), (void)(size))
+#endif
+
struct MemBuf {
struct MemBuf *next;
uchar data[0];
@@ -143,6 +154,8 @@ void *BLI_memarena_alloc(MemArena *ma, size_t size)
mb->next = ma->bufs;
ma->bufs = mb;
+ ASAN_POISON_MEMORY_REGION(ma->curbuf, ma->cursize);
+
memarena_curbuf_align(ma);
}
@@ -152,6 +165,8 @@ void *BLI_memarena_alloc(MemArena *ma, size_t size)
VALGRIND_MEMPOOL_ALLOC(ma, ptr, size);
+ ASAN_UNPOISON_MEMORY_REGION(ptr, size);
+
return ptr;
}
@@ -194,6 +209,7 @@ void BLI_memarena_clear(MemArena *ma)
if (ma->use_calloc) {
memset(ma->curbuf, 0, curbuf_used);
}
+ ASAN_POISON_MEMORY_REGION(ma->curbuf, ma->cursize);
}
VALGRIND_DESTROY_MEMPOOL(ma);
More information about the Bf-blender-cvs
mailing list