Skip to content

Commit

Permalink
Fix TSAN for CI
Browse files Browse the repository at this point in the history
  • Loading branch information
mjp41 committed Jun 12, 2024
1 parent 739fae2 commit 4da5b35
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 6 deletions.
3 changes: 3 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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})
Expand Down
6 changes: 0 additions & 6 deletions src/snmalloc/ds/mpmcstack.h
Original file line number Diff line number Diff line change
Expand Up @@ -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<class T, Construction c = RequiresInit>
Expand Down
8 changes: 8 additions & 0 deletions src/snmalloc/ds/pagemap.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
#pragma once

#include "../ds_core/ds_core.h"

namespace snmalloc
{
/**
Expand Down Expand Up @@ -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);
Expand Down

0 comments on commit 4da5b35

Please sign in to comment.