diff options
author | 卜部昌平 <shyouhei@ruby-lang.org> | 2019-12-03 17:20:07 +0900 |
---|---|---|
committer | 卜部昌平 <shyouhei@ruby-lang.org> | 2019-12-26 20:45:12 +0900 |
commit | adc49f0f9a1106fc5a81b5aba684ec1578ac7d6d (patch) | |
tree | c4392e850fe354a3a7d4f5c6c13f9b8fbcfe68a3 /internal/sanitizers.h | |
parent | ec6f6b53d88b47570c3c2b83cefee2cfd7b72ce3 (diff) |
internal/sanitizers.h rework
Rearrange macro orders for better readability.
Notes
Notes:
Merged: https://github.com/ruby/ruby/pull/2711
Diffstat (limited to 'internal/sanitizers.h')
-rw-r--r-- | internal/sanitizers.h | 76 |
1 files changed, 44 insertions, 32 deletions
diff --git a/internal/sanitizers.h b/internal/sanitizers.h index 4c6ad28e71..680b553bae 100644 --- a/internal/sanitizers.h +++ b/internal/sanitizers.h @@ -9,15 +9,33 @@ * modify this file, provided that the conditions mentioned in the * file COPYING are met. Consult the file for details. */ +#include "ruby/config.h" +#include "internal/compilers.h" /* for __has_feature */ +#ifdef HAVE_VALGRIND_MEMCHECK_H +# include <valgrind/memcheck.h> +#endif + +#ifdef HAVE_SANITIZER_ASAN_INTERFACE_H +# include <sanitizer/asan_interface.h> +#endif + +#ifdef HAVE_SANITIZER_MSAN_INTERFACE_H +# if __has_feature(memory_sanitizer) +# include <sanitizer/msan_interface.h> +# endif +#endif + +#include "internal/stdbool.h" /* for bool */ +#include "ruby/ruby.h" /* for VALUE */ #if 0 -#elif defined(NO_SANITIZE) && __has_feature(memory_sanitizer) +#elif __has_feature(memory_sanitizer) && __has_feature(address_sanitizer) # define ATTRIBUTE_NO_ADDRESS_SAFETY_ANALYSIS(x) \ - NO_SANITIZE("memory", NO_SANITIZE("address", NOINLINE(x))) -#elif defined(NO_SANITIZE) + __attribute__((__no_sanitize__("memory, address"), __noinline__)) x +#elif __has_feature(address_sanitizer) # define ATTRIBUTE_NO_ADDRESS_SAFETY_ANALYSIS(x) \ - NO_SANITIZE("address", NOINLINE(x)) + __attribute__((__no_sanitize__("memory, address"), __noinline__)) x #elif defined(NO_SANITIZE_ADDRESS) # define ATTRIBUTE_NO_ADDRESS_SAFETY_ANALYSIS(x) \ NO_SANITIZE_ADDRESS(NOINLINE(x)) @@ -30,8 +48,9 @@ #if defined(NO_SANITIZE) && defined(__GNUC__) &&! defined(__clang__) /* GCC warns about unknown sanitizer, which is annoying. */ -#undef NO_SANITIZE -#define NO_SANITIZE(x, y) \ +# include "internal/warnings.h" +# undef NO_SANITIZE +# define NO_SANITIZE(x, y) \ COMPILER_WARNING_PUSH; \ COMPILER_WARNING_IGNORED(-Wattributes); \ __attribute__((__no_sanitize__(x))) y; \ @@ -42,37 +61,12 @@ # define NO_SANITIZE(x, y) y #endif -#ifdef HAVE_VALGRIND_MEMCHECK_H -# include <valgrind/memcheck.h> -# ifndef VALGRIND_MAKE_MEM_DEFINED -# define VALGRIND_MAKE_MEM_DEFINED(p, n) VALGRIND_MAKE_READABLE((p), (n)) -# endif -# ifndef VALGRIND_MAKE_MEM_UNDEFINED -# define VALGRIND_MAKE_MEM_UNDEFINED(p, n) VALGRIND_MAKE_WRITABLE((p), (n)) -# endif -#else -# define VALGRIND_MAKE_MEM_DEFINED(p, n) 0 -# define VALGRIND_MAKE_MEM_UNDEFINED(p, n) 0 -#endif - -#ifndef MJIT_HEADER - -#ifdef HAVE_SANITIZER_ASAN_INTERFACE_H -# include <sanitizer/asan_interface.h> -#endif - #if !__has_feature(address_sanitizer) # define __asan_poison_memory_region(x, y) # define __asan_unpoison_memory_region(x, y) # define __asan_region_is_poisoned(x, y) 0 #endif -#ifdef HAVE_SANITIZER_MSAN_INTERFACE_H -# if __has_feature(memory_sanitizer) -# include <sanitizer/msan_interface.h> -# endif -#endif - #if !__has_feature(memory_sanitizer) # define __msan_allocated_memory(x, y) ((void)(x), (void)(y)) # define __msan_poison(x, y) ((void)(x), (void)(y)) @@ -80,6 +74,24 @@ # define __msan_unpoison_string(x) ((void)(x)) #endif +#ifdef VALGRIND_MAKE_READABLE +# define VALGRIND_MAKE_MEM_DEFINED(p, n) VALGRIND_MAKE_READABLE((p), (n)) +#endif + +#ifdef VALGRIND_MAKE_WRITABLE +# define VALGRIND_MAKE_MEM_UNDEFINED(p, n) VALGRIND_MAKE_WRITABLE((p), (n)) +#endif + +#ifndef VALGRIND_MAKE_MEM_DEFINED +# define VALGRIND_MAKE_MEM_DEFINED(p, n) 0 +#endif + +#ifndef VALGRIND_MAKE_MEM_UNDEFINED +# define VALGRIND_MAKE_MEM_UNDEFINED(p, n) 0 +#endif + +#ifndef MJIT_HEADER + /*! * This function asserts that a (continuous) memory region from ptr to size * being "poisoned". Both read / write access to such memory region are @@ -174,6 +186,6 @@ asan_unpoison_object(VALUE obj, bool newobj_p) asan_unpoison_memory_region(ptr, SIZEOF_VALUE, newobj_p); } -#endif +#endif /* MJIT_HEADER */ #endif /* INTERNAL_SANITIZERS_H */ |