re PR libbacktrace/88890 (libbacktrace on 32-bit system with _FILE_OFFSET_BITS =...
[gcc.git] / libsanitizer / asan / asan_posix.cc
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 <stdlib.h>
27 #include <sys/time.h>
28 #include <sys/resource.h>
29 #include <unistd.h>
30
31 namespace __asan {
32
33 void AsanOnDeadlySignal(int signo, void *siginfo, void *context) {
34 StartReportDeadlySignal();
35 SignalContext sig(siginfo, context);
36 ReportDeadlySignal(sig);
37 }
38
39 // ---------------------- TSD ---------------- {{{1
40
41 static pthread_key_t tsd_key;
42 static bool tsd_key_inited = false;
43 void AsanTSDInit(void (*destructor)(void *tsd)) {
44 CHECK(!tsd_key_inited);
45 tsd_key_inited = true;
46 CHECK_EQ(0, pthread_key_create(&tsd_key, destructor));
47 }
48
49 void *AsanTSDGet() {
50 CHECK(tsd_key_inited);
51 return pthread_getspecific(tsd_key);
52 }
53
54 void AsanTSDSet(void *tsd) {
55 CHECK(tsd_key_inited);
56 pthread_setspecific(tsd_key, tsd);
57 }
58
59 void PlatformTSDDtor(void *tsd) {
60 AsanThreadContext *context = (AsanThreadContext*)tsd;
61 if (context->destructor_iterations > 1) {
62 context->destructor_iterations--;
63 CHECK_EQ(0, pthread_setspecific(tsd_key, tsd));
64 return;
65 }
66 AsanThread::TSDDtor(tsd);
67 }
68 } // namespace __asan
69
70 #endif // SANITIZER_POSIX