@@ -47,6 +47,79 @@ extern "C" {
47
47
#define MEM_STATIC_ASSERT (c ) { enum { MEM_static_assert = 1/(int)(!!(c)) }; }
48
48
MEM_STATIC void MEM_check (void ) { MEM_STATIC_ASSERT ((sizeof (size_t )== 4 ) || (sizeof (size_t )== 8 )); }
49
49
50
+ /* detects whether we are being compiled under msan */
51
+ #if defined (__has_feature )
52
+ # if __has_feature (memory_sanitizer )
53
+ # define MEMORY_SANITIZER 1
54
+ # endif
55
+ #endif
56
+
57
+ #if defined (MEMORY_SANITIZER )
58
+ /* Not all platforms that support msan provide sanitizers/msan_interface.h.
59
+ * We therefore declare the functions we need ourselves, rather than trying to
60
+ * include the header file... */
61
+
62
+ #include <stdint.h> /* intptr_t */
63
+
64
+ /* Make memory region fully initialized (without changing its contents). */
65
+ void __msan_unpoison (const volatile void * a , size_t size );
66
+
67
+ /* Make memory region fully uninitialized (without changing its contents).
68
+ This is a legacy interface that does not update origin information. Use
69
+ __msan_allocated_memory() instead. */
70
+ void __msan_poison (const volatile void * a , size_t size );
71
+
72
+ /* Returns the offset of the first (at least partially) poisoned byte in the
73
+ memory range, or -1 if the whole range is good. */
74
+ intptr_t __msan_test_shadow (const volatile void * x , size_t size );
75
+ #endif
76
+
77
+ /* detects whether we are being compiled under asan */
78
+ #if defined (__has_feature )
79
+ # if __has_feature (address_sanitizer )
80
+ # define ADDRESS_SANITIZER 1
81
+ # endif
82
+ #elif defined(__SANITIZE_ADDRESS__ )
83
+ # define ADDRESS_SANITIZER 1
84
+ #endif
85
+
86
+ #if defined (ADDRESS_SANITIZER )
87
+ /* Not all platforms that support asan provide sanitizers/asan_interface.h.
88
+ * We therefore declare the functions we need ourselves, rather than trying to
89
+ * include the header file... */
90
+
91
+ /**
92
+ * Marks a memory region (<c>[addr, addr+size)</c>) as unaddressable.
93
+ *
94
+ * This memory must be previously allocated by your program. Instrumented
95
+ * code is forbidden from accessing addresses in this region until it is
96
+ * unpoisoned. This function is not guaranteed to poison the entire region -
97
+ * it could poison only a subregion of <c>[addr, addr+size)</c> due to ASan
98
+ * alignment restrictions.
99
+ *
100
+ * \note This function is not thread-safe because no two threads can poison or
101
+ * unpoison memory in the same memory region simultaneously.
102
+ *
103
+ * \param addr Start of memory region.
104
+ * \param size Size of memory region. */
105
+ void __asan_poison_memory_region (void const volatile * addr , size_t size );
106
+
107
+ /**
108
+ * Marks a memory region (<c>[addr, addr+size)</c>) as addressable.
109
+ *
110
+ * This memory must be previously allocated by your program. Accessing
111
+ * addresses in this region is allowed until this region is poisoned again.
112
+ * This function could unpoison a super-region of <c>[addr, addr+size)</c> due
113
+ * to ASan alignment restrictions.
114
+ *
115
+ * \note This function is not thread-safe because no two threads can
116
+ * poison or unpoison memory in the same memory region simultaneously.
117
+ *
118
+ * \param addr Start of memory region.
119
+ * \param size Size of memory region. */
120
+ void __asan_unpoison_memory_region (void const volatile * addr , size_t size );
121
+ #endif
122
+
50
123
51
124
/*-**************************************************************
52
125
* Basic Types
@@ -102,7 +175,7 @@ MEM_STATIC void MEM_check(void) { MEM_STATIC_ASSERT((sizeof(size_t)==4) || (size
102
175
#ifndef MEM_FORCE_MEMORY_ACCESS /* can be defined externally, on command line for example */
103
176
# if defined(__GNUC__ ) && ( defined(__ARM_ARCH_6__ ) || defined(__ARM_ARCH_6J__ ) || defined(__ARM_ARCH_6K__ ) || defined(__ARM_ARCH_6Z__ ) || defined(__ARM_ARCH_6ZK__ ) || defined(__ARM_ARCH_6T2__ ) )
104
177
# define MEM_FORCE_MEMORY_ACCESS 2
105
- # elif defined(__INTEL_COMPILER ) || defined(__GNUC__ )
178
+ # elif defined(__INTEL_COMPILER ) || defined(__GNUC__ ) || defined( __ICCARM__ )
106
179
# define MEM_FORCE_MEMORY_ACCESS 1
107
180
# endif
108
181
#endif
0 commit comments