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