[sanitizer] Remove DTLS_on_libc_memalign (#108120)
`DTLS_on_libc_memalign` is called from primary allocator, so `__sanitizer_get_allocated_begin` should also be aware of allocation, and correctly handled by `GetDTLSRange`.
This commit is contained in:
parent
0683c4e839
commit
b07f1be92c
@ -25,7 +25,6 @@
|
||||
# include "sanitizer_common/sanitizer_allocator_checks.h"
|
||||
# include "sanitizer_common/sanitizer_allocator_dlsym.h"
|
||||
# include "sanitizer_common/sanitizer_errno.h"
|
||||
# include "sanitizer_common/sanitizer_tls_get_addr.h"
|
||||
|
||||
// ---------------------- Replacement functions ---------------- {{{1
|
||||
using namespace __asan;
|
||||
@ -99,9 +98,7 @@ INTERCEPTOR(void*, memalign, uptr boundary, uptr size) {
|
||||
|
||||
INTERCEPTOR(void*, __libc_memalign, uptr boundary, uptr size) {
|
||||
GET_STACK_TRACE_MALLOC;
|
||||
void *res = asan_memalign(boundary, size, &stack, FROM_MALLOC);
|
||||
DTLS_on_libc_memalign(res, size);
|
||||
return res;
|
||||
return asan_memalign(boundary, size, &stack, FROM_MALLOC);
|
||||
}
|
||||
#endif // SANITIZER_INTERCEPT_MEMALIGN
|
||||
|
||||
|
@ -39,10 +39,7 @@ INTERCEPTOR(void *, reallocarray, void *ptr, SIZE_T nmemb, SIZE_T size) {
|
||||
}
|
||||
|
||||
INTERCEPTOR(void *, __libc_memalign, SIZE_T alignment, SIZE_T size) {
|
||||
void *ptr = dfsan_memalign(alignment, size);
|
||||
if (ptr)
|
||||
DTLS_on_libc_memalign(ptr, size);
|
||||
return ptr;
|
||||
return dfsan_memalign(alignment, size);
|
||||
}
|
||||
|
||||
INTERCEPTOR(void *, aligned_alloc, SIZE_T alignment, SIZE_T size) {
|
||||
|
@ -17,7 +17,6 @@
|
||||
#include "sanitizer_common/sanitizer_allocator_dlsym.h"
|
||||
#include "sanitizer_common/sanitizer_allocator_interface.h"
|
||||
#include "sanitizer_common/sanitizer_mallinfo.h"
|
||||
#include "sanitizer_common/sanitizer_tls_get_addr.h"
|
||||
|
||||
using namespace __hwasan;
|
||||
|
||||
@ -62,10 +61,7 @@ void *__sanitizer_aligned_alloc(uptr alignment, uptr size) {
|
||||
SANITIZER_INTERFACE_ATTRIBUTE
|
||||
void *__sanitizer___libc_memalign(uptr alignment, uptr size) {
|
||||
GET_MALLOC_STACK_TRACE;
|
||||
void *ptr = hwasan_memalign(alignment, size, &stack);
|
||||
if (ptr)
|
||||
DTLS_on_libc_memalign(ptr, size);
|
||||
return ptr;
|
||||
return hwasan_memalign(alignment, size, &stack);
|
||||
}
|
||||
|
||||
SANITIZER_INTERFACE_ATTRIBUTE
|
||||
|
@ -26,7 +26,6 @@
|
||||
#if SANITIZER_POSIX
|
||||
#include "sanitizer_common/sanitizer_posix.h"
|
||||
#endif
|
||||
#include "sanitizer_common/sanitizer_tls_get_addr.h"
|
||||
#include "lsan.h"
|
||||
#include "lsan_allocator.h"
|
||||
#include "lsan_common.h"
|
||||
@ -135,9 +134,7 @@ INTERCEPTOR(void*, memalign, uptr alignment, uptr size) {
|
||||
INTERCEPTOR(void *, __libc_memalign, uptr alignment, uptr size) {
|
||||
ENSURE_LSAN_INITED;
|
||||
GET_STACK_TRACE_MALLOC;
|
||||
void *res = lsan_memalign(alignment, size, stack);
|
||||
DTLS_on_libc_memalign(res, size);
|
||||
return res;
|
||||
return lsan_memalign(alignment, size, stack);
|
||||
}
|
||||
#define LSAN_MAYBE_INTERCEPT___LIBC_MEMALIGN INTERCEPT_FUNCTION(__libc_memalign)
|
||||
#else
|
||||
|
@ -90,9 +90,7 @@ INTERCEPTOR(void *, memalign, uptr boundary, uptr size) {
|
||||
|
||||
INTERCEPTOR(void *, __libc_memalign, uptr boundary, uptr size) {
|
||||
GET_STACK_TRACE_MALLOC;
|
||||
void *res = memprof_memalign(boundary, size, &stack, FROM_MALLOC);
|
||||
DTLS_on_libc_memalign(res, size);
|
||||
return res;
|
||||
return memprof_memalign(boundary, size, &stack, FROM_MALLOC);
|
||||
}
|
||||
#endif // SANITIZER_INTERCEPT_MEMALIGN
|
||||
|
||||
|
@ -37,7 +37,6 @@
|
||||
#include "sanitizer_common/sanitizer_platform_limits_netbsd.h"
|
||||
#include "sanitizer_common/sanitizer_platform_limits_posix.h"
|
||||
#include "sanitizer_common/sanitizer_stackdepot.h"
|
||||
#include "sanitizer_common/sanitizer_tls_get_addr.h"
|
||||
#include "sanitizer_common/sanitizer_vector.h"
|
||||
|
||||
#if SANITIZER_NETBSD
|
||||
@ -185,10 +184,7 @@ INTERCEPTOR(void *, aligned_alloc, SIZE_T alignment, SIZE_T size) {
|
||||
#if !SANITIZER_NETBSD
|
||||
INTERCEPTOR(void *, __libc_memalign, SIZE_T alignment, SIZE_T size) {
|
||||
GET_MALLOC_STACK_TRACE;
|
||||
void *ptr = msan_memalign(alignment, size, &stack);
|
||||
if (ptr)
|
||||
DTLS_on_libc_memalign(ptr, size);
|
||||
return ptr;
|
||||
return msan_memalign(alignment, size, &stack);
|
||||
}
|
||||
#define MSAN_MAYBE_INTERCEPT___LIBC_MEMALIGN INTERCEPT_FUNCTION(__libc_memalign)
|
||||
#else
|
||||
|
@ -116,7 +116,7 @@ static bool GetDTLSRange(uptr &tls_beg, uptr &tls_size) {
|
||||
return false;
|
||||
tls_beg = (uptr)start;
|
||||
tls_size = __sanitizer_get_allocated_size(start);
|
||||
VReport(2, "__tls_get_addr: glibc >=2.25 suspected; tls={%p,0x%zx}\n",
|
||||
VReport(2, "__tls_get_addr: glibc DTLS suspected; tls={%p,0x%zx}\n",
|
||||
(void *)tls_beg, tls_size);
|
||||
return true;
|
||||
}
|
||||
@ -137,11 +137,7 @@ DTLS::DTV *DTLS_on_tls_get_addr(void *arg_void, void *res,
|
||||
(void *)arg, arg->dso_id, arg->offset, res, (void *)tls_beg,
|
||||
(void *)&tls_beg,
|
||||
atomic_load(&number_of_live_dtls, memory_order_relaxed));
|
||||
if (dtls.last_memalign_ptr == tls_beg) {
|
||||
tls_size = dtls.last_memalign_size;
|
||||
VReport(2, "__tls_get_addr: glibc <=2.24 suspected; tls={%p,0x%zx}\n",
|
||||
(void *)tls_beg, tls_size);
|
||||
} else if (tls_beg >= static_tls_begin && tls_beg < static_tls_end) {
|
||||
if (tls_beg >= static_tls_begin && tls_beg < static_tls_end) {
|
||||
// This is the static TLS block which was initialized / unpoisoned at thread
|
||||
// creation.
|
||||
VReport(2, "__tls_get_addr: static tls: %p\n", (void *)tls_beg);
|
||||
@ -156,13 +152,6 @@ DTLS::DTV *DTLS_on_tls_get_addr(void *arg_void, void *res,
|
||||
return dtv;
|
||||
}
|
||||
|
||||
void DTLS_on_libc_memalign(void *ptr, uptr size) {
|
||||
if (!common_flags()->intercept_tls_get_addr) return;
|
||||
VReport(2, "DTLS_on_libc_memalign: %p 0x%zx\n", ptr, size);
|
||||
dtls.last_memalign_ptr = reinterpret_cast<uptr>(ptr);
|
||||
dtls.last_memalign_size = size;
|
||||
}
|
||||
|
||||
DTLS *DTLS_Get() { return &dtls; }
|
||||
|
||||
bool DTLSInDestruction(DTLS *dtls) {
|
||||
@ -171,7 +160,6 @@ bool DTLSInDestruction(DTLS *dtls) {
|
||||
}
|
||||
|
||||
#else
|
||||
void DTLS_on_libc_memalign(void *ptr, uptr size) {}
|
||||
DTLS::DTV *DTLS_on_tls_get_addr(void *arg, void *res,
|
||||
unsigned long, unsigned long) { return 0; }
|
||||
DTLS *DTLS_Get() { return 0; }
|
||||
|
@ -55,10 +55,6 @@ struct DTLS {
|
||||
static_assert(sizeof(DTVBlock) <= 4096UL, "Unexpected block size");
|
||||
|
||||
atomic_uintptr_t dtv_block;
|
||||
|
||||
// Auxiliary fields, don't access them outside sanitizer_tls_get_addr.cpp
|
||||
uptr last_memalign_size;
|
||||
uptr last_memalign_ptr;
|
||||
};
|
||||
|
||||
template <typename Fn>
|
||||
|
Loading…
x
Reference in New Issue
Block a user