111
|
1 //===-- asan_posix.cc -----------------------------------------------------===//
|
|
2 //
|
|
3 // This file is distributed under the University of Illinois Open Source
|
|
4 // License. See LICENSE.TXT for details.
|
|
5 //
|
|
6 //===----------------------------------------------------------------------===//
|
|
7 //
|
|
8 // This file is a part of AddressSanitizer, an address sanity checker.
|
|
9 //
|
|
10 // Posix-specific details.
|
|
11 //===----------------------------------------------------------------------===//
|
|
12
|
|
13 #include "sanitizer_common/sanitizer_platform.h"
|
|
14 #if SANITIZER_POSIX
|
|
15
|
|
16 #include "asan_internal.h"
|
|
17 #include "asan_interceptors.h"
|
|
18 #include "asan_mapping.h"
|
|
19 #include "asan_report.h"
|
|
20 #include "asan_stack.h"
|
|
21 #include "sanitizer_common/sanitizer_libc.h"
|
|
22 #include "sanitizer_common/sanitizer_posix.h"
|
|
23 #include "sanitizer_common/sanitizer_procmaps.h"
|
|
24
|
|
25 #include <pthread.h>
|
|
26 #include <signal.h>
|
|
27 #include <stdlib.h>
|
|
28 #include <sys/time.h>
|
|
29 #include <sys/resource.h>
|
|
30 #include <unistd.h>
|
|
31
|
|
32 namespace __asan {
|
|
33
|
|
34 void AsanOnDeadlySignal(int signo, void *siginfo, void *context) {
|
|
35 StartReportDeadlySignal();
|
|
36 SignalContext sig(siginfo, context);
|
|
37 ReportDeadlySignal(sig);
|
|
38 }
|
|
39
|
|
40 // ---------------------- TSD ---------------- {{{1
|
|
41
|
|
42 static pthread_key_t tsd_key;
|
|
43 static bool tsd_key_inited = false;
|
|
44 void AsanTSDInit(void (*destructor)(void *tsd)) {
|
|
45 CHECK(!tsd_key_inited);
|
|
46 tsd_key_inited = true;
|
|
47 CHECK_EQ(0, pthread_key_create(&tsd_key, destructor));
|
|
48 }
|
|
49
|
|
50 void *AsanTSDGet() {
|
|
51 CHECK(tsd_key_inited);
|
|
52 return pthread_getspecific(tsd_key);
|
|
53 }
|
|
54
|
|
55 void AsanTSDSet(void *tsd) {
|
|
56 CHECK(tsd_key_inited);
|
|
57 pthread_setspecific(tsd_key, tsd);
|
|
58 }
|
|
59
|
|
60 void PlatformTSDDtor(void *tsd) {
|
|
61 AsanThreadContext *context = (AsanThreadContext*)tsd;
|
|
62 if (context->destructor_iterations > 1) {
|
|
63 context->destructor_iterations--;
|
|
64 CHECK_EQ(0, pthread_setspecific(tsd_key, tsd));
|
|
65 return;
|
|
66 }
|
|
67 AsanThread::TSDDtor(tsd);
|
|
68 }
|
|
69 } // namespace __asan
|
|
70
|
|
71 #endif // SANITIZER_POSIX
|