Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
41 changes: 41 additions & 0 deletions compiler-rt/lib/tsan/rtl/tsan_interceptors_posix.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
#include "sanitizer_common/sanitizer_internal_defs.h"
#include "sanitizer_common/sanitizer_libc.h"
#include "sanitizer_common/sanitizer_linux.h"
#include "sanitizer_common/sanitizer_platform_interceptors.h"
#include "sanitizer_common/sanitizer_platform_limits_netbsd.h"
#include "sanitizer_common/sanitizer_platform_limits_posix.h"
#include "sanitizer_common/sanitizer_posix.h"
Expand Down Expand Up @@ -747,6 +748,41 @@ TSAN_INTERCEPTOR(void, free, void *p) {
user_free(thr, pc, p);
}

# if SANITIZER_INTERCEPT_FREE_SIZED
TSAN_INTERCEPTOR(void, free_sized, void *p, uptr size) {
if (UNLIKELY(!p))
return;
if (in_symbolizer())
return InternalFree(p);
if (DlsymAlloc::PointerIsMine(p))
return DlsymAlloc::Free(p);
invoke_free_hook(p);
SCOPED_INTERCEPTOR_RAW(free_sized, p, size);
user_free(thr, pc, p);
}
# define TSAN_MAYBE_INTERCEPT_FREE_SIZED INTERCEPT_FUNCTION(free_sized)
# else
# define TSAN_MAYBE_INTERCEPT_FREE_SIZED
# endif

# if SANITIZER_INTERCEPT_FREE_ALIGNED_SIZED
TSAN_INTERCEPTOR(void, free_aligned_sized, void *p, uptr alignment, uptr size) {
if (UNLIKELY(!p))
return;
if (in_symbolizer())
return InternalFree(p);
if (DlsymAlloc::PointerIsMine(p))
return DlsymAlloc::Free(p);
invoke_free_hook(p);
SCOPED_INTERCEPTOR_RAW(free_aligned_sized, p, alignment, size);
user_free(thr, pc, p);
}
# define TSAN_MAYBE_INTERCEPT_FREE_ALIGNED_SIZED \
INTERCEPT_FUNCTION(free_aligned_sized)
# else
# define TSAN_MAYBE_INTERCEPT_FREE_ALIGNED_SIZED
# endif

TSAN_INTERCEPTOR(void, cfree, void *p) {
if (UNLIKELY(!p))
return;
Expand All @@ -763,6 +799,9 @@ TSAN_INTERCEPTOR(uptr, malloc_usable_size, void *p) {
SCOPED_INTERCEPTOR_RAW(malloc_usable_size, p);
return user_alloc_usable_size(p);
}
#else
# define TSAN_MAYBE_INTERCEPT_FREE_SIZED
# define TSAN_MAYBE_INTERCEPT_FREE_ALIGNED_SIZED
#endif

TSAN_INTERCEPTOR(char *, strcpy, char *dst, const char *src) {
Expand Down Expand Up @@ -2963,6 +3002,8 @@ void InitializeInterceptors() {
TSAN_INTERCEPT(realloc);
TSAN_INTERCEPT(reallocarray);
TSAN_INTERCEPT(free);
TSAN_MAYBE_INTERCEPT_FREE_SIZED;
TSAN_MAYBE_INTERCEPT_FREE_ALIGNED_SIZED;
TSAN_INTERCEPT(cfree);
TSAN_INTERCEPT(munmap);
TSAN_MAYBE_INTERCEPT_MEMALIGN;
Expand Down
22 changes: 13 additions & 9 deletions compiler-rt/lib/tsan/rtl/tsan_malloc_mac.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -73,15 +73,19 @@ using namespace __tsan;
invoke_free_hook(ptr); \
SCOPED_INTERCEPTOR_RAW(free, ptr); \
user_free(thr, pc, ptr)
#define COMMON_MALLOC_SIZE(ptr) uptr size = user_alloc_usable_size(ptr);
#define COMMON_MALLOC_FILL_STATS(zone, stats)
#define COMMON_MALLOC_REPORT_UNKNOWN_REALLOC(ptr, zone_ptr, zone_name) \
(void)zone_name; \
Report("mz_realloc(%p) -- attempting to realloc unallocated memory.\n", ptr);
#define COMMON_MALLOC_NAMESPACE __tsan
#define COMMON_MALLOC_HAS_ZONE_ENUMERATOR 0
#define COMMON_MALLOC_HAS_EXTRA_INTROSPECTION_INIT 0
# define COMMON_MALLOC_FREE_SIZED(ptr, size) COMMON_MALLOC_FREE(ptr)
# define COMMON_MALLOC_FREE_ALIGNED_SIZED(ptr, alignment, size) \
COMMON_MALLOC_FREE(ptr)
# define COMMON_MALLOC_SIZE(ptr) uptr size = user_alloc_usable_size(ptr);
# define COMMON_MALLOC_FILL_STATS(zone, stats)
# define COMMON_MALLOC_REPORT_UNKNOWN_REALLOC(ptr, zone_ptr, zone_name) \
(void)zone_name; \
Report("mz_realloc(%p) -- attempting to realloc unallocated memory.\n", \
ptr);
# define COMMON_MALLOC_NAMESPACE __tsan
# define COMMON_MALLOC_HAS_ZONE_ENUMERATOR 0
# define COMMON_MALLOC_HAS_EXTRA_INTROSPECTION_INIT 0

#include "sanitizer_common/sanitizer_malloc_mac.inc"
# include "sanitizer_common/sanitizer_malloc_mac.inc"

#endif
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// RUN: %clang -std=c23 -O0 %s -o %t && %run %t
// UNSUPPORTED: asan, hwasan, rtsan, tsan, ubsan
// UNSUPPORTED: asan, hwasan, rtsan, ubsan

#include <stddef.h>
#include <stdlib.h>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// RUN: %clang -std=c23 -O0 %s -o %t && %run %t
// UNSUPPORTED: asan, hwasan, rtsan, tsan, ubsan
// UNSUPPORTED: asan, hwasan, rtsan, ubsan

#include <stddef.h>
#include <stdlib.h>
Expand Down
Loading