* configure.ac: Change target-libasan to target-libsanitizer.
[official-gcc.git] / libsanitizer / asan / asan_thread.h
blobdff8c88528a11c1a74d183c2c1f5890f53bb1bfb
1 //===-- asan_thread.h -------------------------------------------*- C++ -*-===//
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 // ASan-private header for asan_thread.cc.
11 //===----------------------------------------------------------------------===//
12 #ifndef ASAN_THREAD_H
13 #define ASAN_THREAD_H
15 #include "asan_allocator.h"
16 #include "asan_internal.h"
17 #include "asan_stack.h"
18 #include "asan_stats.h"
19 #include "sanitizer_common/sanitizer_libc.h"
21 namespace __asan {
23 const u32 kInvalidTid = 0xffffff; // Must fit into 24 bits.
25 class AsanThread;
27 // These objects are created for every thread and are never deleted,
28 // so we can find them by tid even if the thread is long dead.
29 class AsanThreadSummary {
30 public:
31 explicit AsanThreadSummary(LinkerInitialized) { } // for T0.
32 void Init(u32 parent_tid, StackTrace *stack) {
33 parent_tid_ = parent_tid;
34 announced_ = false;
35 tid_ = kInvalidTid;
36 if (stack) {
37 internal_memcpy(&stack_, stack, sizeof(*stack));
39 thread_ = 0;
41 u32 tid() { return tid_; }
42 void set_tid(u32 tid) { tid_ = tid; }
43 u32 parent_tid() { return parent_tid_; }
44 bool announced() { return announced_; }
45 void set_announced(bool announced) { announced_ = announced; }
46 StackTrace *stack() { return &stack_; }
47 AsanThread *thread() { return thread_; }
48 void set_thread(AsanThread *thread) { thread_ = thread; }
49 static void TSDDtor(void *tsd);
51 private:
52 u32 tid_;
53 u32 parent_tid_;
54 bool announced_;
55 StackTrace stack_;
56 AsanThread *thread_;
59 // AsanThread are stored in TSD and destroyed when the thread dies.
60 class AsanThread {
61 public:
62 explicit AsanThread(LinkerInitialized); // for T0.
63 static AsanThread *Create(u32 parent_tid, thread_callback_t start_routine,
64 void *arg, StackTrace *stack);
65 void Destroy();
67 void Init(); // Should be called from the thread itself.
68 thread_return_t ThreadStart();
70 uptr stack_top() { return stack_top_; }
71 uptr stack_bottom() { return stack_bottom_; }
72 uptr stack_size() { return stack_top_ - stack_bottom_; }
73 u32 tid() { return summary_->tid(); }
74 AsanThreadSummary *summary() { return summary_; }
75 void set_summary(AsanThreadSummary *summary) { summary_ = summary; }
77 const char *GetFrameNameByAddr(uptr addr, uptr *offset);
79 bool AddrIsInStack(uptr addr) {
80 return addr >= stack_bottom_ && addr < stack_top_;
83 FakeStack &fake_stack() { return fake_stack_; }
84 AsanThreadLocalMallocStorage &malloc_storage() { return malloc_storage_; }
85 AsanStats &stats() { return stats_; }
87 private:
88 void SetThreadStackTopAndBottom();
89 void ClearShadowForThreadStack();
90 AsanThreadSummary *summary_;
91 thread_callback_t start_routine_;
92 void *arg_;
93 uptr stack_top_;
94 uptr stack_bottom_;
96 FakeStack fake_stack_;
97 AsanThreadLocalMallocStorage malloc_storage_;
98 AsanStats stats_;
101 } // namespace __asan
103 #endif // ASAN_THREAD_H