Skip to content

Commit

Permalink
[fixup!] Test the NO_SANITIZE_THREAD macro
Browse files Browse the repository at this point in the history
  • Loading branch information
cherusker committed Jul 8, 2017
1 parent d67850d commit 01fda3a
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 15 deletions.
19 changes: 4 additions & 15 deletions mono/metadata/mempool.c
Expand Up @@ -20,6 +20,7 @@

#include "mempool.h"
#include "mempool-internals.h"
#include "utils/mono-compiler.h"

/*
* MonoMemPool is for fast allocation of memory. We free
Expand Down Expand Up @@ -95,18 +96,14 @@ mono_mempool_new (void)
* \param initial_size the amount of memory to initially reserve for the memory pool.
* \returns a new memory pool with a specific initial memory reservation.
*/
#if defined(__has_feature)
#if __has_feature(thread_sanitizer)
// clang's ThreadSanitizer detects races of total_bytes_allocated and pool->d.allocated throughout the functions
// * mono_mempool_alloc
// * mono_mempool_new_size
// * mono_mempool_destroy
// while these races could lead to wrong values, total_bytes_allocated is just used for debugging / reporting and since
// the mempool.c functions are called quite often, a discussion led the the conclusion of ignoring these races:
// https://bugzilla.xamarin.com/show_bug.cgi?id=57936
__attribute__ ((no_sanitize("thread")))
#endif
#endif
MONO_NO_SANITIZE_THREAD
MonoMemPool *
mono_mempool_new_size (int initial_size)
{
Expand Down Expand Up @@ -136,18 +133,14 @@ mono_mempool_new_size (int initial_size)
*
* Free all memory associated with this pool.
*/
#if defined(__has_feature)
#if __has_feature(thread_sanitizer)
// clang's ThreadSanitizer detects races of total_bytes_allocated and pool->d.allocated throughout the functions
// * mono_mempool_alloc
// * mono_mempool_new_size
// * mono_mempool_destroy
// while these races could lead to wrong values, total_bytes_allocated is just used for debugging / reporting and since
// the mempool.c functions are called quite often, a discussion led the the conclusion of ignoring these races:
// https://bugzilla.xamarin.com/show_bug.cgi?id=57936
__attribute__ ((no_sanitize("thread")))
#endif
#endif
MONO_NO_SANITIZE_THREAD
void
mono_mempool_destroy (MonoMemPool *pool)
{
Expand Down Expand Up @@ -282,18 +275,14 @@ get_next_size (MonoMemPool *pool, int size)
*
* \returns the address of a newly allocated memory block.
*/
#if defined(__has_feature)
#if __has_feature(thread_sanitizer)
// clang's ThreadSanitizer detects races of total_bytes_allocated and pool->d.allocated throughout the functions
// * mono_mempool_alloc
// * mono_mempool_new_size
// * mono_mempool_destroy
// while these races could lead to wrong values, total_bytes_allocated is just used for debugging / reporting and since
// the mempool.c functions are called quite often, a discussion led the the conclusion of ignoring these races:
// https://bugzilla.xamarin.com/show_bug.cgi?id=57936
__attribute__ ((no_sanitize("thread")))
#endif
#endif
MONO_NO_SANITIZE_THREAD
gpointer
mono_mempool_alloc (MonoMemPool *pool, guint size)
{
Expand Down
11 changes: 11 additions & 0 deletions mono/utils/mono-compiler.h
Expand Up @@ -113,5 +113,16 @@ typedef SSIZE_T ssize_t;
#define MONO_GNUC_VERSION (__GNUC__ * 10000 + __GNUC_MINOR__ * 100 + __GNUC_PATCHLEVEL__)
#endif

/* Used to tell clang's ThreadSanitizer to not report data races that occur within a certain function */
#if defined(__has_feature)
#if __has_feature(thread_sanitizer)
#define MONO_NO_SANITIZE_THREAD __attribute__ ((no_sanitize("thread")))
#else
#define MONO_NO_SANITIZE_THREAD
#endif
#else
#define MONO_NO_SANITIZE_THREAD
#endif

#endif /* __UTILS_MONO_COMPILER_H__*/

0 comments on commit 01fda3a

Please sign in to comment.