@@ -30,19 +30,36 @@ static void _PyMem_DebugCheckAddress(char api_id, const void *p);
3030static void _PyMem_SetupDebugHooksDomain (PyMemAllocatorDomain domain );
3131
3232#if defined(__has_feature ) /* Clang */
33- # if __has_feature (address_sanitizer ) /* is ASAN enabled? */
34- # define ATTRIBUTE_NO_ADDRESS_SAFETY_ANALYSIS \
33+ # if __has_feature (address_sanitizer ) /* is ASAN enabled? */
34+ # define _Py_NO_ADDRESS_SAFETY_ANALYSIS \
3535 __attribute__((no_address_safety_analysis))
36- #else
37- #define ATTRIBUTE_NO_ADDRESS_SAFETY_ANALYSIS
38- #endif
39- #else
40- #if defined(__SANITIZE_ADDRESS__ ) /* GCC 4.8.x, is ASAN enabled? */
41- #define ATTRIBUTE_NO_ADDRESS_SAFETY_ANALYSIS \
36+ # endif
37+ # if __has_feature (thread_sanitizer ) /* is TSAN enabled? */
38+ # define _Py_NO_SANITIZE_THREAD __attribute__((no_sanitize_thread))
39+ # endif
40+ # if __has_feature (memory_sanitizer ) /* is MSAN enabled? */
41+ # define _Py_NO_SANITIZE_MEMORY __attribute__((no_sanitize_memory))
42+ # endif
43+ #elif defined(__GNUC__ )
44+ # if defined(__SANITIZE_ADDRESS__ ) /* GCC 4.8+, is ASAN enabled? */
45+ # define _Py_NO_ADDRESS_SAFETY_ANALYSIS \
4246 __attribute__((no_address_safety_analysis))
43- #else
44- #define ATTRIBUTE_NO_ADDRESS_SAFETY_ANALYSIS
45- #endif
47+ # endif
48+ // TSAN is supported since GCC 4.8, but __SANITIZE_THREAD__ macro
49+ // is provided only since GCC 7.
50+ # if __GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 8 )
51+ # define _Py_NO_SANITIZE_THREAD __attribute__((no_sanitize_thread))
52+ # endif
53+ #endif
54+
55+ #ifndef _Py_NO_ADDRESS_SAFETY_ANALYSIS
56+ # define _Py_NO_ADDRESS_SAFETY_ANALYSIS
57+ #endif
58+ #ifndef _Py_NO_SANITIZE_THREAD
59+ # define _Py_NO_SANITIZE_THREAD
60+ #endif
61+ #ifndef _Py_NO_SANITIZE_MEMORY
62+ # define _Py_NO_SANITIZE_MEMORY
4663#endif
4764
4865#ifdef WITH_PYMALLOC
@@ -1301,7 +1318,9 @@ obmalloc controls. Since this test is needed at every entry point, it's
13011318extremely desirable that it be this fast.
13021319*/
13031320
1304- static bool ATTRIBUTE_NO_ADDRESS_SAFETY_ANALYSIS
1321+ static bool _Py_NO_ADDRESS_SAFETY_ANALYSIS
1322+ _Py_NO_SANITIZE_THREAD
1323+ _Py_NO_SANITIZE_MEMORY
13051324address_in_range (void * p , poolp pool )
13061325{
13071326 // Since address_in_range may be reading from memory which was not allocated
0 commit comments