summaryrefslogtreecommitdiff
path: root/lib/asan/asan_thread.cc
AgeCommit message (Collapse)Author
2017-12-04[ASan] Enhance libsanitizer support for invalid-pointer-pair.Alex Shlyapnikov
Following patch adds support of all memory origins in CheckForInvalidPointerPair function. For small difference of pointers, it's directly done in shadow memory (the limit was set to 2048B). Then we search for origin of first pointer and verify that the second one has the same origin. If so, we verify that it points either to a same variable (in case of stack memory or a global variable), or to a same heap segment. Committing on behanf of marxin and jakubjelinek. Reviewers: alekseyshl, kcc Subscribers: llvm-commits Differential revision: https://reviews.llvm.org/D40600 git-svn-id: https://llvm.org/svn/llvm-project/compiler-rt/trunk@319668 91177308-0d34-0410-b5e6-96231b3b80d8
2017-08-09[asan] Refactor thread creation bookkeepingVitaly Buka
Summary: This is a pure refactoring change. It paves the way for OS-specific implementations, such as Fuchsia's, that can do most of the per-thread bookkeeping work in the creator thread before the new thread actually starts. This model is simpler and cleaner, avoiding some race issues that the interceptor code for thread creation has to do for the existing OS-specific implementations. Submitted on behalf of Roland McGrath. Reviewers: vitalybuka, alekseyshl, kcc Reviewed By: alekseyshl Subscribers: phosek, filcab, llvm-commits, kubamracek Tags: #sanitizers Differential Revision: https://reviews.llvm.org/D36385 git-svn-id: https://llvm.org/svn/llvm-project/compiler-rt/trunk@310432 91177308-0d34-0410-b5e6-96231b3b80d8
2017-08-09[asan] Complete the Fuchsia portVitaly Buka
Submitted on behalf of Roland McGrath. Reviewers: kcc, eugenis, alekseyshl, vitalybuka Reviewed By: vitalybuka Subscribers: filcab, vitalybuka, srhines, kubamracek, mgorny, phosek, llvm-commits Tags: #sanitizers Differential Revision: https://reviews.llvm.org/D35865 git-svn-id: https://llvm.org/svn/llvm-project/compiler-rt/trunk@310431 91177308-0d34-0410-b5e6-96231b3b80d8
2017-07-05[asan] Remove check for stack sizeJonas Hahnfeld
This has been introduced in r304598 and fails for increased stack sizes. Differential Revision: https://reviews.llvm.org/D34876 git-svn-id: https://llvm.org/svn/llvm-project/compiler-rt/trunk@307127 91177308-0d34-0410-b5e6-96231b3b80d8
2017-06-02[asan] fix one more case where stack-use-after-return is not ↵Kostya Serebryany
async-signal-safe (during thread startup). beef-up the test to give it a chance to catch regressions. Also relax the lint to make C++11 more usable. git-svn-id: https://llvm.org/svn/llvm-project/compiler-rt/trunk@304598 91177308-0d34-0410-b5e6-96231b3b80d8
2017-04-17[sanitizer] Introduce tid_t as a typedef for OS-provided thread IDsKuba Mracek
We seem to assume that OS-provided thread IDs are either uptr or int, neither of which is true on Darwin. This introduces a tid_t type, which holds a OS-provided thread ID (gettid on Linux, pthread_threadid_np on Darwin, pthread_self on FreeBSD). Differential Revision: https://reviews.llvm.org/D31774 git-svn-id: https://llvm.org/svn/llvm-project/compiler-rt/trunk@300473 91177308-0d34-0410-b5e6-96231b3b80d8
2017-04-10[Asan] Eliminate SHADOW_TO_MEM() macroIvan A. Kosarev
Differential Revision: https://reviews.llvm.org/D31592 git-svn-id: https://llvm.org/svn/llvm-project/compiler-rt/trunk@299867 91177308-0d34-0410-b5e6-96231b3b80d8
2017-02-02[tsan] Properly describe GCD worker threads in reportsKuba Mracek
When dealing with GCD worker threads, TSan currently prints weird things like "created by thread T-1" and "[failed to restore the stack]" in reports. This patch avoids that and instead prints "Thread T3 (...) is a GCD worker thread". Differential Revision: https://reviews.llvm.org/D29103 git-svn-id: https://llvm.org/svn/llvm-project/compiler-rt/trunk@293882 91177308-0d34-0410-b5e6-96231b3b80d8
2016-09-28[ASAN] Pass previous stack information through __sanitizer_finish_switch_fiberDmitry Vyukov
This patch extends __sanitizer_finish_switch_fiber method to optionally return previous stack base and size. This solves the problem of coroutines/fibers library not knowing the original stack context from which the library is used. It's incorrect to assume that such context is always the default stack of current thread (e.g. one such library may be used from a fiber/coroutine created by another library). Bulding a separate stack tracking mechanism would not only duplicate AsanThread, but also require each coroutines/fibers library to integrate with it. Author: Andrii Grynenko (andriigrynenko) Reviewed in: https://reviews.llvm.org/D24628 git-svn-id: https://llvm.org/svn/llvm-project/compiler-rt/trunk@282582 91177308-0d34-0410-b5e6-96231b3b80d8
2016-09-07[asan] Fix a crash in GetCurrentThread() before init.Evgeniy Stepanov
Android-specific code in GetCurrentThread() does not handle the situation when there is no ThreadContext for the current thread. This happens if the current thread is requested before the main thread is added to the registry. 64-bit allocator does that to record map/unmap stats during initialization. git-svn-id: https://llvm.org/svn/llvm-project/compiler-rt/trunk@280876 91177308-0d34-0410-b5e6-96231b3b80d8
2016-06-21[asan] add primitives that allow coroutine implementationsDmitry Vyukov
This patch adds the __sanitizer_start_switch_fiber and __sanitizer_finish_switch_fiber methods inspired from what can be found here https://github.com/facebook/folly/commit/2ea64dd24946cbc9f3f4ac3f6c6b98a486c56e73 . These methods are needed when the compiled software needs to implement coroutines, fibers or the like. Without a way to annotate them, when the program jumps to a stack that is not the thread stack, __asan_handle_no_return shows a warning about that, and the fake stack mechanism may free fake frames that are still in use. Author: blastrock (Philippe Daouadi) Reviewed in http://reviews.llvm.org/D20913 git-svn-id: https://llvm.org/svn/llvm-project/compiler-rt/trunk@273260 91177308-0d34-0410-b5e6-96231b3b80d8
2016-01-14[LSan] Use __tls_get_addr interceptor to keep track of dynamic TLS.Alexey Samsonov
Summary: We have a way to keep track of allocated DTLS segments: let's use it in LSan. Although this code is fragile and relies on glibc implementation details, in some cases it proves to be better than existing way of tracking DTLS in LSan: marking as "reachable" all memory chunks allocated directly by "ld". The plan is to eventually get rid of the latter, once we are sure it's safe to remove. Reviewers: kcc Subscribers: llvm-commits Differential Revision: http://reviews.llvm.org/D16164 git-svn-id: https://llvm.org/svn/llvm-project/compiler-rt/trunk@257785 91177308-0d34-0410-b5e6-96231b3b80d8
2015-10-01[compiler-rt] Apply modernize-use-nullptr fixes in sanitizersVedant Kumar
- Trim spaces. - Use nullptr in place of 0 for pointer variables. - Use '!p' in place of 'p == 0' for null pointer checks. - Add blank lines to separate function definitions. - Add 'extern "C"' or 'namespace foo' comments after the appropriate closing brackets This is a continuation of work from 409b7b82. The focus here is on the various sanitizers (not sanitizer_common, as before). Patch by Eugene Zelenko! Differential Revision: http://reviews.llvm.org/D13225 git-svn-id: https://llvm.org/svn/llvm-project/compiler-rt/trunk@248966 91177308-0d34-0410-b5e6-96231b3b80d8
2015-07-21[asan] Remove AsanPlatformThreadInitReid Kleckner
Since the CoreFoundation allocator replacement was moved in r173134, all implementations of this function have been empty. Reviewers: samsonov Differential Revision: http://reviews.llvm.org/D11375 git-svn-id: https://llvm.org/svn/llvm-project/compiler-rt/trunk@242811 91177308-0d34-0410-b5e6-96231b3b80d8
2014-12-05[ASan] Refactor thread starting code.Sergey Matveev
Move thread context creation into AsanThread::Create(). git-svn-id: https://llvm.org/svn/llvm-project/compiler-rt/trunk@223483 91177308-0d34-0410-b5e6-96231b3b80d8
2014-12-05[ASan, LSan] Improve tracking of thread creation.Sergey Matveev
In the current scheme of things, the call to ThreadStart() in the child thread is not synchronized with the parent thread. So, if a pointer is passed to pthread_create, there may be a window of time during which this pointer will not be discoverable by LSan. I.e. the pthread_create interceptor has already returneed and thus the pointer is no longer on the parent stack, but we don't yet know the location of the child stack. This has caused bogus leak reports (see http://llvm.org/bugs/show_bug.cgi?id=21621/). This patch makes the pthread_create interceptor wait until the child thread is properly registered before returning. git-svn-id: https://llvm.org/svn/llvm-project/compiler-rt/trunk@223419 91177308-0d34-0410-b5e6-96231b3b80d8
2014-10-26Change StackDepot interface to use StackTrace more extensivelyAlexey Samsonov
git-svn-id: https://llvm.org/svn/llvm-project/compiler-rt/trunk@220637 91177308-0d34-0410-b5e6-96231b3b80d8
2014-10-01[ASan] Make stack-buffer-overflow reports more robustAlexey Samsonov
Summary: Fix the function that gets stack frame description by address in thread stack, so that it clearly indicates failures. Make this error non-fatal, and print as much information as we can in this case. Make all errors in ParseFrameDescription non-fatal. Test Plan: check-asan testsuite Reviewers: kcc Reviewed By: kcc Subscribers: llvm-commits Differential Revision: http://reviews.llvm.org/D5554 git-svn-id: https://llvm.org/svn/llvm-project/compiler-rt/trunk@218819 91177308-0d34-0410-b5e6-96231b3b80d8
2014-06-06[asan] initialize fake_stack_ to 0 before we call SetThreadStackAndTls, ↵Kostya Serebryany
because that may actually try to use fake_stack_ (still don't know how). Yet another case where we desperately want https://sourceware.org/glibc/wiki/ThreadPropertiesAPI git-svn-id: https://llvm.org/svn/llvm-project/compiler-rt/trunk@210315 91177308-0d34-0410-b5e6-96231b3b80d8
2014-05-15Fix typosAlp Toker
git-svn-id: https://llvm.org/svn/llvm-project/compiler-rt/trunk@208841 91177308-0d34-0410-b5e6-96231b3b80d8
2014-02-26Reapply r201910. MSVC gets __func__ defined explicitly, even though itJoerg Sonnenberger
can't build anything here. git-svn-id: https://llvm.org/svn/llvm-project/compiler-rt/trunk@202297 91177308-0d34-0410-b5e6-96231b3b80d8
2014-02-22Revert "Replace __FUNCTION__ with __func__, the latter being standard ↵Reid Kleckner
C99/C++11." This reverts commit r201910. While __func__ may be standard in C++11, it was only recently added to MSVC in 2013 CTP, and LLVM supports MSVC 2012. __FUNCTION__ may not be standard, but it's *very* portable. git-svn-id: https://llvm.org/svn/llvm-project/compiler-rt/trunk@201916 91177308-0d34-0410-b5e6-96231b3b80d8
2014-02-21Replace __FUNCTION__ with __func__, the latter being standard C99/C++11.Joerg Sonnenberger
git-svn-id: https://llvm.org/svn/llvm-project/compiler-rt/trunk@201910 91177308-0d34-0410-b5e6-96231b3b80d8
2014-01-29[asan] experimental intercetor for __tls_get_addr. So far it does nothing ↵Kostya Serebryany
interesting, actual usage will come later. See https://groups.google.com/forum/#!topic/address-sanitizer/BfwYD8HMxTM for background git-svn-id: https://llvm.org/svn/llvm-project/compiler-rt/trunk@200384 91177308-0d34-0410-b5e6-96231b3b80d8
2014-01-28[ASan] Move the signal handling-related flags to sanitizer_common.Alexander Potapenko
This change is a part of refactoring intended to have common signal handling behavior in all tools. git-svn-id: https://llvm.org/svn/llvm-project/compiler-rt/trunk@200295 91177308-0d34-0410-b5e6-96231b3b80d8
2013-12-16[asan] replace the flag uar_stack_size_log with two flags ↵Kostya Serebryany
min_uar_stack_size_log/max_uar_stack_size_log git-svn-id: https://llvm.org/svn/llvm-project/compiler-rt/trunk@197370 91177308-0d34-0410-b5e6-96231b3b80d8
2013-12-11[asan] if verbosity>=2, print the fake stack usage stats at thread exit; No ↵Kostya Serebryany
functionality change in non-verboze mode git-svn-id: https://llvm.org/svn/llvm-project/compiler-rt/trunk@197037 91177308-0d34-0410-b5e6-96231b3b80d8
2013-12-05[sanitizer] Introduce VReport and VPrintf macros and use them in sanitizer code.Sergey Matveev
Instead of "if (common_flags()->verbosity) Report(...)" we now have macros. git-svn-id: https://llvm.org/svn/llvm-project/compiler-rt/trunk@196497 91177308-0d34-0410-b5e6-96231b3b80d8
2013-11-27[ASan] Clarify that AsanThread objects are allocated only via mmap(). No ↵Alexey Samsonov
functionality change. git-svn-id: https://llvm.org/svn/llvm-project/compiler-rt/trunk@195840 91177308-0d34-0410-b5e6-96231b3b80d8
2013-11-13[asan] fix a leak in tds ↵Kostya Serebryany
(https://code.google.com/p/address-sanitizer/issues/detail?id=233) git-svn-id: https://llvm.org/svn/llvm-project/compiler-rt/trunk@194572 91177308-0d34-0410-b5e6-96231b3b80d8
2013-10-24Introduce an operator new for LowLevelAllocator, and convert most users to it.Peter Collingbourne
git-svn-id: https://llvm.org/svn/llvm-project/compiler-rt/trunk@193308 91177308-0d34-0410-b5e6-96231b3b80d8
2013-10-18[asan] allocate AsanThreadContext using LowLevelAllocator instead of mmap to ↵Kostya Serebryany
save space git-svn-id: https://llvm.org/svn/llvm-project/compiler-rt/trunk@192980 91177308-0d34-0410-b5e6-96231b3b80d8
2013-10-18[asan] reduce the size of AsanThreadContext by storing the stack trace in ↵Kostya Serebryany
the stack depot git-svn-id: https://llvm.org/svn/llvm-project/compiler-rt/trunk@192979 91177308-0d34-0410-b5e6-96231b3b80d8
2013-10-15tsan: move verbosity flag to CommonFlagsDmitry Vyukov
git-svn-id: https://llvm.org/svn/llvm-project/compiler-rt/trunk@192701 91177308-0d34-0410-b5e6-96231b3b80d8
2013-10-14[lsan] Support ASan's stack-use-after-return mode in LSan.Sergey Matveev
Treat the fake stack as live memory. git-svn-id: https://llvm.org/svn/llvm-project/compiler-rt/trunk@192593 91177308-0d34-0410-b5e6-96231b3b80d8
2013-10-14[asan] Improve thread lifetime tracking on POSIX systems.Sergey Matveev
Call AsanThread::Destroy() from a late-running TSD destructor. Previously we called it before any user-registered TSD destructors, which caused false positives in LeakSanitizer. git-svn-id: https://llvm.org/svn/llvm-project/compiler-rt/trunk@192585 91177308-0d34-0410-b5e6-96231b3b80d8
2013-09-27[asan] introduce run-time flag uar_stack_size_log to control the size of ↵Kostya Serebryany
FakeStack; don't crash when the fake stack is exhausted, move some code to .cc file git-svn-id: https://llvm.org/svn/llvm-project/compiler-rt/trunk@191510 91177308-0d34-0410-b5e6-96231b3b80d8
2013-09-19[asan] fix one more async-signal-safety issue with use-after-returnKostya Serebryany
git-svn-id: https://llvm.org/svn/llvm-project/compiler-rt/trunk@191004 91177308-0d34-0410-b5e6-96231b3b80d8
2013-09-18[asan] add a run-time option detect_stack_use_after_return, add verbosity ↵Kostya Serebryany
output for fake stack git-svn-id: https://llvm.org/svn/llvm-project/compiler-rt/trunk@190932 91177308-0d34-0410-b5e6-96231b3b80d8
2013-09-13[asan] second attempt to use TLS with fake stack. This time it looks (more) ↵Kostya Serebryany
async-signal safe. git-svn-id: https://llvm.org/svn/llvm-project/compiler-rt/trunk@190663 91177308-0d34-0410-b5e6-96231b3b80d8
2013-09-12[asan] (part 2) don't lazy-init fake_stack if we only need to check that ↵Kostya Serebryany
fake_stack exists (should fix 32-bit builds) git-svn-id: https://llvm.org/svn/llvm-project/compiler-rt/trunk@190594 91177308-0d34-0410-b5e6-96231b3b80d8
2013-09-12[asan] don't lazy-init fake_stack if we only need to check that fake_stack ↵Kostya Serebryany
exists (should fix 32-bit builds) git-svn-id: https://llvm.org/svn/llvm-project/compiler-rt/trunk@190593 91177308-0d34-0410-b5e6-96231b3b80d8
2013-09-12[asan] hopefully make the FakeStack async-signal safe, enable the related testKostya Serebryany
git-svn-id: https://llvm.org/svn/llvm-project/compiler-rt/trunk@190592 91177308-0d34-0410-b5e6-96231b3b80d8
2013-09-02Improve collecting malloc stats in ASanAlexey Samsonov
Summary: This change makes races between updates of thread-local stats and merging all the thread-local stats together less harmful. Reviewers: kcc Reviewed By: kcc CC: dvyukov, llvm-commits Differential Revision: http://llvm-reviews.chandlerc.com/D1572 git-svn-id: https://llvm.org/svn/llvm-project/compiler-rt/trunk@189744 91177308-0d34-0410-b5e6-96231b3b80d8
2013-07-08[lsan] Handle fork() correctly.Sergey Matveev
Update the main thread's os_id on every pthread_create, and before initiating leak checking. This ensures that we have the correct os_id even if we have forked after Init(). git-svn-id: https://llvm.org/svn/llvm-project/compiler-rt/trunk@185815 91177308-0d34-0410-b5e6-96231b3b80d8
2013-06-26[asan] initialize fake_stack lazily and increase its maximal size. This ↵Kostya Serebryany
makes -fsanitize=address,use-after-return more robust: all SPEC tests pass now. In the default mode thread stacks become a bit smaller. git-svn-id: https://llvm.org/svn/llvm-project/compiler-rt/trunk@184934 91177308-0d34-0410-b5e6-96231b3b80d8
2013-06-21[asan] Move lsan_disabled out of thread context.Sergey Matveev
Fix for the case where disabler is used in pthread key destructor. git-svn-id: https://llvm.org/svn/llvm-project/compiler-rt/trunk@184553 91177308-0d34-0410-b5e6-96231b3b80d8
2013-06-04Fix ALIGNED misuse in asan_thread.cc (built on all platforms); also, add a ↵Timur Iskhodzhanov
comment to the ALIGNED macro describing the correct usage git-svn-id: https://llvm.org/svn/llvm-project/compiler-rt/trunk@183214 91177308-0d34-0410-b5e6-96231b3b80d8
2013-06-03[asan] ASan Linux MIPS32 support (compiler-rt part), patch by Jyun-Yan YKostya Serebryany
git-svn-id: https://llvm.org/svn/llvm-project/compiler-rt/trunk@183105 91177308-0d34-0410-b5e6-96231b3b80d8
2013-06-03[lsan] Add __lsan_disable() and __lsan_enable().Sergey Matveev
Objects allocated after a call to __lsan_disable() will be treated as live memory. Also add a ScopedDisabler. git-svn-id: https://llvm.org/svn/llvm-project/compiler-rt/trunk@183099 91177308-0d34-0410-b5e6-96231b3b80d8