summaryrefslogtreecommitdiff
path: root/lib/asan/asan_thread.h
diff options
context:
space:
mode:
Diffstat (limited to 'lib/asan/asan_thread.h')
-rw-r--r--lib/asan/asan_thread.h52
1 files changed, 27 insertions, 25 deletions
diff --git a/lib/asan/asan_thread.h b/lib/asan/asan_thread.h
index c382c85a6a3c..9a032fe3e66c 100644
--- a/lib/asan/asan_thread.h
+++ b/lib/asan/asan_thread.h
@@ -18,10 +18,11 @@
#include "asan_internal.h"
#include "asan_stack.h"
#include "asan_stats.h"
+#include "sanitizer_common/sanitizer_libc.h"
namespace __asan {
-const size_t kMaxThreadStackSize = 16 * (1 << 20); // 16M
+const u32 kInvalidTid = 0xffffff; // Must fit into 24 bits.
class AsanThread;
@@ -30,12 +31,12 @@ class AsanThread;
class AsanThreadSummary {
public:
explicit AsanThreadSummary(LinkerInitialized) { } // for T0.
- AsanThreadSummary(int tid, int parent_tid, AsanStackTrace *stack)
- : tid_(tid),
- parent_tid_(parent_tid),
- announced_(false) {
+ void Init(u32 parent_tid, AsanStackTrace *stack) {
+ parent_tid_ = parent_tid;
+ announced_ = false;
+ tid_ = kInvalidTid;
if (stack) {
- stack_ = *stack;
+ internal_memcpy(&stack_, stack, sizeof(*stack));
}
thread_ = 0;
}
@@ -43,16 +44,19 @@ class AsanThreadSummary {
if (tid_ == 0) return; // no need to announce the main thread.
if (!announced_) {
announced_ = true;
- Printf("Thread T%d created by T%d here:\n", tid_, parent_tid_);
+ AsanPrintf("Thread T%d created by T%d here:\n", tid_, parent_tid_);
stack_.PrintStack();
}
}
- int tid() { return tid_; }
+ u32 tid() { return tid_; }
+ void set_tid(u32 tid) { tid_ = tid; }
AsanThread *thread() { return thread_; }
void set_thread(AsanThread *thread) { thread_ = thread; }
+ static void TSDDtor(void *tsd);
+
private:
- int tid_;
- int parent_tid_;
+ u32 tid_;
+ u32 parent_tid_;
bool announced_;
AsanStackTrace stack_;
AsanThread *thread_;
@@ -62,23 +66,23 @@ class AsanThreadSummary {
class AsanThread {
public:
explicit AsanThread(LinkerInitialized); // for T0.
- AsanThread(int parent_tid, void *(*start_routine) (void *),
- void *arg, AsanStackTrace *stack);
- ~AsanThread();
+ static AsanThread *Create(u32 parent_tid, thread_callback_t start_routine,
+ void *arg, AsanStackTrace *stack);
+ void Destroy();
void Init(); // Should be called from the thread itself.
- void *ThreadStart();
+ thread_return_t ThreadStart();
- uintptr_t stack_top() { return stack_top_; }
- uintptr_t stack_bottom() { return stack_bottom_; }
- size_t stack_size() { return stack_top_ - stack_bottom_; }
- int tid() { return summary_->tid(); }
+ uptr stack_top() { return stack_top_; }
+ uptr stack_bottom() { return stack_bottom_; }
+ uptr stack_size() { return stack_top_ - stack_bottom_; }
+ u32 tid() { return summary_->tid(); }
AsanThreadSummary *summary() { return summary_; }
void set_summary(AsanThreadSummary *summary) { summary_ = summary; }
- const char *GetFrameNameByAddr(uintptr_t addr, uintptr_t *offset);
+ const char *GetFrameNameByAddr(uptr addr, uptr *offset);
- bool AddrIsInStack(uintptr_t addr) {
+ bool AddrIsInStack(uptr addr) {
return addr >= stack_bottom_ && addr < stack_top_;
}
@@ -86,17 +90,15 @@ class AsanThread {
AsanThreadLocalMallocStorage &malloc_storage() { return malloc_storage_; }
AsanStats &stats() { return stats_; }
- static const int kInvalidTid = -1;
-
private:
void SetThreadStackTopAndBottom();
void ClearShadowForThreadStack();
AsanThreadSummary *summary_;
- void *(*start_routine_) (void *param);
+ thread_callback_t start_routine_;
void *arg_;
- uintptr_t stack_top_;
- uintptr_t stack_bottom_;
+ uptr stack_top_;
+ uptr stack_bottom_;
FakeStack fake_stack_;
AsanThreadLocalMallocStorage malloc_storage_;