From 8e11f89a685063221fa4c2df0ee750d997aee386 Mon Sep 17 00:00:00 2001 From: Pieter Wuille Date: Tue, 6 Dec 2022 18:38:32 -0500 Subject: [PATCH] Add support for msan integration to checkmem.h --- src/checkmem.h | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/src/checkmem.h b/src/checkmem.h index 55d96c3d5..571e4cc38 100644 --- a/src/checkmem.h +++ b/src/checkmem.h @@ -39,6 +39,20 @@ /* Define a statement-like macro that ignores the arguments. */ #define SECP256K1_CHECKMEM_NOOP(p, len) do { (void)(p); (void)(len); } while(0) +/* If compiling under msan, map the SECP256K1_CHECKMEM_* functionality to msan. + * Choose this preferentially, even when VALGRIND is defined, as msan-compiled + * binaries can't be run under valgrind anyway. */ +#if defined(__has_feature) +# if __has_feature(memory_sanitizer) +# include +# define SECP256K1_CHECKMEM_ENABLED 1 +# define SECP256K1_CHECKMEM_UNDEFINE(p, len) __msan_allocated_memory((p), (len)) +# define SECP256K1_CHECKMEM_DEFINE(p, len) __msan_unpoison((p), (len)) +# define SECP256K1_CHECKMEM_CHECK(p, len) __msan_check_mem_is_initialized((p), (len)) +# define SECP256K1_CHECKMEM_RUNNING() (1) +# endif +#endif + /* If valgrind integration is desired (through the VALGRIND define), implement the * SECP256K1_CHECKMEM_* macros using valgrind. */ #if !defined SECP256K1_CHECKMEM_ENABLED