Commit e71ead7b authored by Kenny Yu's avatar Kenny Yu Committed by Facebook Github Bot

Add TSAN annotation macros for shared mutexes

Summary:
This change is part of a bigger effort to make `folly::SharedMutex`
compatible with TSAN so that TSAN can find lock inversions with these
types of mutexes.

In order to do this, we need to annotate the mutex function calls
accordingly. The annotation functions are provided by the TSAN
runtime library.

Upcoming changes to `folly::SharedMutex`:

1. provide annotation helper macros (this change)
2. fix or suppress known issues in existing libraries (these macros will allow us to suppress issues)
3. once all the issues are fixed, annotate `SharedMutex` accordingly

Reviewed By: nbronson

Differential Revision: D9797582

fbshipit-source-id: 12306db98505fe31a8d8590113d10585840fbe6d
parent 03fe7209
......@@ -95,6 +95,84 @@
#define FOLLY_SANITIZE_THREAD 1
#endif
/* These functions are defined by the TSAN runtime library and allow us to
* annotate mutexes appopriately for TSAN. */
#ifdef FOLLY_SANITIZE_THREAD
extern "C" void
AnnotateRWLockCreate(const char* f, int l, const volatile void* addr);
extern "C" void
AnnotateRWLockCreateStatic(const char* f, int l, const volatile void* addr);
extern "C" void
AnnotateRWLockDestroy(const char* f, int l, const volatile void* addr);
extern "C" void
AnnotateRWLockAcquired(const char* f, int l, const volatile void* addr, long w);
extern "C" void
AnnotateRWLockReleased(const char* f, int l, const volatile void* addr, long w);
extern "C" void AnnotateBenignRaceSized(
const char* f,
int l,
const volatile void* addr,
long size,
const char* desc);
#define FOLLY_ANNOTATE_RWLOCK_CREATE(addr) \
AnnotateRWLockCreate(__FILE__, __LINE__, (addr))
#define FOLLY_ANNOTATE_RWLOCK_CREATE_STATIC(addr) \
AnnotateRWLockCreateStatic(__FILE__, __LINE__, (addr))
#define FOLLY_ANNOTATE_RWLOCK_DESTROY(addr) \
AnnotateRWLockDestroy(__FILE__, __LINE__, (addr))
#define FOLLY_ANNOTATE_RWLOCK_ACQUIRED(addr, w) \
AnnotateRWLockAcquired(__FILE__, __LINE__, (addr), (w))
#define FOLLY_ANNOTATE_RWLOCK_TRY_ACQUIRED(result, addr, w) \
if ((result)) { \
FOLLY_ANNOTATE_RWLOCK_ACQUIRED((addr), (w)); \
}
#define FOLLY_ANNOTATE_RWLOCK_RELEASED(addr, w) \
AnnotateRWLockReleased(__FILE__, __LINE__, (addr), (w))
#define FOLLY_ANNOTATE_BENIGN_RACE_SIZED(addr, size, desc) \
AnnotateBenignRaceSized(__FILE__, __LINE__, (addr), (size), (desc))
#else
#define FOLLY_ANNOTATE_RWLOCK_CREATE(addr) \
(void)addr; \
do { \
} while (0)
#define FOLLY_ANNOTATE_RWLOCK_CREATE_STATIC(addr) \
(void)addr; \
do { \
} while (0)
#define FOLLY_ANNOTATE_RWLOCK_DESTROY(addr) \
(void)addr; \
do { \
} while (0)
#define FOLLY_ANNOTATE_RWLOCK_ACQUIRED(addr, w) \
(void)addr; \
(void)w; \
do { \
} while (0)
#define FOLLY_ANNOTATE_RWLOCK_TRY_ACQUIRED(result, addr, w) \
(void)result; \
(void)addr; \
(void)w; \
do { \
} while (0)
#define FOLLY_ANNOTATE_RWLOCK_RELEASED(addr, w) \
(void)addr; \
(void)w; \
do { \
} while (0)
#define FOLLY_ANNOTATE_BENIGN_RACE_SIZED(addr, size, desc) \
(void)addr; \
(void)size; \
(void)desc; \
do { \
} while (0)
#endif
#define FOLLY_ANNOTATE_RWLOCK_RDLOCK 0L
#define FOLLY_ANNOTATE_RWLOCK_WRLOCK 1L
/**
* Define a convenience macro to test when ASAN, UBSAN or TSAN sanitizer are
* being used
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment