2011-11-30 09:07:02 +08:00
|
|
|
//===-- asan_lock.h ---------------------------------------------*- C++ -*-===//
|
|
|
|
//
|
|
|
|
// The LLVM Compiler Infrastructure
|
|
|
|
//
|
|
|
|
// This file is distributed under the University of Illinois Open Source
|
|
|
|
// License. See LICENSE.TXT for details.
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
//
|
|
|
|
// This file is a part of AddressSanitizer, an address sanity checker.
|
|
|
|
//
|
|
|
|
// A wrapper for a simple lock.
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
#ifndef ASAN_LOCK_H
|
|
|
|
#define ASAN_LOCK_H
|
|
|
|
|
2012-06-30 01:10:08 +08:00
|
|
|
#include "sanitizer_common/sanitizer_mutex.h"
|
2011-11-30 09:07:02 +08:00
|
|
|
#include "asan_internal.h"
|
|
|
|
|
|
|
|
// The locks in ASan are global objects and they are never destroyed to avoid
|
|
|
|
// at-exit races (that is, a lock is being used by other threads while the main
|
|
|
|
// thread is doing atexit destructors).
|
2012-01-11 05:24:40 +08:00
|
|
|
// We define the class using opaque storage to avoid including system headers.
|
2011-11-30 09:07:02 +08:00
|
|
|
|
|
|
|
namespace __asan {
|
|
|
|
|
|
|
|
class AsanLock {
|
|
|
|
public:
|
2012-01-11 05:24:40 +08:00
|
|
|
explicit AsanLock(LinkerInitialized);
|
|
|
|
void Lock();
|
|
|
|
void Unlock();
|
|
|
|
bool IsLocked() { return owner_ != 0; }
|
2011-11-30 09:07:02 +08:00
|
|
|
private:
|
2012-05-31 22:35:53 +08:00
|
|
|
uptr opaque_storage_[10];
|
|
|
|
uptr owner_; // for debugging and for malloc_introspection_t interface
|
2011-11-30 09:07:02 +08:00
|
|
|
};
|
|
|
|
|
2012-06-30 01:10:08 +08:00
|
|
|
typedef GenericScopedLock<AsanLock> ScopedLock;
|
2011-11-30 09:07:02 +08:00
|
|
|
|
|
|
|
} // namespace __asan
|
|
|
|
|
|
|
|
#endif // ASAN_LOCK_H
|