12
12
// sanitizer_common/sanitizer_common_interceptors.inc
13
13
// ===----------------------------------------------------------------------===//
14
14
15
+ #include " sanitizer_common/sanitizer_allocator_dlsym.h"
15
16
#include " sanitizer_common/sanitizer_atomic.h"
16
17
#include " sanitizer_common/sanitizer_errno.h"
17
18
#include " sanitizer_common/sanitizer_glibc_version.h"
19
+ #include " sanitizer_common/sanitizer_internal_defs.h"
18
20
#include " sanitizer_common/sanitizer_libc.h"
19
21
#include " sanitizer_common/sanitizer_linux.h"
20
22
#include " sanitizer_common/sanitizer_platform_limits_netbsd.h"
21
23
#include " sanitizer_common/sanitizer_platform_limits_posix.h"
22
- #include " sanitizer_common/sanitizer_placement_new.h"
23
24
#include " sanitizer_common/sanitizer_posix.h"
24
25
#include " sanitizer_common/sanitizer_stacktrace.h"
25
26
#include " sanitizer_common/sanitizer_tls_get_addr.h"
@@ -252,6 +253,13 @@ SANITIZER_WEAK_CXX_DEFAULT_IMPL void OnPotentiallyBlockingRegionBegin() {}
252
253
SANITIZER_WEAK_CXX_DEFAULT_IMPL void OnPotentiallyBlockingRegionEnd () {}
253
254
#endif
254
255
256
+ // FIXME: Use for `in_symbolizer()` as well. As-is we can't use
257
+ // `DlSymAllocator`, because it uses the primary allocator only. Symbolizer
258
+ // requires support of the secondary allocator for larger blocks.
259
+ struct DlsymAlloc : public DlSymAllocator <DlsymAlloc> {
260
+ static bool UseImpl () { return (ctx && !ctx->initialized ); }
261
+ };
262
+
255
263
} // namespace __tsan
256
264
257
265
static ThreadSignalContext *SigCtx (ThreadState *thr) {
@@ -661,6 +669,8 @@ TSAN_INTERCEPTOR(void, _longjmp, uptr *env, int val) {
661
669
TSAN_INTERCEPTOR (void *, malloc, uptr size) {
662
670
if (in_symbolizer ())
663
671
return InternalAlloc (size);
672
+ if (DlsymAlloc::Use ())
673
+ return DlsymAlloc::Allocate (size);
664
674
void *p = 0 ;
665
675
{
666
676
SCOPED_INTERCEPTOR_RAW (malloc, size);
@@ -681,6 +691,8 @@ TSAN_INTERCEPTOR(void*, __libc_memalign, uptr align, uptr sz) {
681
691
TSAN_INTERCEPTOR (void *, calloc, uptr n, uptr size) {
682
692
if (in_symbolizer ())
683
693
return InternalCalloc (n, size);
694
+ if (DlsymAlloc::Use ())
695
+ return DlsymAlloc::Callocate (n, size);
684
696
void *p = 0 ;
685
697
{
686
698
SCOPED_INTERCEPTOR_RAW (calloc, n, size);
@@ -693,6 +705,8 @@ TSAN_INTERCEPTOR(void *, calloc, uptr n, uptr size) {
693
705
TSAN_INTERCEPTOR (void *, realloc, void *p, uptr size) {
694
706
if (in_symbolizer ())
695
707
return InternalRealloc (p, size);
708
+ if (DlsymAlloc::Use () || DlsymAlloc::PointerIsMine (p))
709
+ return DlsymAlloc::Realloc (p, size);
696
710
if (p)
697
711
invoke_free_hook (p);
698
712
{
@@ -717,20 +731,24 @@ TSAN_INTERCEPTOR(void *, reallocarray, void *p, uptr n, uptr size) {
717
731
}
718
732
719
733
TSAN_INTERCEPTOR (void , free, void *p) {
720
- if (p == 0 )
734
+ if (UNLIKELY (!p) )
721
735
return ;
722
736
if (in_symbolizer ())
723
737
return InternalFree (p);
738
+ if (DlsymAlloc::PointerIsMine (p))
739
+ return DlsymAlloc::Free (p);
724
740
invoke_free_hook (p);
725
741
SCOPED_INTERCEPTOR_RAW (free, p);
726
742
user_free (thr, pc, p);
727
743
}
728
744
729
745
TSAN_INTERCEPTOR (void , cfree, void *p) {
730
- if (p == 0 )
746
+ if (UNLIKELY (!p) )
731
747
return ;
732
748
if (in_symbolizer ())
733
749
return InternalFree (p);
750
+ if (DlsymAlloc::PointerIsMine (p))
751
+ return DlsymAlloc::Free (p);
734
752
invoke_free_hook (p);
735
753
SCOPED_INTERCEPTOR_RAW (cfree, p);
736
754
user_free (thr, pc, p);
0 commit comments