SanitizeThread.h 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110
  1. /*
  2. * Copyright 2013-present Facebook, Inc.
  3. *
  4. * Licensed under the Apache License, Version 2.0 (the "License");
  5. * you may not use this file except in compliance with the License.
  6. * You may obtain a copy of the License at
  7. *
  8. * http://www.apache.org/licenses/LICENSE-2.0
  9. *
  10. * Unless required by applicable law or agreed to in writing, software
  11. * distributed under the License is distributed on an "AS IS" BASIS,
  12. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13. * See the License for the specific language governing permissions and
  14. * limitations under the License.
  15. */
  16. #pragma once
  17. #include <folly/CPortability.h>
  18. #include <folly/Portability.h>
  19. namespace folly {
  20. enum class annotate_rwlock_level : long {
  21. rdlock = 0,
  22. wrlock = 1,
  23. };
  24. namespace detail {
  25. FOLLY_ALWAYS_INLINE static void annotate_ignore(...) {}
  26. } // namespace detail
  27. #if _MSC_VER
  28. #define FOLLY_DETAIL_ANNOTATE(name, ...) detail::annotate_ignore(__VA_ARGS__)
  29. #else
  30. #define FOLLY_DETAIL_ANNOTATE(name, ...) Annotate##name(__VA_ARGS__)
  31. #endif
  32. FOLLY_ALWAYS_INLINE static void annotate_rwlock_create(
  33. void const volatile* const addr,
  34. char const* const f,
  35. int const l) {
  36. if (kIsSanitizeThread) {
  37. FOLLY_DETAIL_ANNOTATE(RWLockCreate, f, l, addr);
  38. }
  39. }
  40. FOLLY_ALWAYS_INLINE static void annotate_rwlock_create_static(
  41. void const volatile* const addr,
  42. char const* const f,
  43. int const l) {
  44. if (kIsSanitizeThread) {
  45. FOLLY_DETAIL_ANNOTATE(RWLockCreateStatic, f, l, addr);
  46. }
  47. }
  48. FOLLY_ALWAYS_INLINE static void annotate_rwlock_destroy(
  49. void const volatile* const addr,
  50. char const* const f,
  51. int const l) {
  52. if (kIsSanitizeThread) {
  53. FOLLY_DETAIL_ANNOTATE(RWLockDestroy, f, l, addr);
  54. }
  55. }
  56. FOLLY_ALWAYS_INLINE static void annotate_rwlock_acquired(
  57. void const volatile* const addr,
  58. annotate_rwlock_level const w,
  59. char const* const f,
  60. int const l) {
  61. if (kIsSanitizeThread) {
  62. FOLLY_DETAIL_ANNOTATE(RWLockAcquired, f, l, addr, static_cast<long>(w));
  63. }
  64. }
  65. FOLLY_ALWAYS_INLINE static void annotate_rwlock_try_acquired(
  66. void const volatile* const addr,
  67. annotate_rwlock_level const w,
  68. bool const result,
  69. char const* const f,
  70. int const l) {
  71. if (result) {
  72. annotate_rwlock_acquired(addr, w, f, l);
  73. }
  74. }
  75. FOLLY_ALWAYS_INLINE static void annotate_rwlock_released(
  76. void const volatile* const addr,
  77. annotate_rwlock_level const w,
  78. char const* const f,
  79. int const l) {
  80. if (kIsSanitizeThread) {
  81. FOLLY_DETAIL_ANNOTATE(RWLockReleased, f, l, addr, static_cast<long>(w));
  82. }
  83. }
  84. FOLLY_ALWAYS_INLINE static void annotate_benign_race_sized(
  85. void const volatile* const addr,
  86. long const size,
  87. char const* const desc,
  88. char const* const f,
  89. int const l) {
  90. if (kIsSanitizeThread) {
  91. FOLLY_DETAIL_ANNOTATE(BenignRaceSized, f, l, addr, size, desc);
  92. }
  93. }
  94. #undef FOLLY_DETAIL_ANNOTATE
  95. } // namespace folly