27 Commits

Author SHA1 Message Date
Vitaly Buka
fa81868fe6
[lsan] Log thread history (#111949)
Only with high verbosity and leak reports, or thread logging requested.
2024-10-11 18:09:37 -07:00
Fangrui Song
ba66d60b1c
[sanitizer] Replace ALIGNED with alignas
C++11 `alignas` is already used extensively. `alignas` must precede
`static`, so adjust the ordering accordingly.

msan.cpp: Clang 15 doesn't allow `__attribute__((visibility("default"))) alignas(16)`.
Use the order `alignas(16) SANITIZER_INTERFACE_ATTRIBUTE`. Tested with Clang 7.

Pull Request: https://github.com/llvm/llvm-project/pull/98958
2024-07-15 16:12:42 -07:00
Vitaly Buka
07edc1c16f [NFC][sanitizer] Rename *ThreadRegistry functions
Reviewed By: thurston

Differential Revision: https://reviews.llvm.org/D150407
2023-05-24 18:34:14 -07:00
Vitaly Buka
c46bc0d3e7 [lsan] Fix allocator_interface implementation
__sanitizer_get_current_allocated_bytes had as body, but allocator
caches were not registered to collect stats. It's done by
SizeClassAllocator64LocalCache::Init().

Reviewed By: thurston

Differential Revision: https://reviews.llvm.org/D151355
2023-05-24 13:27:23 -07:00
Vitaly Buka
3cabfe666c [LSAN] Use ThreadArgRetval in LSAN
Fixes false leaks on thread retval.

Reviewed By: thurston

Differential Revision: https://reviews.llvm.org/D150165
2023-05-18 01:11:54 -07:00
Vitaly Buka
d2b434b4e9 Revert "[LSAN] Use ThreadArgRetval in LSAN"
https://bugs.chromium.org/p/chromium/issues/detail?id=1445676

This reverts commit 20a3c6e84e0955ac20762c35e8c2435017ae967d.
2023-05-16 10:49:45 -07:00
Vitaly Buka
20a3c6e84e [LSAN] Use ThreadArgRetval in LSAN
Fixes false leaks on thread retval.

Reviewed By: thurston

Differential Revision: https://reviews.llvm.org/D150165
2023-05-11 15:58:04 -07:00
Vitaly Buka
b5eb55d19d [NFC][LSAN] Move GetAdditionalThreadContextPtrsLocked 2023-05-08 12:44:13 -07:00
Vitaly Buka
437b7602e4 [NFC][lsan] Use LowLevelAllocator to allocate ThreadContext
This is more RAM and CPU efficient than allocating entire page per
context, and this approach is used by other sanitizers already.

With the patch "create_thread_loop2.cpp.tmp 5000" is 30% faster.
2023-04-17 20:05:26 -07:00
Vitaly Buka
7760272778 [lsan] Don't crash on ThreadRegistry::threads_ data race
Comment "No lock needed" in CurrentThreadContext was wrong.
Concurent ThreadRegistry::CreateThread can resize and relocate
ThreadRegistry::threads_ the same time CurrentThreadContext reads it.

To mitigate lock cost we store ThreadContext* instead of tid in
THREADLOCAL cache, we can tid from the ThreadContext*.

Reviewed By: kstoimenov, MaskRay

Differential Revision: https://reviews.llvm.org/D148281
2023-04-17 15:33:43 -07:00
Vitaly Buka
02eb818f64 [NFC][lsan] Add GetCurrentThreadId wrapper for GetCurrentThread
I am going to change return type of GetCurrentThreadId() in the next
patch.

Differential Revision: https://reviews.llvm.org/D148394
2023-04-14 23:02:15 -07:00
Vitaly Buka
e3b378fad9 [NFC][lsan] Move SetCurrentThread call
Future patch will set the current context as well.
Existing callsite requires additional lock to find context.

Differential Revision: https://reviews.llvm.org/D148390
2023-04-14 16:28:13 -07:00
Kirill Stoimenov
af210ee506 [LSAN][Fuchsia] Added ForEachExtraThreadStackRange to support Fuchsia code.
Reviewed By: vitalybuka

Differential Revision: https://reviews.llvm.org/D141724
2023-01-13 21:20:41 -08:00
Kirill Stoimenov
c184423e70 [LSAN] More LSAN interface tweaking.
Main goal is to remove thread registry dependency from the interface because HWASAN is using its own code to manage threads.

Reviewed By: vitalybuka, kstoimenov

Differential Revision: https://reviews.llvm.org/D140039
2023-01-12 17:58:11 -08:00
Vitaly Buka
eb2db81eba Revert "[LSAN] More LSAN interface tweaking."
Breaks bots.
Also it's missing changes we discussed on review.

This reverts commit f001e50f955c3cdf2deb79e38a9fd19c9a781882.
This reverts commit 2924189233fdb724453ead4b94595107b1ce9cfa.
2023-01-12 17:32:40 -08:00
Kirill Stoimenov
2924189233 [LSAN] More LSAN interface tweaking.
Main goal is to remove thread registry dependency from the interface because HWASAN is using its own code to manage threads.

Reviewed By: vitalybuka, kstoimenov

Differential Revision: https://reviews.llvm.org/D140039
2023-01-12 23:44:08 +00:00
Kirill Stoimenov
f547c173f2 [LSAN][NFC] Removed FinishThreadLocked from the LSAN interface.
It is only used in the LSAN specific part.

Reviewed By: vitalybuka

Differential Revision: https://reviews.llvm.org/D140109
2023-01-06 00:28:40 +00:00
Kirill Stoimenov
e43e0ffbe7 [LSAN][NFC] Eliminated GetThreadRegistryLocked from the LSAN interface to avoid the need to implement it in HWASAN.
Reviewed By: vitalybuka

Differential Revision: https://reviews.llvm.org/D139976
2022-12-14 00:15:40 +00:00
Dmitry Vyukov
033b94ab52 lsan: remove pthread_detach/join interceptors
They don't seem to do anything useful in lsan.
They are needed only if a tools needs to execute
some custom logic during detach/join, or if it uses
thread registry quarantine. Lsan does none of this.
And if a tool cares then it would also need to intercept
pthread_tryjoin_np and pthread_timedjoin_np, otherwise
it will mess thread states.
Fwiw, asan does not intercept these functions either.

Reviewed By: vitalybuka

Differential Revision: https://reviews.llvm.org/D113920
2021-11-17 14:49:15 +01:00
Dmitry Vyukov
dfd9808b6c sanitizer_common: add simpler ThreadRegistry ctor
Currently ThreadRegistry is overcomplicated because of tsan,
it needs tid quarantine and reuse counters. Other sanitizers
don't need that. It also seems that no other sanitizer now
needs max number of threads. Asan used to need 2^24 limit,
but it does not seem to be needed now. Other sanitizers blindly
copy-pasted that without reasons. Lsan also uses quarantine,
but I don't see why that may be potentially needed.

Add a ThreadRegistry ctor that does not require any sizes
and use it in all sanitizers except for tsan.
In preparation for new tsan runtime, which won't need
any of these parameters as well.

Reviewed By: vitalybuka

Differential Revision: https://reviews.llvm.org/D105713
2021-07-13 22:52:25 -07:00
Vitaly Buka
b4a6fa12d1 Revert "sanitizer_common: add simpler ThreadRegistry ctor"
Breaks https://lab.llvm.org/buildbot/#/builders/sanitizer-x86_64-linux-android

This reverts commit 6062c672bc5e560a4c3dc73741f9e82b39d08527.
This reverts commit 8e489b4b96e31cfb004e03cfa1393c425c504013.
2021-07-12 12:04:12 -07:00
Dmitry Vyukov
8e489b4b96 sanitizer_common: add simpler ThreadRegistry ctor
Currently ThreadRegistry is overcomplicated because of tsan,
it needs tid quarantine and reuse counters. Other sanitizers
don't need that. It also seems that no other sanitizer now
needs max number of threads. Asan used to need 2^24 limit,
but it does not seem to be needed now. Other sanitizers blindly
copy-pasted that without reasons. Lsan also uses quarantine,
but I don't see why that may be potentially needed.

Add a ThreadRegistry ctor that does not require any sizes
and use it in all sanitizers except for tsan.
In preparation for new tsan runtime, which won't need
any of these parameters as well.

Reviewed By: vitalybuka

Differential Revision: https://reviews.llvm.org/D105713
2021-07-11 12:36:28 +02:00
Fangrui Song
35fb4b9a7c [lsan] Bump the thread limit from 1<<13 to 1<<22
This matches asan. Some applications need more than 1<<13 threads.

Reviewed By: vitalybuka

Differential Revision: https://reviews.llvm.org/D103731
2021-06-04 20:15:56 -07:00
Dmitry Vyukov
92a3a2dc3e sanitizer_common: introduce kInvalidTid/kMainTid
Currently we have a bit of a mess related to tids:
 - sanitizers re-declare kInvalidTid multiple times
 - some call it kUnknownTid
 - implicit assumptions that main tid is 0
 - asan/memprof claim their tids need to fit into 24 bits,
   but this does not seem to be true anymore
 - inconsistent use of u32/int to store tids

Introduce kInvalidTid/kMainTid in sanitizer_common
and use them consistently.

Reviewed By: vitalybuka

Differential Revision: https://reviews.llvm.org/D101428
2021-04-30 15:58:05 +02:00
Marco Vanotti
a83eb048cb [lsan] Add interceptor for pthread_detach.
This commit adds an interceptor for the pthread_detach function,
calling into ThreadRegistry::DetachThread, allowing for thread contexts
to be reused.

Without this change, programs may fail when they create more than 8K
threads.

Fixes: https://bugs.llvm.org/show_bug.cgi?id=47389

Reviewed By: vitalybuka

Differential Revision: https://reviews.llvm.org/D88184
2020-09-25 14:22:45 -07:00
Roland McGrath
38fd1806a1 [lsan] Factor pthread-specific assumptions out of thread tracking code
This is a small refactoring to prepare for porting LSan to Fuchsia.
Factor out parts of lsan_thread.{cpp,h} that don't apply to Fuchsia.
Since existing supported systems are POSIX-based, the affected code
is moved to lsan_posix.{cpp.h}.

Patch By: mcgrathr

Differential Revision: https://reviews.llvm.org/D73309
2020-01-24 16:55:11 -08:00
Nico Weber
ae1fc9baae compiler-rt: Rename .cc file in lib/lsan to .cpp
Like r367463, but for lsan.

llvm-svn: 367561
2019-08-01 14:01:30 +00:00