diff --git a/CMakeLists.txt b/CMakeLists.txt index 5697790cc..745ae198f 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -331,6 +331,9 @@ if(NOT SNMALLOC_HEADER_ONLY_LIBRARY) if(SNMALLOC_SANITIZER) target_compile_options(${TESTNAME} PRIVATE -g -fsanitize=${SNMALLOC_SANITIZER} -fno-omit-frame-pointer) target_link_libraries(${TESTNAME} -fsanitize=${SNMALLOC_SANITIZER}) + if (${SNMALLOC_SANITIZER} MATCHES "thread") + target_compile_definitions(${TESTNAME} PRIVATE SNMALLOC_THREAD_SANITIZER_ENABLED) + endif() endif() add_warning_flags(${TESTNAME}) diff --git a/src/snmalloc/ds/mpmcstack.h b/src/snmalloc/ds/mpmcstack.h index cd005e9bf..e6a3b1d9f 100644 --- a/src/snmalloc/ds/mpmcstack.h +++ b/src/snmalloc/ds/mpmcstack.h @@ -4,12 +4,6 @@ #include "aba.h" #include "allocconfig.h" -#if defined(__has_feature) -# if __has_feature(thread_sanitizer) -# define SNMALLOC_THREAD_SANITIZER_ENABLED -# endif -#endif - namespace snmalloc { template diff --git a/src/snmalloc/ds/pagemap.h b/src/snmalloc/ds/pagemap.h index 267fe9a0b..abfc539d0 100644 --- a/src/snmalloc/ds/pagemap.h +++ b/src/snmalloc/ds/pagemap.h @@ -1,5 +1,7 @@ #pragma once +#include "../ds_core/ds_core.h" + namespace snmalloc { /** @@ -179,7 +181,13 @@ namespace snmalloc // Allocate a power of two extra to allow the placement of the // pagemap be difficult to guess if randomize_position set. size_t additional_size = +#ifdef SNMALLOC_THREAD_SANITIZER_ENABLED + // When running with TSAN we failed to allocate the very large range + // randomly + randomize_position ? bits::next_pow2(REQUIRED_SIZE) : 0; +#else randomize_position ? bits::next_pow2(REQUIRED_SIZE) * 4 : 0; +#endif size_t request_size = REQUIRED_SIZE + additional_size; auto new_body_untyped = PAL::reserve(request_size);