Skip to content

Commit 8e11f89

Browse files
committed
Add support for msan integration to checkmem.h
1 parent 8dc6407 commit 8e11f89

File tree

1 file changed

+14
-0
lines changed

1 file changed

+14
-0
lines changed

src/checkmem.h

+14
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,20 @@
3939
/* Define a statement-like macro that ignores the arguments. */
4040
#define SECP256K1_CHECKMEM_NOOP(p, len) do { (void)(p); (void)(len); } while(0)
4141

42+
/* If compiling under msan, map the SECP256K1_CHECKMEM_* functionality to msan.
43+
* Choose this preferentially, even when VALGRIND is defined, as msan-compiled
44+
* binaries can't be run under valgrind anyway. */
45+
#if defined(__has_feature)
46+
# if __has_feature(memory_sanitizer)
47+
# include <sanitizer/msan_interface.h>
48+
# define SECP256K1_CHECKMEM_ENABLED 1
49+
# define SECP256K1_CHECKMEM_UNDEFINE(p, len) __msan_allocated_memory((p), (len))
50+
# define SECP256K1_CHECKMEM_DEFINE(p, len) __msan_unpoison((p), (len))
51+
# define SECP256K1_CHECKMEM_CHECK(p, len) __msan_check_mem_is_initialized((p), (len))
52+
# define SECP256K1_CHECKMEM_RUNNING() (1)
53+
# endif
54+
#endif
55+
4256
/* If valgrind integration is desired (through the VALGRIND define), implement the
4357
* SECP256K1_CHECKMEM_* macros using valgrind. */
4458
#if !defined SECP256K1_CHECKMEM_ENABLED

0 commit comments

Comments
 (0)