Commit e83309fe authored by Yedidya Feldblum's avatar Yedidya Feldblum Committed by Facebook GitHub Bot

revise sanitizer extern wrappers

Summary: Make them a bit shorter with a bit less repetition. Performance-wise, trades away two direct calls for one indirect but perfectly-predictable call. And continues to optimize away in non-sanitizer builds.

Reviewed By: luciang

Differential Revision: D31673074

fbshipit-source-id: f6d8b66cf45a81788d1ec0c5b58241f4fc693001
parent 0ae0ccc8
......@@ -22,17 +22,20 @@
// https://github.com/llvm-mirror/compiler-rt/blob/master/include/sanitizer/asan_interface.h
extern "C" void* __asan_region_is_poisoned(void*, std::size_t);
namespace folly {
namespace detail {
namespace {
FOLLY_CREATE_EXTERN_ACCESSOR(
asan_region_is_poisoned_access_v, __asan_region_is_poisoned);
void* asan_region_is_poisoned_(void* const ptr, std::size_t len) {
constexpr auto fun =
asan_region_is_poisoned_access_v<kIsLibrarySanitizeAddress>;
return fun ? fun(ptr, len) : nullptr;
}
} // namespace
static constexpr auto const E = folly::kIsLibrarySanitizeAddress;
namespace folly {
namespace detail {
FOLLY_STORAGE_CONSTEXPR asan_region_is_poisoned_t* const
asan_region_is_poisoned_v = asan_region_is_poisoned_access_v<E>;
} // namespace detail
} // namespace folly
......@@ -22,9 +22,10 @@ namespace folly {
namespace detail {
void* asan_region_is_poisoned_(void* ptr, std::size_t len);
using asan_region_is_poisoned_t = void*(void* ptr, std::size_t len);
extern asan_region_is_poisoned_t* const asan_region_is_poisoned_v;
}
} // namespace detail
// asan_region_is_poisoned
//
......@@ -35,9 +36,8 @@ void* asan_region_is_poisoned_(void* ptr, std::size_t len);
// always returns nullptr.
FOLLY_ALWAYS_INLINE static void* asan_region_is_poisoned(
void* const ptr, std::size_t const len) {
return kIsSanitizeAddress //
? detail::asan_region_is_poisoned_(ptr, len)
: nullptr;
auto fun = detail::asan_region_is_poisoned_v;
return kIsSanitizeAddress ? fun(ptr, len) : nullptr;
}
} // namespace folly
......@@ -23,41 +23,40 @@
// header files.
extern "C" void AnnotateRWLockCreate(
const char* f, int l, const volatile void* addr);
char const* f, int l, const volatile void* addr);
extern "C" void AnnotateRWLockCreateStatic(
const char* f, int l, const volatile void* addr);
char const* f, int l, const volatile void* addr);
extern "C" void AnnotateRWLockDestroy(
const char* f, int l, const volatile void* addr);
char const* f, int l, const volatile void* addr);
extern "C" void AnnotateRWLockAcquired(
const char* f, int l, const volatile void* addr, long w);
char const* f, int l, const volatile void* addr, long w);
extern "C" void AnnotateRWLockReleased(
const char* f, int l, const volatile void* addr, long w);
char const* f, int l, const volatile void* addr, long w);
extern "C" void AnnotateBenignRaceSized(
const char* f,
char const* f,
int l,
const volatile void* addr,
long size,
const char* desc);
char const* desc);
extern "C" void AnnotateIgnoreReadsBegin(const char* f, int l);
extern "C" void AnnotateIgnoreReadsBegin(char const* f, int l);
extern "C" void AnnotateIgnoreReadsEnd(const char* f, int l);
extern "C" void AnnotateIgnoreReadsEnd(char const* f, int l);
extern "C" void AnnotateIgnoreWritesBegin(const char* f, int l);
extern "C" void AnnotateIgnoreWritesBegin(char const* f, int l);
extern "C" void AnnotateIgnoreWritesEnd(const char* f, int l);
extern "C" void AnnotateIgnoreWritesEnd(char const* f, int l);
extern "C" void AnnotateIgnoreSyncBegin(const char* f, int l);
extern "C" void AnnotateIgnoreSyncBegin(char const* f, int l);
extern "C" void AnnotateIgnoreSyncEnd(const char* f, int l);
extern "C" void AnnotateIgnoreSyncEnd(char const* f, int l);
namespace folly {
namespace detail {
namespace {
FOLLY_CREATE_EXTERN_ACCESSOR(
annotate_rwlock_create_access_v, AnnotateRWLockCreate);
......@@ -95,92 +94,48 @@ FOLLY_CREATE_EXTERN_ACCESSOR(
FOLLY_CREATE_EXTERN_ACCESSOR(
annotate_ignore_sync_end_access_v, AnnotateIgnoreSyncEnd);
void annotate_rwlock_create_impl(
void const volatile* const addr, char const* const f, int const l) {
constexpr auto fun = annotate_rwlock_create_access_v<kIsSanitizeThread>;
return fun ? fun(f, l, addr) : void();
}
void annotate_rwlock_create_static_impl(
void const volatile* const addr, char const* const f, int const l) {
constexpr auto fun =
annotate_rwlock_create_static_access_v<kIsSanitizeThread>;
return fun ? fun(f, l, addr) : void();
}
void annotate_rwlock_destroy_impl(
void const volatile* const addr, char const* const f, int const l) {
constexpr auto fun = annotate_rwlock_destroy_access_v<kIsSanitizeThread>;
return fun ? fun(f, l, addr) : void();
}
void annotate_rwlock_acquired_impl(
void const volatile* const addr,
annotate_rwlock_level const w,
char const* const f,
int const l) {
constexpr auto fun = annotate_rwlock_acquired_access_v<kIsSanitizeThread>;
return fun ? fun(f, l, addr, static_cast<long>(w)) : void();
}
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) {
constexpr auto fun = annotate_rwlock_released_access_v<kIsSanitizeThread>;
return fun ? fun(f, l, addr, static_cast<long>(w)) : void();
}
void annotate_benign_race_sized_impl(
const volatile void* addr,
long size,
const char* desc,
const char* f,
int l) {
constexpr auto fun = annotate_benign_race_sized_access_v<kIsSanitizeThread>;
return fun ? fun(f, l, addr, size, desc) : void();
}
void annotate_ignore_reads_begin_impl(const char* f, int l) {
constexpr auto fun = annotate_ignore_reads_begin_access_v<kIsSanitizeThread>;
return fun ? fun(f, l) : void();
}
void annotate_ignore_reads_end_impl(const char* f, int l) {
constexpr auto fun = annotate_ignore_reads_end_access_v<kIsSanitizeThread>;
return fun ? fun(f, l) : void();
}
void annotate_ignore_writes_begin_impl(const char* f, int l) {
constexpr auto fun = annotate_ignore_writes_begin_access_v<kIsSanitizeThread>;
return fun ? fun(f, l) : void();
}
void annotate_ignore_writes_end_impl(const char* f, int l) {
constexpr auto fun = annotate_ignore_writes_end_access_v<kIsSanitizeThread>;
return fun ? fun(f, l) : void();
}
void annotate_ignore_sync_begin_impl(const char* f, int l) {
constexpr auto fun = annotate_ignore_sync_begin_access_v<kIsSanitizeThread>;
return fun ? fun(f, l) : void();
}
void annotate_ignore_sync_end_impl(const char* f, int l) {
constexpr auto fun = annotate_ignore_sync_end_access_v<kIsSanitizeThread>;
return fun ? fun(f, l) : void();
}
} // namespace
static constexpr auto const E = folly::kIsSanitizeThread;
namespace folly {
namespace detail {
FOLLY_STORAGE_CONSTEXPR annotate_rwlock_cd_t* const annotate_rwlock_create_v =
annotate_rwlock_create_access_v<E>;
FOLLY_STORAGE_CONSTEXPR annotate_rwlock_cd_t* const
annotate_rwlock_create_static_v = annotate_rwlock_create_static_access_v<E>;
FOLLY_STORAGE_CONSTEXPR annotate_rwlock_cd_t* const annotate_rwlock_destroy_v =
annotate_rwlock_destroy_access_v<E>;
FOLLY_STORAGE_CONSTEXPR annotate_rwlock_ar_t* const annotate_rwlock_acquired_v =
annotate_rwlock_acquired_access_v<E>;
FOLLY_STORAGE_CONSTEXPR annotate_rwlock_ar_t* const annotate_rwlock_released_v =
annotate_rwlock_released_access_v<E>;
FOLLY_STORAGE_CONSTEXPR annotate_benign_race_sized_t* const
annotate_benign_race_sized_v = annotate_benign_race_sized_access_v<E>;
FOLLY_STORAGE_CONSTEXPR annotate_ignore_t* const annotate_ignore_reads_begin_v =
annotate_ignore_reads_begin_access_v<E>;
FOLLY_STORAGE_CONSTEXPR annotate_ignore_t* const annotate_ignore_reads_end_v =
annotate_ignore_reads_end_access_v<E>;
FOLLY_STORAGE_CONSTEXPR annotate_ignore_t* const
annotate_ignore_writes_begin_v = annotate_ignore_writes_begin_access_v<E>;
FOLLY_STORAGE_CONSTEXPR annotate_ignore_t* const annotate_ignore_writes_end_v =
annotate_ignore_writes_end_access_v<E>;
FOLLY_STORAGE_CONSTEXPR annotate_ignore_t* const annotate_ignore_sync_begin_v =
annotate_ignore_sync_begin_access_v<E>;
FOLLY_STORAGE_CONSTEXPR annotate_ignore_t* const annotate_ignore_sync_end_v =
annotate_ignore_sync_end_access_v<E>;
} // namespace detail
} // namespace folly
......@@ -27,67 +27,43 @@ enum class annotate_rwlock_level : long {
namespace detail {
void annotate_rwlock_create_impl(
void const volatile* const addr, char const* const f, int const l);
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);
void annotate_ignore_reads_begin_impl(const char* f, int l);
void annotate_ignore_reads_end_impl(const char* f, int l);
void annotate_ignore_writes_begin_impl(const char* f, int l);
void annotate_ignore_writes_end_impl(const char* f, int l);
void annotate_ignore_sync_begin_impl(const char* f, int l);
void annotate_ignore_sync_end_impl(const char* f, int l);
using annotate_rwlock_cd_t = void(char const*, int, void const volatile*);
using annotate_rwlock_ar_t = void(char const*, int, void const volatile*, long);
using annotate_benign_race_sized_t =
void(char const*, int, void const volatile*, long, char const*);
using annotate_ignore_t = void(char const*, int);
extern annotate_rwlock_cd_t* const annotate_rwlock_create_v;
extern annotate_rwlock_cd_t* const annotate_rwlock_create_static_v;
extern annotate_rwlock_cd_t* const annotate_rwlock_destroy_v;
extern annotate_rwlock_ar_t* const annotate_rwlock_acquired_v;
extern annotate_rwlock_ar_t* const annotate_rwlock_released_v;
extern annotate_benign_race_sized_t* const annotate_benign_race_sized_v;
extern annotate_ignore_t* const annotate_ignore_reads_begin_v;
extern annotate_ignore_t* const annotate_ignore_reads_end_v;
extern annotate_ignore_t* const annotate_ignore_writes_begin_v;
extern annotate_ignore_t* const annotate_ignore_writes_end_v;
extern annotate_ignore_t* const annotate_ignore_sync_begin_v;
extern annotate_ignore_t* const annotate_ignore_sync_end_v;
} // namespace detail
FOLLY_ALWAYS_INLINE static void annotate_rwlock_create(
void const volatile* const addr, char const* const f, int const l) {
if (kIsSanitizeThread) {
detail::annotate_rwlock_create_impl(addr, f, l);
}
auto fun = detail::annotate_rwlock_create_v;
return kIsSanitizeThread && fun ? fun(f, l, addr) : void();
}
FOLLY_ALWAYS_INLINE static void annotate_rwlock_create_static(
void const volatile* const addr, char const* const f, int const l) {
if (kIsSanitizeThread) {
detail::annotate_rwlock_create_static_impl(addr, f, l);
}
auto fun = detail::annotate_rwlock_create_static_v;
return kIsSanitizeThread && fun ? fun(f, l, addr) : void();
}
FOLLY_ALWAYS_INLINE static void annotate_rwlock_destroy(
void const volatile* const addr, char const* const f, int const l) {
if (kIsSanitizeThread) {
detail::annotate_rwlock_destroy_impl(addr, f, l);
}
auto fun = detail::annotate_rwlock_destroy_v;
return kIsSanitizeThread && fun ? fun(f, l, addr) : void();
}
FOLLY_ALWAYS_INLINE static void annotate_rwlock_acquired(
......@@ -95,9 +71,8 @@ FOLLY_ALWAYS_INLINE static void annotate_rwlock_acquired(
annotate_rwlock_level const w,
char const* const f,
int const l) {
if (kIsSanitizeThread) {
detail::annotate_rwlock_acquired_impl(addr, w, f, l);
}
auto fun = detail::annotate_rwlock_acquired_v;
return kIsSanitizeThread && fun ? fun(f, l, addr, long(w)) : void();
}
FOLLY_ALWAYS_INLINE static void annotate_rwlock_try_acquired(
......@@ -106,9 +81,7 @@ FOLLY_ALWAYS_INLINE static void annotate_rwlock_try_acquired(
bool const result,
char const* const f,
int const l) {
if (result) {
annotate_rwlock_acquired(addr, w, f, l);
}
return result ? annotate_rwlock_acquired(addr, w, f, l) : void();
}
FOLLY_ALWAYS_INLINE static void annotate_rwlock_released(
......@@ -116,9 +89,8 @@ FOLLY_ALWAYS_INLINE static void annotate_rwlock_released(
annotate_rwlock_level const w,
char const* const f,
int const l) {
if (kIsSanitizeThread) {
detail::annotate_rwlock_released_impl(addr, w, f, l);
}
auto fun = detail::annotate_rwlock_released_v;
return kIsSanitizeThread && fun ? fun(f, l, addr, long(w)) : void();
}
FOLLY_ALWAYS_INLINE static void annotate_benign_race_sized(
......@@ -127,56 +99,51 @@ FOLLY_ALWAYS_INLINE static void annotate_benign_race_sized(
char const* const desc,
char const* const f,
int const l) {
if (kIsSanitizeThread) {
detail::annotate_benign_race_sized_impl(addr, size, desc, f, l);
}
auto fun = detail::annotate_benign_race_sized_v;
return kIsSanitizeThread && fun ? fun(f, l, addr, size, desc) : void();
}
FOLLY_ALWAYS_INLINE static void annotate_ignore_reads_begin(
const char* f, int l) {
if (kIsSanitizeThread) {
detail::annotate_ignore_reads_begin_impl(f, l);
}
char const* const f, int const l) {
auto fun = detail::annotate_ignore_reads_begin_v;
return kIsSanitizeThread && fun ? fun(f, l) : void();
}
FOLLY_ALWAYS_INLINE static void annotate_ignore_reads_end(
const char* f, int l) {
if (kIsSanitizeThread) {
detail::annotate_ignore_reads_end_impl(f, l);
}
char const* const f, int const l) {
auto fun = detail::annotate_ignore_reads_end_v;
return kIsSanitizeThread && fun ? fun(f, l) : void();
}
FOLLY_ALWAYS_INLINE static void annotate_ignore_writes_begin(
const char* f, int l) {
if (kIsSanitizeThread) {
detail::annotate_ignore_writes_begin_impl(f, l);
}
char const* const f, int const l) {
auto fun = detail::annotate_ignore_writes_begin_v;
return kIsSanitizeThread && fun ? fun(f, l) : void();
}
FOLLY_ALWAYS_INLINE static void annotate_ignore_writes_end(
const char* f, int l) {
if (kIsSanitizeThread) {
detail::annotate_ignore_writes_end_impl(f, l);
}
char const* const f, int const l) {
auto fun = detail::annotate_ignore_writes_end_v;
return kIsSanitizeThread && fun ? fun(f, l) : void();
}
FOLLY_ALWAYS_INLINE static void annotate_ignore_sync_begin(
const char* f, int l) {
if (kIsSanitizeThread) {
detail::annotate_ignore_sync_begin_impl(f, l);
}
char const* const f, int const l) {
auto fun = detail::annotate_ignore_sync_begin_v;
return kIsSanitizeThread && fun ? fun(f, l) : void();
}
FOLLY_ALWAYS_INLINE static void annotate_ignore_sync_end(const char* f, int l) {
if (kIsSanitizeThread) {
detail::annotate_ignore_sync_end_impl(f, l);
}
FOLLY_ALWAYS_INLINE static void annotate_ignore_sync_end(
char const* const f, int const l) {
auto fun = detail::annotate_ignore_sync_end_v;
return kIsSanitizeThread && fun ? fun(f, l) : void();
}
class annotate_ignore_thread_sanitizer_guard {
public:
annotate_ignore_thread_sanitizer_guard(const char* file, int line)
: file_(file), line_(line) {
annotate_ignore_thread_sanitizer_guard(
char const* const file, int const line) noexcept
: file_{file}, line_{line} {
annotate_ignore_reads_begin(file_, line_);
annotate_ignore_writes_begin(file_, line_);
}
......@@ -192,8 +159,8 @@ class annotate_ignore_thread_sanitizer_guard {
}
private:
const char* file_;
int line_;
char const* const file_;
int const line_;
};
} // 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