Commit 20f2b04c authored by Nathan Bronson's avatar Nathan Bronson Committed by Facebook Github Bot

move TSAN annotation hook declarations out of header

Summary:
AnnotateBenignRaceSized is prototyped with a long size arg in
some third-party libraries and a size_t arg in others.  This diff moves
folly's prototypes for the TSAN hooks out of a widely-included header
file so that the incompatible declarations can coexist.  This function
is declared with C linkage, so the mismatch is not a problem at link time.

Reviewed By: yfeldblum

Differential Revision: D12881785

fbshipit-source-id: af1b7404d9c3d9b728105591c112143d7388f4f9
parent 89f3eed9
...@@ -173,22 +173,3 @@ ...@@ -173,22 +173,3 @@
#define FOLLY_MICROSOFT_ABI_VER _MSC_VER #define FOLLY_MICROSOFT_ABI_VER _MSC_VER
#endif #endif
#endif #endif
// These functions are defined by the TSAN runtime library and enable
// annotating mutexes for TSAN.
extern "C" FOLLY_ATTR_WEAK void
AnnotateRWLockCreate(const char* f, int l, const volatile void* addr);
extern "C" FOLLY_ATTR_WEAK void
AnnotateRWLockCreateStatic(const char* f, int l, const volatile void* addr);
extern "C" FOLLY_ATTR_WEAK void
AnnotateRWLockDestroy(const char* f, int l, const volatile void* addr);
extern "C" FOLLY_ATTR_WEAK void
AnnotateRWLockAcquired(const char* f, int l, const volatile void* addr, long w);
extern "C" FOLLY_ATTR_WEAK void
AnnotateRWLockReleased(const char* f, int l, const volatile void* addr, long w);
extern "C" FOLLY_ATTR_WEAK void AnnotateBenignRaceSized(
const char* f,
int l,
const volatile void* addr,
long size,
const char* desc);
/*
* Copyright 2013-present Facebook, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#include <folly/synchronization/SanitizeThread.h>
// abseil uses size_t for size params while other FB code and libraries use
// long, so it is helpful to keep these declarations out of widely-included
// header files.
extern "C" FOLLY_ATTR_WEAK void
AnnotateRWLockCreate(const char* f, int l, const volatile void* addr);
extern "C" FOLLY_ATTR_WEAK void
AnnotateRWLockCreateStatic(const char* f, int l, const volatile void* addr);
extern "C" FOLLY_ATTR_WEAK void
AnnotateRWLockDestroy(const char* f, int l, const volatile void* addr);
extern "C" FOLLY_ATTR_WEAK void
AnnotateRWLockAcquired(const char* f, int l, const volatile void* addr, long w);
extern "C" FOLLY_ATTR_WEAK void
AnnotateRWLockReleased(const char* f, int l, const volatile void* addr, long w);
extern "C" FOLLY_ATTR_WEAK void AnnotateBenignRaceSized(
const char* f,
int l,
const volatile void* addr,
long size,
const char* desc);
namespace {
void do_nothing(...) {}
} // namespace
#if _MSC_VER
#define CALL_HOOK(name, ...) do_nothing(__VA_ARGS__)
#else
#define CALL_HOOK(name, ...) name(__VA_ARGS__)
#endif
namespace folly {
namespace detail {
void annotate_rwlock_create_impl(
void const volatile* const addr,
char const* const f,
int const l) {
if (kIsSanitizeThread) {
CALL_HOOK(AnnotateRWLockCreate, f, l, addr);
}
}
void annotate_rwlock_create_static_impl(
void const volatile* const addr,
char const* const f,
int const l) {
if (kIsSanitizeThread) {
CALL_HOOK(AnnotateRWLockCreateStatic, f, l, addr);
}
}
void annotate_rwlock_destroy_impl(
void const volatile* const addr,
char const* const f,
int const l) {
if (kIsSanitizeThread) {
CALL_HOOK(AnnotateRWLockDestroy, f, l, addr);
}
}
void annotate_rwlock_acquired_impl(
void const volatile* const addr,
annotate_rwlock_level const w,
char const* const f,
int const l) {
if (kIsSanitizeThread) {
CALL_HOOK(AnnotateRWLockAcquired, f, l, addr, static_cast<long>(w));
}
}
void annotate_rwlock_try_acquired_impl(
void const volatile* const addr,
annotate_rwlock_level const w,
bool const result,
char const* const f,
int const l) {
if (result) {
annotate_rwlock_acquired(addr, w, f, l);
}
}
void annotate_rwlock_released_impl(
void const volatile* const addr,
annotate_rwlock_level const w,
char const* const f,
int const l) {
if (kIsSanitizeThread) {
CALL_HOOK(AnnotateRWLockReleased, f, l, addr, static_cast<long>(w));
}
}
void annotate_benign_race_sized_impl(
const volatile void* addr,
long size,
const char* desc,
const char* f,
int l) {
if (kIsSanitizeThread) {
CALL_HOOK(AnnotateBenignRaceSized, f, l, addr, size, desc);
}
}
} // namespace detail
} // namespace folly
...@@ -16,7 +16,6 @@ ...@@ -16,7 +16,6 @@
#pragma once #pragma once
#include <folly/CPortability.h>
#include <folly/Portability.h> #include <folly/Portability.h>
namespace folly { namespace folly {
...@@ -27,21 +26,49 @@ enum class annotate_rwlock_level : long { ...@@ -27,21 +26,49 @@ enum class annotate_rwlock_level : long {
}; };
namespace detail { namespace detail {
FOLLY_ALWAYS_INLINE static void annotate_ignore(...) {}
} // namespace detail
#if _MSC_VER void annotate_rwlock_create_impl(
#define FOLLY_DETAIL_ANNOTATE(name, ...) detail::annotate_ignore(__VA_ARGS__) void const volatile* const addr,
#else char const* const f,
#define FOLLY_DETAIL_ANNOTATE(name, ...) Annotate##name(__VA_ARGS__) int const l);
#endif
void annotate_rwlock_create_static_impl(
void const volatile* const addr,
char const* const f,
int const l);
void annotate_rwlock_destroy_impl(
void const volatile* const addr,
char const* const f,
int const l);
void annotate_rwlock_acquired_impl(
void const volatile* const addr,
annotate_rwlock_level const w,
char const* const f,
int const l);
void annotate_rwlock_released_impl(
void const volatile* const addr,
annotate_rwlock_level const w,
char const* const f,
int const l);
void annotate_benign_race_sized_impl(
const volatile void* addr,
long size,
const char* desc,
const char* f,
int l);
} // namespace detail
FOLLY_ALWAYS_INLINE static void annotate_rwlock_create( FOLLY_ALWAYS_INLINE static void annotate_rwlock_create(
void const volatile* const addr, void const volatile* const addr,
char const* const f, char const* const f,
int const l) { int const l) {
if (kIsSanitizeThread) { if (kIsSanitizeThread) {
FOLLY_DETAIL_ANNOTATE(RWLockCreate, f, l, addr); detail::annotate_rwlock_create_impl(addr, f, l);
} }
} }
...@@ -50,7 +77,7 @@ FOLLY_ALWAYS_INLINE static void annotate_rwlock_create_static( ...@@ -50,7 +77,7 @@ FOLLY_ALWAYS_INLINE static void annotate_rwlock_create_static(
char const* const f, char const* const f,
int const l) { int const l) {
if (kIsSanitizeThread) { if (kIsSanitizeThread) {
FOLLY_DETAIL_ANNOTATE(RWLockCreateStatic, f, l, addr); detail::annotate_rwlock_create_static_impl(addr, f, l);
} }
} }
...@@ -59,7 +86,7 @@ FOLLY_ALWAYS_INLINE static void annotate_rwlock_destroy( ...@@ -59,7 +86,7 @@ FOLLY_ALWAYS_INLINE static void annotate_rwlock_destroy(
char const* const f, char const* const f,
int const l) { int const l) {
if (kIsSanitizeThread) { if (kIsSanitizeThread) {
FOLLY_DETAIL_ANNOTATE(RWLockDestroy, f, l, addr); detail::annotate_rwlock_destroy_impl(addr, f, l);
} }
} }
...@@ -69,7 +96,7 @@ FOLLY_ALWAYS_INLINE static void annotate_rwlock_acquired( ...@@ -69,7 +96,7 @@ FOLLY_ALWAYS_INLINE static void annotate_rwlock_acquired(
char const* const f, char const* const f,
int const l) { int const l) {
if (kIsSanitizeThread) { if (kIsSanitizeThread) {
FOLLY_DETAIL_ANNOTATE(RWLockAcquired, f, l, addr, static_cast<long>(w)); detail::annotate_rwlock_acquired_impl(addr, w, f, l);
} }
} }
...@@ -90,7 +117,7 @@ FOLLY_ALWAYS_INLINE static void annotate_rwlock_released( ...@@ -90,7 +117,7 @@ FOLLY_ALWAYS_INLINE static void annotate_rwlock_released(
char const* const f, char const* const f,
int const l) { int const l) {
if (kIsSanitizeThread) { if (kIsSanitizeThread) {
FOLLY_DETAIL_ANNOTATE(RWLockReleased, f, l, addr, static_cast<long>(w)); detail::annotate_rwlock_released_impl(addr, w, f, l);
} }
} }
...@@ -101,10 +128,8 @@ FOLLY_ALWAYS_INLINE static void annotate_benign_race_sized( ...@@ -101,10 +128,8 @@ FOLLY_ALWAYS_INLINE static void annotate_benign_race_sized(
char const* const f, char const* const f,
int const l) { int const l) {
if (kIsSanitizeThread) { if (kIsSanitizeThread) {
FOLLY_DETAIL_ANNOTATE(BenignRaceSized, f, l, addr, size, desc); detail::annotate_benign_race_sized_impl(addr, size, desc, f, l);
} }
} }
#undef FOLLY_DETAIL_ANNOTATE
} // namespace folly } // namespace folly
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