1 //===-- asan_thread.h -------------------------------------------*- C++ -*-===//
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 // ASan-private header for asan_thread.cc.
11 //===----------------------------------------------------------------------===//
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"
23 const u32 kInvalidTid
= 0xffffff; // Must fit into 24 bits.
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
{
31 explicit AsanThreadSummary(LinkerInitialized
) { } // for T0.
32 void Init(u32 parent_tid
, StackTrace
*stack
) {
33 parent_tid_
= parent_tid
;
37 internal_memcpy(&stack_
, stack
, sizeof(*stack
));
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
);
59 // AsanThread are stored in TSD and destroyed when the thread dies.
62 explicit AsanThread(LinkerInitialized
); // for T0.
63 static AsanThread
*Create(u32 parent_tid
, thread_callback_t start_routine
,
64 void *arg
, StackTrace
*stack
);
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_
; }
88 void SetThreadStackTopAndBottom();
89 void ClearShadowForThreadStack();
90 AsanThreadSummary
*summary_
;
91 thread_callback_t start_routine_
;
96 FakeStack fake_stack_
;
97 AsanThreadLocalMallocStorage malloc_storage_
;
101 } // namespace __asan
103 #endif // ASAN_THREAD_H