summaryrefslogtreecommitdiff
path: root/lib/asan/asan_linux.cc
diff options
context:
space:
mode:
authorKostya Serebryany <kcc@google.com>2012-01-10 21:24:40 +0000
committerKostya Serebryany <kcc@google.com>2012-01-10 21:24:40 +0000
commitd55f5f8c413622db4bd28b5cca9bfeb4d61564e0 (patch)
tree32d2ebc2f181cd3a53774d7bfd0f7bc29ebb8597 /lib/asan/asan_linux.cc
parent0ecf5eb729dd81a43f8585cb438d3cb2a35899ed (diff)
downloadcompiler-rt-d55f5f8c413622db4bd28b5cca9bfeb4d61564e0.tar.gz
[asan] move OS-dependent code away from asan_lock.h
git-svn-id: https://llvm.org/svn/llvm-project/compiler-rt/trunk@147878 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/asan/asan_linux.cc')
-rw-r--r--lib/asan/asan_linux.cc21
1 files changed, 21 insertions, 0 deletions
diff --git a/lib/asan/asan_linux.cc b/lib/asan/asan_linux.cc
index a1be40e5e..17e2e379c 100644
--- a/lib/asan/asan_linux.cc
+++ b/lib/asan/asan_linux.cc
@@ -15,6 +15,7 @@
#include "asan_interceptors.h"
#include "asan_internal.h"
+#include "asan_lock.h"
#include "asan_procmaps.h"
#include "asan_thread.h"
@@ -276,6 +277,26 @@ void AsanThread::SetThreadStackTopAndBottom() {
CHECK(AddrIsInStack((uintptr_t)&attr));
}
+AsanLock::AsanLock(LinkerInitialized) {
+ // We assume that pthread_mutex_t initialized to all zeroes is a valid
+ // unlocked mutex. We can not use PTHREAD_MUTEX_INITIALIZER as it triggers
+ // a gcc warning:
+ // extended initializer lists only available with -std=c++0x or -std=gnu++0x
+}
+
+void AsanLock::Lock() {
+ CHECK(sizeof(pthread_mutex_t) <= sizeof(opaque_storage_));
+ pthread_mutex_lock((pthread_mutex_t*)&opaque_storage_);
+ CHECK(!owner_);
+ owner_ = (uintptr_t)pthread_self();
+}
+
+void AsanLock::Unlock() {
+ CHECK(owner_ == (uintptr_t)pthread_self());
+ owner_ = 0;
+ pthread_mutex_unlock((pthread_mutex_t*)&opaque_storage_);
+}
+
} // namespace __asan
#endif // __linux__