Skip to content

Commit 765921d

Browse files
committed
sanitizer_common: prefix thread-safety macros with SANITIZER_
Currently we use very common names for macros like ACQUIRE/RELEASE, which cause conflicts with system headers. Prefix all macros with SANITIZER_ to avoid conflicts. Reviewed By: vitalybuka Differential Revision: https://reviews.llvm.org/D116652
1 parent 21babe4 commit 765921d

28 files changed

+133
-121
lines changed

compiler-rt/lib/asan/asan_allocator.cpp

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -840,12 +840,12 @@ struct Allocator {
840840
quarantine.PrintStats();
841841
}
842842

843-
void ForceLock() ACQUIRE(fallback_mutex) {
843+
void ForceLock() SANITIZER_ACQUIRE(fallback_mutex) {
844844
allocator.ForceLock();
845845
fallback_mutex.Lock();
846846
}
847847

848-
void ForceUnlock() RELEASE(fallback_mutex) {
848+
void ForceUnlock() SANITIZER_RELEASE(fallback_mutex) {
849849
fallback_mutex.Unlock();
850850
allocator.ForceUnlock();
851851
}
@@ -1054,9 +1054,11 @@ uptr asan_mz_size(const void *ptr) {
10541054
return instance.AllocationSize(reinterpret_cast<uptr>(ptr));
10551055
}
10561056

1057-
void asan_mz_force_lock() NO_THREAD_SAFETY_ANALYSIS { instance.ForceLock(); }
1057+
void asan_mz_force_lock() SANITIZER_NO_THREAD_SAFETY_ANALYSIS {
1058+
instance.ForceLock();
1059+
}
10581060

1059-
void asan_mz_force_unlock() NO_THREAD_SAFETY_ANALYSIS {
1061+
void asan_mz_force_unlock() SANITIZER_NO_THREAD_SAFETY_ANALYSIS {
10601062
instance.ForceUnlock();
10611063
}
10621064

compiler-rt/lib/cfi/cfi.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -322,14 +322,14 @@ void InitShadow() {
322322
THREADLOCAL int in_loader;
323323
Mutex shadow_update_lock;
324324

325-
void EnterLoader() NO_THREAD_SAFETY_ANALYSIS {
325+
void EnterLoader() SANITIZER_NO_THREAD_SAFETY_ANALYSIS {
326326
if (in_loader == 0) {
327327
shadow_update_lock.Lock();
328328
}
329329
++in_loader;
330330
}
331331

332-
void ExitLoader() NO_THREAD_SAFETY_ANALYSIS {
332+
void ExitLoader() SANITIZER_NO_THREAD_SAFETY_ANALYSIS {
333333
CHECK(in_loader > 0);
334334
--in_loader;
335335
UpdateShadow();

compiler-rt/lib/lsan/lsan_common.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -230,8 +230,8 @@ void UnlockAllocator();
230230
// Returns true if [addr, addr + sizeof(void *)) is poisoned.
231231
bool WordIsPoisoned(uptr addr);
232232
// Wrappers for ThreadRegistry access.
233-
void LockThreadRegistry() NO_THREAD_SAFETY_ANALYSIS;
234-
void UnlockThreadRegistry() NO_THREAD_SAFETY_ANALYSIS;
233+
void LockThreadRegistry() SANITIZER_NO_THREAD_SAFETY_ANALYSIS;
234+
void UnlockThreadRegistry() SANITIZER_NO_THREAD_SAFETY_ANALYSIS;
235235

236236
struct ScopedStopTheWorldLock {
237237
ScopedStopTheWorldLock() {

compiler-rt/lib/memprof/memprof_allocator.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -524,12 +524,12 @@ struct Allocator {
524524

525525
void PrintStats() { allocator.PrintStats(); }
526526

527-
void ForceLock() NO_THREAD_SAFETY_ANALYSIS {
527+
void ForceLock() SANITIZER_NO_THREAD_SAFETY_ANALYSIS {
528528
allocator.ForceLock();
529529
fallback_mutex.Lock();
530530
}
531531

532-
void ForceUnlock() NO_THREAD_SAFETY_ANALYSIS {
532+
void ForceUnlock() SANITIZER_NO_THREAD_SAFETY_ANALYSIS {
533533
fallback_mutex.Unlock();
534534
allocator.ForceUnlock();
535535
}

compiler-rt/lib/sanitizer_common/sanitizer_addrhashmap.h

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -201,7 +201,8 @@ AddrHashMap<T, kSize>::AddrHashMap() {
201201
}
202202

203203
template <typename T, uptr kSize>
204-
void AddrHashMap<T, kSize>::acquire(Handle *h) NO_THREAD_SAFETY_ANALYSIS {
204+
void AddrHashMap<T, kSize>::acquire(Handle *h)
205+
SANITIZER_NO_THREAD_SAFETY_ANALYSIS {
205206
uptr addr = h->addr_;
206207
uptr hash = calcHash(addr);
207208
Bucket *b = &table_[hash];
@@ -330,7 +331,8 @@ void AddrHashMap<T, kSize>::acquire(Handle *h) NO_THREAD_SAFETY_ANALYSIS {
330331
}
331332

332333
template <typename T, uptr kSize>
333-
void AddrHashMap<T, kSize>::release(Handle *h) NO_THREAD_SAFETY_ANALYSIS {
334+
void AddrHashMap<T, kSize>::release(Handle *h)
335+
SANITIZER_NO_THREAD_SAFETY_ANALYSIS {
334336
if (!h->cell_)
335337
return;
336338
Bucket *b = h->bucket_;

compiler-rt/lib/sanitizer_common/sanitizer_allocator.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -126,12 +126,12 @@ void InternalFree(void *addr, InternalAllocatorCache *cache) {
126126
RawInternalFree(addr, cache);
127127
}
128128

129-
void InternalAllocatorLock() NO_THREAD_SAFETY_ANALYSIS {
129+
void InternalAllocatorLock() SANITIZER_NO_THREAD_SAFETY_ANALYSIS {
130130
internal_allocator_cache_mu.Lock();
131131
internal_allocator()->ForceLock();
132132
}
133133

134-
void InternalAllocatorUnlock() NO_THREAD_SAFETY_ANALYSIS {
134+
void InternalAllocatorUnlock() SANITIZER_NO_THREAD_SAFETY_ANALYSIS {
135135
internal_allocator()->ForceUnlock();
136136
internal_allocator_cache_mu.Unlock();
137137
}

compiler-rt/lib/sanitizer_common/sanitizer_allocator_combined.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -175,12 +175,12 @@ class CombinedAllocator {
175175

176176
// ForceLock() and ForceUnlock() are needed to implement Darwin malloc zone
177177
// introspection API.
178-
void ForceLock() NO_THREAD_SAFETY_ANALYSIS {
178+
void ForceLock() SANITIZER_NO_THREAD_SAFETY_ANALYSIS {
179179
primary_.ForceLock();
180180
secondary_.ForceLock();
181181
}
182182

183-
void ForceUnlock() NO_THREAD_SAFETY_ANALYSIS {
183+
void ForceUnlock() SANITIZER_NO_THREAD_SAFETY_ANALYSIS {
184184
secondary_.ForceUnlock();
185185
primary_.ForceUnlock();
186186
}

compiler-rt/lib/sanitizer_common/sanitizer_allocator_primary32.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -238,13 +238,13 @@ class SizeClassAllocator32 {
238238

239239
// ForceLock() and ForceUnlock() are needed to implement Darwin malloc zone
240240
// introspection API.
241-
void ForceLock() NO_THREAD_SAFETY_ANALYSIS {
241+
void ForceLock() SANITIZER_NO_THREAD_SAFETY_ANALYSIS {
242242
for (uptr i = 0; i < kNumClasses; i++) {
243243
GetSizeClassInfo(i)->mutex.Lock();
244244
}
245245
}
246246

247-
void ForceUnlock() NO_THREAD_SAFETY_ANALYSIS {
247+
void ForceUnlock() SANITIZER_NO_THREAD_SAFETY_ANALYSIS {
248248
for (int i = kNumClasses - 1; i >= 0; i--) {
249249
GetSizeClassInfo(i)->mutex.Unlock();
250250
}

compiler-rt/lib/sanitizer_common/sanitizer_allocator_primary64.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -354,13 +354,13 @@ class SizeClassAllocator64 {
354354

355355
// ForceLock() and ForceUnlock() are needed to implement Darwin malloc zone
356356
// introspection API.
357-
void ForceLock() NO_THREAD_SAFETY_ANALYSIS {
357+
void ForceLock() SANITIZER_NO_THREAD_SAFETY_ANALYSIS {
358358
for (uptr i = 0; i < kNumClasses; i++) {
359359
GetRegionInfo(i)->mutex.Lock();
360360
}
361361
}
362362

363-
void ForceUnlock() NO_THREAD_SAFETY_ANALYSIS {
363+
void ForceUnlock() SANITIZER_NO_THREAD_SAFETY_ANALYSIS {
364364
for (int i = (int)kNumClasses - 1; i >= 0; i--) {
365365
GetRegionInfo(i)->mutex.Unlock();
366366
}

compiler-rt/lib/sanitizer_common/sanitizer_allocator_secondary.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -267,9 +267,9 @@ class LargeMmapAllocator {
267267

268268
// ForceLock() and ForceUnlock() are needed to implement Darwin malloc zone
269269
// introspection API.
270-
void ForceLock() ACQUIRE(mutex_) { mutex_.Lock(); }
270+
void ForceLock() SANITIZER_ACQUIRE(mutex_) { mutex_.Lock(); }
271271

272-
void ForceUnlock() RELEASE(mutex_) { mutex_.Unlock(); }
272+
void ForceUnlock() SANITIZER_RELEASE(mutex_) { mutex_.Unlock(); }
273273

274274
// Iterate over all existing chunks.
275275
// The allocator must be locked when calling this function.

compiler-rt/lib/sanitizer_common/sanitizer_common.h

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -238,12 +238,12 @@ void SetPrintfAndReportCallback(void (*callback)(const char *));
238238
// Lock sanitizer error reporting and protects against nested errors.
239239
class ScopedErrorReportLock {
240240
public:
241-
ScopedErrorReportLock() ACQUIRE(mutex_) { Lock(); }
242-
~ScopedErrorReportLock() RELEASE(mutex_) { Unlock(); }
241+
ScopedErrorReportLock() SANITIZER_ACQUIRE(mutex_) { Lock(); }
242+
~ScopedErrorReportLock() SANITIZER_RELEASE(mutex_) { Unlock(); }
243243

244-
static void Lock() ACQUIRE(mutex_);
245-
static void Unlock() RELEASE(mutex_);
246-
static void CheckLocked() CHECK_LOCKED(mutex_);
244+
static void Lock() SANITIZER_ACQUIRE(mutex_);
245+
static void Unlock() SANITIZER_RELEASE(mutex_);
246+
static void CheckLocked() SANITIZER_CHECK_LOCKED(mutex_);
247247

248248
private:
249249
static atomic_uintptr_t reporting_thread_;

compiler-rt/lib/sanitizer_common/sanitizer_mutex.h

Lines changed: 26 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -20,25 +20,27 @@
2020

2121
namespace __sanitizer {
2222

23-
class MUTEX StaticSpinMutex {
23+
class SANITIZER_MUTEX StaticSpinMutex {
2424
public:
2525
void Init() {
2626
atomic_store(&state_, 0, memory_order_relaxed);
2727
}
2828

29-
void Lock() ACQUIRE() {
29+
void Lock() SANITIZER_ACQUIRE() {
3030
if (LIKELY(TryLock()))
3131
return;
3232
LockSlow();
3333
}
3434

35-
bool TryLock() TRY_ACQUIRE(true) {
35+
bool TryLock() SANITIZER_TRY_ACQUIRE(true) {
3636
return atomic_exchange(&state_, 1, memory_order_acquire) == 0;
3737
}
3838

39-
void Unlock() RELEASE() { atomic_store(&state_, 0, memory_order_release); }
39+
void Unlock() SANITIZER_RELEASE() {
40+
atomic_store(&state_, 0, memory_order_release);
41+
}
4042

41-
void CheckLocked() const CHECK_LOCKED() {
43+
void CheckLocked() const SANITIZER_CHECK_LOCKED() {
4244
CHECK_EQ(atomic_load(&state_, memory_order_relaxed), 1);
4345
}
4446

@@ -48,7 +50,7 @@ class MUTEX StaticSpinMutex {
4850
void LockSlow();
4951
};
5052

51-
class MUTEX SpinMutex : public StaticSpinMutex {
53+
class SANITIZER_MUTEX SpinMutex : public StaticSpinMutex {
5254
public:
5355
SpinMutex() {
5456
Init();
@@ -156,12 +158,12 @@ class CheckedMutex {
156158
// Derive from CheckedMutex for the purposes of EBO.
157159
// We could make it a field marked with [[no_unique_address]],
158160
// but this attribute is not supported by some older compilers.
159-
class MUTEX Mutex : CheckedMutex {
161+
class SANITIZER_MUTEX Mutex : CheckedMutex {
160162
public:
161163
explicit constexpr Mutex(MutexType type = MutexUnchecked)
162164
: CheckedMutex(type) {}
163165

164-
void Lock() ACQUIRE() {
166+
void Lock() SANITIZER_ACQUIRE() {
165167
CheckedMutex::Lock();
166168
u64 reset_mask = ~0ull;
167169
u64 state = atomic_load_relaxed(&state_);
@@ -206,7 +208,7 @@ class MUTEX Mutex : CheckedMutex {
206208
}
207209
}
208210

209-
void Unlock() RELEASE() {
211+
void Unlock() SANITIZER_RELEASE() {
210212
CheckedMutex::Unlock();
211213
bool wake_writer;
212214
u64 wake_readers;
@@ -234,7 +236,7 @@ class MUTEX Mutex : CheckedMutex {
234236
readers_.Post(wake_readers);
235237
}
236238

237-
void ReadLock() ACQUIRE_SHARED() {
239+
void ReadLock() SANITIZER_ACQUIRE_SHARED() {
238240
CheckedMutex::Lock();
239241
u64 reset_mask = ~0ull;
240242
u64 state = atomic_load_relaxed(&state_);
@@ -271,7 +273,7 @@ class MUTEX Mutex : CheckedMutex {
271273
}
272274
}
273275

274-
void ReadUnlock() RELEASE_SHARED() {
276+
void ReadUnlock() SANITIZER_RELEASE_SHARED() {
275277
CheckedMutex::Unlock();
276278
bool wake;
277279
u64 new_state;
@@ -297,13 +299,13 @@ class MUTEX Mutex : CheckedMutex {
297299
// owns the mutex but a child checks that it is locked. Rather than
298300
// maintaining complex state to work around those situations, the check only
299301
// checks that the mutex is owned.
300-
void CheckWriteLocked() const CHECK_LOCKED() {
302+
void CheckWriteLocked() const SANITIZER_CHECK_LOCKED() {
301303
CHECK(atomic_load(&state_, memory_order_relaxed) & kWriterLock);
302304
}
303305

304-
void CheckLocked() const CHECK_LOCKED() { CheckWriteLocked(); }
306+
void CheckLocked() const SANITIZER_CHECK_LOCKED() { CheckWriteLocked(); }
305307

306-
void CheckReadLocked() const CHECK_LOCKED() {
308+
void CheckReadLocked() const SANITIZER_CHECK_LOCKED() {
307309
CHECK(atomic_load(&state_, memory_order_relaxed) & kReaderLockMask);
308310
}
309311

@@ -361,13 +363,13 @@ void FutexWait(atomic_uint32_t *p, u32 cmp);
361363
void FutexWake(atomic_uint32_t *p, u32 count);
362364

363365
template <typename MutexType>
364-
class SCOPED_LOCK GenericScopedLock {
366+
class SANITIZER_SCOPED_LOCK GenericScopedLock {
365367
public:
366-
explicit GenericScopedLock(MutexType *mu) ACQUIRE(mu) : mu_(mu) {
368+
explicit GenericScopedLock(MutexType *mu) SANITIZER_ACQUIRE(mu) : mu_(mu) {
367369
mu_->Lock();
368370
}
369371

370-
~GenericScopedLock() RELEASE() { mu_->Unlock(); }
372+
~GenericScopedLock() SANITIZER_RELEASE() { mu_->Unlock(); }
371373

372374
private:
373375
MutexType *mu_;
@@ -377,13 +379,14 @@ class SCOPED_LOCK GenericScopedLock {
377379
};
378380

379381
template <typename MutexType>
380-
class SCOPED_LOCK GenericScopedReadLock {
382+
class SANITIZER_SCOPED_LOCK GenericScopedReadLock {
381383
public:
382-
explicit GenericScopedReadLock(MutexType *mu) ACQUIRE(mu) : mu_(mu) {
384+
explicit GenericScopedReadLock(MutexType *mu) SANITIZER_ACQUIRE(mu)
385+
: mu_(mu) {
383386
mu_->ReadLock();
384387
}
385388

386-
~GenericScopedReadLock() RELEASE() { mu_->ReadUnlock(); }
389+
~GenericScopedReadLock() SANITIZER_RELEASE() { mu_->ReadUnlock(); }
387390

388391
private:
389392
MutexType *mu_;
@@ -393,18 +396,18 @@ class SCOPED_LOCK GenericScopedReadLock {
393396
};
394397

395398
template <typename MutexType>
396-
class SCOPED_LOCK GenericScopedRWLock {
399+
class SANITIZER_SCOPED_LOCK GenericScopedRWLock {
397400
public:
398401
ALWAYS_INLINE explicit GenericScopedRWLock(MutexType *mu, bool write)
399-
ACQUIRE(mu)
402+
SANITIZER_ACQUIRE(mu)
400403
: mu_(mu), write_(write) {
401404
if (write_)
402405
mu_->Lock();
403406
else
404407
mu_->ReadLock();
405408
}
406409

407-
ALWAYS_INLINE ~GenericScopedRWLock() RELEASE() {
410+
ALWAYS_INLINE ~GenericScopedRWLock() SANITIZER_RELEASE() {
408411
if (write_)
409412
mu_->Unlock();
410413
else

compiler-rt/lib/sanitizer_common/sanitizer_platform_limits_posix.cpp

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -170,13 +170,9 @@ typedef struct user_fpregs elf_fpregset_t;
170170
#endif
171171

172172
// Include these after system headers to avoid name clashes and ambiguities.
173-
#include "sanitizer_internal_defs.h"
174-
#include "sanitizer_platform_limits_posix.h"
175-
176-
// To prevent macro redefinition warning between our sanitizer_thread_safety.h
177-
// and system's scsi.h.
178-
# undef RELEASE
179173
# include "sanitizer_common.h"
174+
# include "sanitizer_internal_defs.h"
175+
# include "sanitizer_platform_limits_posix.h"
180176

181177
namespace __sanitizer {
182178
unsigned struct_utsname_sz = sizeof(struct utsname);

compiler-rt/lib/sanitizer_common/sanitizer_quarantine.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -149,8 +149,8 @@ class Quarantine {
149149
Cache cache_;
150150
char pad2_[kCacheLineSize];
151151

152-
void NOINLINE Recycle(uptr min_size, Callback cb) REQUIRES(recycle_mutex_)
153-
RELEASE(recycle_mutex_) {
152+
void NOINLINE Recycle(uptr min_size, Callback cb)
153+
SANITIZER_REQUIRES(recycle_mutex_) SANITIZER_RELEASE(recycle_mutex_) {
154154
Cache tmp;
155155
{
156156
SpinMutexLock l(&cache_mutex_);

compiler-rt/lib/sanitizer_common/sanitizer_stack_store.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ class StackStore {
9797
Packed,
9898
Unpacked,
9999
};
100-
State state GUARDED_BY(mtx_);
100+
State state SANITIZER_GUARDED_BY(mtx_);
101101

102102
uptr *Create(StackStore *store);
103103

@@ -109,8 +109,8 @@ class StackStore {
109109
void TestOnlyUnmap(StackStore *store);
110110
bool Stored(uptr n);
111111
bool IsPacked() const;
112-
void Lock() NO_THREAD_SAFETY_ANALYSIS { mtx_.Lock(); }
113-
void Unlock() NO_THREAD_SAFETY_ANALYSIS { mtx_.Unlock(); }
112+
void Lock() SANITIZER_NO_THREAD_SAFETY_ANALYSIS { mtx_.Lock(); }
113+
void Unlock() SANITIZER_NO_THREAD_SAFETY_ANALYSIS { mtx_.Unlock(); }
114114
};
115115

116116
BlockInfo blocks_[kBlockCount] = {};

0 commit comments

Comments
 (0)