diff options
author | Campbell Barton <ideasman42@gmail.com> | 2019-03-02 03:41:55 +0300 |
---|---|---|
committer | Campbell Barton <ideasman42@gmail.com> | 2019-03-02 03:50:44 +0300 |
commit | b5d87f802806df6f19d53213d31acbc6f26864b6 (patch) | |
tree | 9e79b720d0ff8629eb2b18341f1c8eb39440d826 /source/blender | |
parent | 4d9bf4fc6ce29f95abff6020e51ae3b78a79df89 (diff) |
BLI_memarena: use ASAN memory poison
Detects invalid memory use when WITH_COMPILER_ASAN is enabled.
Diffstat (limited to 'source/blender')
-rw-r--r-- | source/blender/blenlib/intern/BLI_memarena.c | 16 |
1 files changed, 16 insertions, 0 deletions
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); |