Alexey Samsonov | e5f5895 | 2012-06-04 13:50:10 +0000 | [diff] [blame] | 1 | //===-- asan_thread.cc ----------------------------------------------------===// |
Kostya Serebryany | 1e172b4 | 2011-11-30 01:07:02 +0000 | [diff] [blame] | 2 | // |
| 3 | // The LLVM Compiler Infrastructure |
| 4 | // |
| 5 | // This file is distributed under the University of Illinois Open Source |
| 6 | // License. See LICENSE.TXT for details. |
| 7 | // |
| 8 | //===----------------------------------------------------------------------===// |
| 9 | // |
| 10 | // This file is a part of AddressSanitizer, an address sanity checker. |
| 11 | // |
| 12 | // Thread-related code. |
| 13 | //===----------------------------------------------------------------------===// |
| 14 | #include "asan_allocator.h" |
| 15 | #include "asan_interceptors.h" |
Alexey Samsonov | 7e84349 | 2013-03-28 15:42:43 +0000 | [diff] [blame] | 16 | #include "asan_poisoning.h" |
Alexey Samsonov | 55cdfc6 | 2012-01-17 06:35:31 +0000 | [diff] [blame] | 17 | #include "asan_stack.h" |
Kostya Serebryany | 1e172b4 | 2011-11-30 01:07:02 +0000 | [diff] [blame] | 18 | #include "asan_thread.h" |
Kostya Serebryany | 1e172b4 | 2011-11-30 01:07:02 +0000 | [diff] [blame] | 19 | #include "asan_mapping.h" |
Alexey Samsonov | e5931fd | 2012-06-07 07:13:46 +0000 | [diff] [blame] | 20 | #include "sanitizer_common/sanitizer_common.h" |
Alexey Samsonov | def1be9 | 2013-03-21 11:23:41 +0000 | [diff] [blame] | 21 | #include "sanitizer_common/sanitizer_placement_new.h" |
Sergey Matveev | f1ac1a4 | 2013-05-21 13:40:13 +0000 | [diff] [blame] | 22 | #include "lsan/lsan_common.h" |
Kostya Serebryany | 1e172b4 | 2011-11-30 01:07:02 +0000 | [diff] [blame] | 23 | |
Kostya Serebryany | 1e172b4 | 2011-11-30 01:07:02 +0000 | [diff] [blame] | 24 | namespace __asan { |
| 25 | |
Alexey Samsonov | def1be9 | 2013-03-21 11:23:41 +0000 | [diff] [blame] | 26 | // AsanThreadContext implementation. |
Kostya Serebryany | 1e172b4 | 2011-11-30 01:07:02 +0000 | [diff] [blame] | 27 | |
Alexey Samsonov | def1be9 | 2013-03-21 11:23:41 +0000 | [diff] [blame] | 28 | void AsanThreadContext::OnCreated(void *arg) { |
| 29 | CreateThreadContextArgs *args = static_cast<CreateThreadContextArgs*>(arg); |
| 30 | if (args->stack) { |
| 31 | internal_memcpy(&stack, args->stack, sizeof(stack)); |
| 32 | } |
| 33 | thread = args->thread; |
| 34 | thread->set_context(this); |
| 35 | } |
| 36 | |
| 37 | void AsanThreadContext::OnFinished() { |
| 38 | // Drop the link to the AsanThread object. |
| 39 | thread = 0; |
| 40 | } |
| 41 | |
| 42 | static char thread_registry_placeholder[sizeof(ThreadRegistry)]; |
| 43 | static ThreadRegistry *asan_thread_registry; |
| 44 | |
| 45 | static ThreadContextBase *GetAsanThreadContext(u32 tid) { |
| 46 | void *mem = MmapOrDie(sizeof(AsanThreadContext), "AsanThreadContext"); |
| 47 | return new(mem) AsanThreadContext(tid); |
| 48 | } |
| 49 | |
| 50 | ThreadRegistry &asanThreadRegistry() { |
| 51 | static bool initialized; |
| 52 | // Don't worry about thread_safety - this should be called when there is |
| 53 | // a single thread. |
| 54 | if (!initialized) { |
| 55 | // Never reuse ASan threads: we store pointer to AsanThreadContext |
| 56 | // in TSD and can't reliably tell when no more TSD destructors will |
| 57 | // be called. It would be wrong to reuse AsanThreadContext for another |
| 58 | // thread before all TSD destructors will be called for it. |
| 59 | asan_thread_registry = new(thread_registry_placeholder) ThreadRegistry( |
| 60 | GetAsanThreadContext, kMaxNumberOfThreads, kMaxNumberOfThreads); |
| 61 | initialized = true; |
| 62 | } |
| 63 | return *asan_thread_registry; |
| 64 | } |
| 65 | |
| 66 | AsanThreadContext *GetThreadContextByTidLocked(u32 tid) { |
| 67 | return static_cast<AsanThreadContext *>( |
| 68 | asanThreadRegistry().GetThreadLocked(tid)); |
| 69 | } |
| 70 | |
| 71 | // AsanThread implementation. |
| 72 | |
| 73 | AsanThread *AsanThread::Create(thread_callback_t start_routine, |
| 74 | void *arg) { |
Kostya Serebryany | f67ec2b | 2012-11-23 15:38:49 +0000 | [diff] [blame] | 75 | uptr PageSize = GetPageSizeCached(); |
| 76 | uptr size = RoundUpTo(sizeof(AsanThread), PageSize); |
Alexey Samsonov | a25b346 | 2012-06-06 16:15:07 +0000 | [diff] [blame] | 77 | AsanThread *thread = (AsanThread*)MmapOrDie(size, __FUNCTION__); |
Alexey Samsonov | 55cdfc6 | 2012-01-17 06:35:31 +0000 | [diff] [blame] | 78 | thread->start_routine_ = start_routine; |
| 79 | thread->arg_ = arg; |
Alexey Samsonov | def1be9 | 2013-03-21 11:23:41 +0000 | [diff] [blame] | 80 | thread->context_ = 0; |
Alexey Samsonov | 55cdfc6 | 2012-01-17 06:35:31 +0000 | [diff] [blame] | 81 | |
| 82 | return thread; |
Kostya Serebryany | 1e172b4 | 2011-11-30 01:07:02 +0000 | [diff] [blame] | 83 | } |
| 84 | |
Alexey Samsonov | def1be9 | 2013-03-21 11:23:41 +0000 | [diff] [blame] | 85 | void AsanThread::TSDDtor(void *tsd) { |
| 86 | AsanThreadContext *context = (AsanThreadContext*)tsd; |
| 87 | if (flags()->verbosity >= 1) |
| 88 | Report("T%d TSDDtor\n", context->tid); |
| 89 | if (context->thread) |
| 90 | context->thread->Destroy(); |
Kostya Serebryany | f58f998 | 2012-02-07 00:27:15 +0000 | [diff] [blame] | 91 | } |
| 92 | |
Kostya Serebryany | a6b5226 | 2012-01-06 19:44:11 +0000 | [diff] [blame] | 93 | void AsanThread::Destroy() { |
Alexey Samsonov | cb8c4dc | 2012-07-09 14:36:04 +0000 | [diff] [blame] | 94 | if (flags()->verbosity >= 1) { |
Kostya Serebryany | f58f998 | 2012-02-07 00:27:15 +0000 | [diff] [blame] | 95 | Report("T%d exited\n", tid()); |
| 96 | } |
| 97 | |
Alexey Samsonov | def1be9 | 2013-03-21 11:23:41 +0000 | [diff] [blame] | 98 | asanThreadRegistry().FinishThread(tid()); |
| 99 | FlushToAccumulatedStats(&stats_); |
Kostya Serebryany | 1e172b4 | 2011-11-30 01:07:02 +0000 | [diff] [blame] | 100 | // We also clear the shadow on thread destruction because |
| 101 | // some code may still be executing in later TSD destructors |
| 102 | // and we don't want it to have any poisoned stack. |
Sergey Matveev | 12d01ba | 2013-05-29 13:09:44 +0000 | [diff] [blame^] | 103 | ClearShadowForThreadStackAndTLS(); |
Alexey Samsonov | 55cdfc6 | 2012-01-17 06:35:31 +0000 | [diff] [blame] | 104 | fake_stack().Cleanup(); |
Kostya Serebryany | f67ec2b | 2012-11-23 15:38:49 +0000 | [diff] [blame] | 105 | uptr size = RoundUpTo(sizeof(AsanThread), GetPageSizeCached()); |
Alexey Samsonov | a25b346 | 2012-06-06 16:15:07 +0000 | [diff] [blame] | 106 | UnmapOrDie(this, size); |
Kostya Serebryany | 1e172b4 | 2011-11-30 01:07:02 +0000 | [diff] [blame] | 107 | } |
| 108 | |
Kostya Serebryany | 69eca73 | 2011-12-16 19:13:35 +0000 | [diff] [blame] | 109 | void AsanThread::Init() { |
Sergey Matveev | 12d01ba | 2013-05-29 13:09:44 +0000 | [diff] [blame^] | 110 | SetThreadStackAndTls(); |
Alexey Samsonov | 55cdfc6 | 2012-01-17 06:35:31 +0000 | [diff] [blame] | 111 | CHECK(AddrIsInMem(stack_bottom_)); |
Kostya Serebryany | 541cfb1 | 2013-01-18 11:30:36 +0000 | [diff] [blame] | 112 | CHECK(AddrIsInMem(stack_top_ - 1)); |
Sergey Matveev | 12d01ba | 2013-05-29 13:09:44 +0000 | [diff] [blame^] | 113 | ClearShadowForThreadStackAndTLS(); |
Alexey Samsonov | cb8c4dc | 2012-07-09 14:36:04 +0000 | [diff] [blame] | 114 | if (flags()->verbosity >= 1) { |
Kostya Serebryany | 1e172b4 | 2011-11-30 01:07:02 +0000 | [diff] [blame] | 115 | int local = 0; |
Evgeniy Stepanov | 739eb79 | 2012-03-21 11:32:46 +0000 | [diff] [blame] | 116 | Report("T%d: stack [%p,%p) size 0x%zx; local=%p\n", |
Alexey Samsonov | 5bcca4e | 2012-06-06 10:46:00 +0000 | [diff] [blame] | 117 | tid(), (void*)stack_bottom_, (void*)stack_top_, |
Kostya Serebryany | a7e760a | 2012-01-09 19:18:27 +0000 | [diff] [blame] | 118 | stack_top_ - stack_bottom_, &local); |
Kostya Serebryany | 1e172b4 | 2011-11-30 01:07:02 +0000 | [diff] [blame] | 119 | } |
Alexey Samsonov | 55cdfc6 | 2012-01-17 06:35:31 +0000 | [diff] [blame] | 120 | fake_stack_.Init(stack_size()); |
Alexander Potapenko | 75b19eb | 2012-07-23 14:07:58 +0000 | [diff] [blame] | 121 | AsanPlatformThreadInit(); |
Kostya Serebryany | 69eca73 | 2011-12-16 19:13:35 +0000 | [diff] [blame] | 122 | } |
| 123 | |
Alexey Samsonov | def1be9 | 2013-03-21 11:23:41 +0000 | [diff] [blame] | 124 | thread_return_t AsanThread::ThreadStart(uptr os_id) { |
Kostya Serebryany | 69eca73 | 2011-12-16 19:13:35 +0000 | [diff] [blame] | 125 | Init(); |
Alexey Samsonov | def1be9 | 2013-03-21 11:23:41 +0000 | [diff] [blame] | 126 | asanThreadRegistry().StartThread(tid(), os_id, 0); |
Alexey Samsonov | cb8c4dc | 2012-07-09 14:36:04 +0000 | [diff] [blame] | 127 | if (flags()->use_sigaltstack) SetAlternateSignalStack(); |
Kostya Serebryany | 1e172b4 | 2011-11-30 01:07:02 +0000 | [diff] [blame] | 128 | |
| 129 | if (!start_routine_) { |
Kostya Serebryany | 3f4c387 | 2012-05-31 14:35:53 +0000 | [diff] [blame] | 130 | // start_routine_ == 0 if we're on the main thread or on one of the |
Kostya Serebryany | 1e172b4 | 2011-11-30 01:07:02 +0000 | [diff] [blame] | 131 | // OS X libdispatch worker threads. But nobody is supposed to call |
| 132 | // ThreadStart() for the worker threads. |
Kostya Serebryany | a27bdf7 | 2013-04-05 14:40:25 +0000 | [diff] [blame] | 133 | CHECK_EQ(tid(), 0); |
Kostya Serebryany | 1e172b4 | 2011-11-30 01:07:02 +0000 | [diff] [blame] | 134 | return 0; |
| 135 | } |
| 136 | |
Timur Iskhodzhanov | 600972e | 2012-02-24 15:28:43 +0000 | [diff] [blame] | 137 | thread_return_t res = start_routine_(arg_); |
Kostya Serebryany | 1e172b4 | 2011-11-30 01:07:02 +0000 | [diff] [blame] | 138 | malloc_storage().CommitBack(); |
Alexey Samsonov | cb8c4dc | 2012-07-09 14:36:04 +0000 | [diff] [blame] | 139 | if (flags()->use_sigaltstack) UnsetAlternateSignalStack(); |
Kostya Serebryany | 1e172b4 | 2011-11-30 01:07:02 +0000 | [diff] [blame] | 140 | |
Kostya Serebryany | af34415 | 2012-01-11 02:03:16 +0000 | [diff] [blame] | 141 | this->Destroy(); |
| 142 | |
Kostya Serebryany | 1e172b4 | 2011-11-30 01:07:02 +0000 | [diff] [blame] | 143 | return res; |
| 144 | } |
| 145 | |
Sergey Matveev | 12d01ba | 2013-05-29 13:09:44 +0000 | [diff] [blame^] | 146 | void AsanThread::SetThreadStackAndTls() { |
| 147 | uptr stack_size = 0, tls_size = 0; |
| 148 | GetThreadStackAndTls(tid() == 0, &stack_bottom_, &stack_size, &tls_begin_, |
| 149 | &tls_size); |
| 150 | stack_top_ = stack_bottom_ + stack_size; |
| 151 | tls_end_ = tls_begin_ + tls_size; |
| 152 | |
Alexey Samsonov | e5931fd | 2012-06-07 07:13:46 +0000 | [diff] [blame] | 153 | int local; |
| 154 | CHECK(AddrIsInStack((uptr)&local)); |
| 155 | } |
| 156 | |
Sergey Matveev | 12d01ba | 2013-05-29 13:09:44 +0000 | [diff] [blame^] | 157 | void AsanThread::ClearShadowForThreadStackAndTLS() { |
Alexey Samsonov | 55cdfc6 | 2012-01-17 06:35:31 +0000 | [diff] [blame] | 158 | PoisonShadow(stack_bottom_, stack_top_ - stack_bottom_, 0); |
Sergey Matveev | 12d01ba | 2013-05-29 13:09:44 +0000 | [diff] [blame^] | 159 | if (tls_begin_ != tls_end_) |
| 160 | PoisonShadow(tls_begin_, tls_end_ - tls_begin_, 0); |
Alexey Samsonov | 55cdfc6 | 2012-01-17 06:35:31 +0000 | [diff] [blame] | 161 | } |
| 162 | |
Kostya Serebryany | 50f3daa | 2013-03-22 10:36:24 +0000 | [diff] [blame] | 163 | const char *AsanThread::GetFrameNameByAddr(uptr addr, uptr *offset, |
| 164 | uptr *frame_pc) { |
Kostya Serebryany | 3f4c387 | 2012-05-31 14:35:53 +0000 | [diff] [blame] | 165 | uptr bottom = 0; |
Kostya Serebryany | 1e172b4 | 2011-11-30 01:07:02 +0000 | [diff] [blame] | 166 | if (AddrIsInStack(addr)) { |
| 167 | bottom = stack_bottom(); |
| 168 | } else { |
| 169 | bottom = fake_stack().AddrIsInFakeStack(addr); |
| 170 | CHECK(bottom); |
Alexander Potapenko | e406c8c | 2012-11-15 15:24:42 +0000 | [diff] [blame] | 171 | *offset = addr - bottom; |
Kostya Serebryany | 50f3daa | 2013-03-22 10:36:24 +0000 | [diff] [blame] | 172 | *frame_pc = ((uptr*)bottom)[2]; |
Alexander Potapenko | e406c8c | 2012-11-15 15:24:42 +0000 | [diff] [blame] | 173 | return (const char *)((uptr*)bottom)[1]; |
Kostya Serebryany | 1e172b4 | 2011-11-30 01:07:02 +0000 | [diff] [blame] | 174 | } |
Kostya Serebryany | 5af39e5 | 2012-11-21 12:38:58 +0000 | [diff] [blame] | 175 | uptr aligned_addr = addr & ~(SANITIZER_WORDSIZE/8 - 1); // align addr. |
Kostya Serebryany | ee39255 | 2012-05-31 15:02:07 +0000 | [diff] [blame] | 176 | u8 *shadow_ptr = (u8*)MemToShadow(aligned_addr); |
| 177 | u8 *shadow_bottom = (u8*)MemToShadow(bottom); |
Evgeniy Stepanov | 3972ea0 | 2012-05-12 12:33:10 +0000 | [diff] [blame] | 178 | |
| 179 | while (shadow_ptr >= shadow_bottom && |
Alexander Potapenko | e406c8c | 2012-11-15 15:24:42 +0000 | [diff] [blame] | 180 | *shadow_ptr != kAsanStackLeftRedzoneMagic) { |
Evgeniy Stepanov | 3972ea0 | 2012-05-12 12:33:10 +0000 | [diff] [blame] | 181 | shadow_ptr--; |
Kostya Serebryany | 1e172b4 | 2011-11-30 01:07:02 +0000 | [diff] [blame] | 182 | } |
Evgeniy Stepanov | 3972ea0 | 2012-05-12 12:33:10 +0000 | [diff] [blame] | 183 | |
| 184 | while (shadow_ptr >= shadow_bottom && |
Alexander Potapenko | e406c8c | 2012-11-15 15:24:42 +0000 | [diff] [blame] | 185 | *shadow_ptr == kAsanStackLeftRedzoneMagic) { |
Evgeniy Stepanov | 3972ea0 | 2012-05-12 12:33:10 +0000 | [diff] [blame] | 186 | shadow_ptr--; |
| 187 | } |
| 188 | |
| 189 | if (shadow_ptr < shadow_bottom) { |
Alexander Potapenko | e406c8c | 2012-11-15 15:24:42 +0000 | [diff] [blame] | 190 | *offset = 0; |
| 191 | return "UNKNOWN"; |
Evgeniy Stepanov | 3972ea0 | 2012-05-12 12:33:10 +0000 | [diff] [blame] | 192 | } |
| 193 | |
Kostya Serebryany | 3f4c387 | 2012-05-31 14:35:53 +0000 | [diff] [blame] | 194 | uptr* ptr = (uptr*)SHADOW_TO_MEM((uptr)(shadow_ptr + 1)); |
Alexander Potapenko | e406c8c | 2012-11-15 15:24:42 +0000 | [diff] [blame] | 195 | CHECK(ptr[0] == kCurrentStackFrameMagic); |
Kostya Serebryany | 3f4c387 | 2012-05-31 14:35:53 +0000 | [diff] [blame] | 196 | *offset = addr - (uptr)ptr; |
Kostya Serebryany | 50f3daa | 2013-03-22 10:36:24 +0000 | [diff] [blame] | 197 | *frame_pc = ptr[2]; |
Evgeniy Stepanov | 3972ea0 | 2012-05-12 12:33:10 +0000 | [diff] [blame] | 198 | return (const char*)ptr[1]; |
Kostya Serebryany | 1e172b4 | 2011-11-30 01:07:02 +0000 | [diff] [blame] | 199 | } |
| 200 | |
Alexey Samsonov | def1be9 | 2013-03-21 11:23:41 +0000 | [diff] [blame] | 201 | static bool ThreadStackContainsAddress(ThreadContextBase *tctx_base, |
| 202 | void *addr) { |
| 203 | AsanThreadContext *tctx = static_cast<AsanThreadContext*>(tctx_base); |
| 204 | AsanThread *t = tctx->thread; |
| 205 | return (t && t->fake_stack().StackSize() && |
| 206 | (t->fake_stack().AddrIsInFakeStack((uptr)addr) || |
| 207 | t->AddrIsInStack((uptr)addr))); |
| 208 | } |
| 209 | |
Alexey Samsonov | 89c1384 | 2013-03-20 09:23:28 +0000 | [diff] [blame] | 210 | AsanThread *GetCurrentThread() { |
Alexey Samsonov | def1be9 | 2013-03-21 11:23:41 +0000 | [diff] [blame] | 211 | AsanThreadContext *context = (AsanThreadContext*)AsanTSDGet(); |
| 212 | if (!context) { |
| 213 | if (SANITIZER_ANDROID) { |
| 214 | // On Android, libc constructor is called _after_ asan_init, and cleans up |
| 215 | // TSD. Try to figure out if this is still the main thread by the stack |
| 216 | // address. We are not entirely sure that we have correct main thread |
Dmitry Vyukov | 195369b | 2013-03-22 07:29:59 +0000 | [diff] [blame] | 217 | // limits, so only do this magic on Android, and only if the found thread |
| 218 | // is the main thread. |
Alexey Samsonov | def1be9 | 2013-03-21 11:23:41 +0000 | [diff] [blame] | 219 | AsanThreadContext *tctx = GetThreadContextByTidLocked(0); |
| 220 | if (ThreadStackContainsAddress(tctx, &context)) { |
| 221 | SetCurrentThread(tctx->thread); |
| 222 | return tctx->thread; |
| 223 | } |
Alexey Samsonov | 89c1384 | 2013-03-20 09:23:28 +0000 | [diff] [blame] | 224 | } |
Alexey Samsonov | 89c1384 | 2013-03-20 09:23:28 +0000 | [diff] [blame] | 225 | return 0; |
| 226 | } |
Alexey Samsonov | def1be9 | 2013-03-21 11:23:41 +0000 | [diff] [blame] | 227 | return context->thread; |
Alexey Samsonov | 89c1384 | 2013-03-20 09:23:28 +0000 | [diff] [blame] | 228 | } |
| 229 | |
| 230 | void SetCurrentThread(AsanThread *t) { |
Alexey Samsonov | def1be9 | 2013-03-21 11:23:41 +0000 | [diff] [blame] | 231 | CHECK(t->context()); |
Alexey Samsonov | 89c1384 | 2013-03-20 09:23:28 +0000 | [diff] [blame] | 232 | if (flags()->verbosity >= 2) { |
| 233 | Report("SetCurrentThread: %p for thread %p\n", |
Alexey Samsonov | def1be9 | 2013-03-21 11:23:41 +0000 | [diff] [blame] | 234 | t->context(), (void*)GetThreadSelf()); |
Alexey Samsonov | 89c1384 | 2013-03-20 09:23:28 +0000 | [diff] [blame] | 235 | } |
| 236 | // Make sure we do not reset the current AsanThread. |
Alexey Samsonov | def1be9 | 2013-03-21 11:23:41 +0000 | [diff] [blame] | 237 | CHECK_EQ(0, AsanTSDGet()); |
| 238 | AsanTSDSet(t->context()); |
| 239 | CHECK_EQ(t->context(), AsanTSDGet()); |
Alexey Samsonov | 89c1384 | 2013-03-20 09:23:28 +0000 | [diff] [blame] | 240 | } |
| 241 | |
| 242 | u32 GetCurrentTidOrInvalid() { |
| 243 | AsanThread *t = GetCurrentThread(); |
| 244 | return t ? t->tid() : kInvalidTid; |
| 245 | } |
| 246 | |
Alexey Samsonov | def1be9 | 2013-03-21 11:23:41 +0000 | [diff] [blame] | 247 | AsanThread *FindThreadByStackAddress(uptr addr) { |
| 248 | asanThreadRegistry().CheckLocked(); |
| 249 | AsanThreadContext *tctx = static_cast<AsanThreadContext *>( |
| 250 | asanThreadRegistry().FindThreadContextLocked(ThreadStackContainsAddress, |
| 251 | (void *)addr)); |
| 252 | return tctx ? tctx->thread : 0; |
| 253 | } |
Kostya Serebryany | 1e172b4 | 2011-11-30 01:07:02 +0000 | [diff] [blame] | 254 | } // namespace __asan |
Sergey Matveev | f1ac1a4 | 2013-05-21 13:40:13 +0000 | [diff] [blame] | 255 | |
| 256 | // --- Implementation of LSan-specific functions --- {{{1 |
| 257 | namespace __lsan { |
| 258 | bool GetThreadRangesLocked(uptr os_id, uptr *stack_begin, uptr *stack_end, |
| 259 | uptr *tls_begin, uptr *tls_end, |
| 260 | uptr *cache_begin, uptr *cache_end) { |
Sergey Matveev | 12d01ba | 2013-05-29 13:09:44 +0000 | [diff] [blame^] | 261 | __asan::AsanThreadContext *context = static_cast<__asan::AsanThreadContext *>( |
| 262 | __asan::asanThreadRegistry().FindThreadContextByOsIDLocked(os_id)); |
| 263 | if (!context) return false; |
| 264 | __asan::AsanThread *t = context->thread; |
| 265 | if (!t) return false; |
| 266 | *stack_begin = t->stack_bottom(); |
| 267 | *stack_end = t->stack_top(); |
| 268 | *tls_begin = t->tls_begin(); |
| 269 | *tls_end = t->tls_end(); |
| 270 | // ASan doesn't keep allocator caches in TLS, so these are unused. |
| 271 | *cache_begin = 0; |
| 272 | *cache_end = 0; |
| 273 | return true; |
Sergey Matveev | f1ac1a4 | 2013-05-21 13:40:13 +0000 | [diff] [blame] | 274 | } |
| 275 | |
| 276 | void LockThreadRegistry() { |
| 277 | __asan::asanThreadRegistry().Lock(); |
| 278 | } |
| 279 | |
| 280 | void UnlockThreadRegistry() { |
| 281 | __asan::asanThreadRegistry().Unlock(); |
| 282 | } |
| 283 | } // namespace __lsan |