1 //===-- asan_posix.cc -----------------------------------------------------===//
3 // This file is distributed under the University of Illinois Open Source
4 // License. See LICENSE.TXT for details.
6 //===----------------------------------------------------------------------===//
8 // This file is a part of AddressSanitizer, an address sanity checker.
10 // Posix-specific details.
11 //===----------------------------------------------------------------------===//
13 #include "sanitizer_common/sanitizer_platform.h"
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"
29 #include <sys/resource.h>
34 void AsanOnDeadlySignal(int signo
, void *siginfo
, void *context
) {
35 StartReportDeadlySignal();
36 SignalContext
sig(siginfo
, context
);
37 ReportDeadlySignal(sig
);
40 // ---------------------- TSD ---------------- {{{1
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
));
51 CHECK(tsd_key_inited
);
52 return pthread_getspecific(tsd_key
);
55 void AsanTSDSet(void *tsd
) {
56 CHECK(tsd_key_inited
);
57 pthread_setspecific(tsd_key
, tsd
);
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
));
67 AsanThread::TSDDtor(tsd
);
71 #endif // SANITIZER_POSIX