Skip to content

Add helgrind and drd annotations to critnib data strcture #411

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Apr 5, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 12 additions & 2 deletions src/utils/utils_concurrency.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@
#include <stdatomic.h>
#endif

#include "utils_sanitizers.h"

#ifdef __cplusplus
extern "C" {
#endif
Expand Down Expand Up @@ -72,9 +74,17 @@ static __inline unsigned char util_mssb_index(long long value) {
#define util_lssb_index(x) ((unsigned char)__builtin_ctzll(x))
#define util_mssb_index(x) ((unsigned char)(63 - __builtin_clzll(x)))
#define util_atomic_load_acquire(object, dest) \
__atomic_load(object, dest, memory_order_acquire)
do { \
utils_annotate_acquire((void *)object); \
__atomic_load(object, dest, memory_order_acquire); \
} while (0)

#define util_atomic_store_release(object, desired) \
__atomic_store_n(object, desired, memory_order_release)
do { \
__atomic_store_n(object, desired, memory_order_release); \
utils_annotate_release((void *)dst); \
} while (0)

#define util_atomic_increment(object) \
__atomic_add_fetch(object, 1, __ATOMIC_ACQ_REL)
#endif
Expand Down
9 changes: 9 additions & 0 deletions src/utils/utils_sanitizers.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@
*
*/

#ifndef UMF_UTILS_SANITIZERS_H
#define UMF_UTILS_SANITIZERS_H 1

#if defined(__has_feature)
#if __has_feature(thread_sanitizer)
#ifndef __SANITIZE_THREAD__
Expand Down Expand Up @@ -113,6 +116,8 @@ extern "C" {
static inline void utils_annotate_acquire(void *ptr) {
#if __SANITIZE_THREAD__
__tsan_acquire(ptr);
#elif UMF_VG_HELGRIND_ENABLED || UMF_VG_DRD_ENABLED
ANNOTATE_HAPPENS_AFTER(ptr);
#else
(void)ptr;
#endif
Expand All @@ -121,6 +126,8 @@ static inline void utils_annotate_acquire(void *ptr) {
static inline void utils_annotate_release(void *ptr) {
#if __SANITIZE_THREAD__
__tsan_release(ptr);
#elif UMF_VG_HELGRIND_ENABLED || UMF_VG_DRD_ENABLED
ANNOTATE_HAPPENS_BEFORE(ptr);
#else
(void)ptr;
#endif
Expand Down Expand Up @@ -164,3 +171,5 @@ static inline void utils_annotate_memory_inaccessible(void *ptr, size_t size) {
#ifdef __cplusplus
}
#endif

#endif /* UMF_UTILS_SANITIZERS_H */