1 //===-- tsan_malloc_mac.cc ------------------------------------------------===//
3 // This file is distributed under the University of Illinois Open Source
4 // License. See LICENSE.TXT for details.
6 //===----------------------------------------------------------------------===//
8 // This file is a part of ThreadSanitizer (TSan), a race detector.
10 // Mac-specific malloc interception.
11 //===----------------------------------------------------------------------===//
13 #include "sanitizer_common/sanitizer_platform.h"
16 #include "sanitizer_common/sanitizer_errno.h"
17 #include "tsan_interceptors.h"
18 #include "tsan_stack_trace.h"
20 using namespace __tsan
;
21 #define COMMON_MALLOC_ZONE_NAME "tsan"
22 #define COMMON_MALLOC_ENTER()
23 #define COMMON_MALLOC_SANITIZER_INITIALIZED (cur_thread()->is_inited)
24 #define COMMON_MALLOC_FORCE_LOCK()
25 #define COMMON_MALLOC_FORCE_UNLOCK()
26 #define COMMON_MALLOC_MEMALIGN(alignment, size) \
28 user_memalign(cur_thread(), StackTrace::GetCurrentPc(), alignment, size)
29 #define COMMON_MALLOC_MALLOC(size) \
30 if (cur_thread()->in_symbolizer) return InternalAlloc(size); \
31 SCOPED_INTERCEPTOR_RAW(malloc, size); \
32 void *p = user_alloc(thr, pc, size)
33 #define COMMON_MALLOC_REALLOC(ptr, size) \
34 if (cur_thread()->in_symbolizer) return InternalRealloc(ptr, size); \
35 SCOPED_INTERCEPTOR_RAW(realloc, ptr, size); \
36 void *p = user_realloc(thr, pc, ptr, size)
37 #define COMMON_MALLOC_CALLOC(count, size) \
38 if (cur_thread()->in_symbolizer) return InternalCalloc(count, size); \
39 SCOPED_INTERCEPTOR_RAW(calloc, size, count); \
40 void *p = user_calloc(thr, pc, size, count)
41 #define COMMON_MALLOC_POSIX_MEMALIGN(memptr, alignment, size) \
42 if (cur_thread()->in_symbolizer) { \
43 void *p = InternalAlloc(size, nullptr, alignment); \
44 if (!p) return errno_ENOMEM; \
48 SCOPED_INTERCEPTOR_RAW(posix_memalign, memptr, alignment, size); \
49 int res = user_posix_memalign(thr, pc, memptr, alignment, size);
50 #define COMMON_MALLOC_VALLOC(size) \
51 if (cur_thread()->in_symbolizer) \
52 return InternalAlloc(size, nullptr, GetPageSizeCached()); \
53 SCOPED_INTERCEPTOR_RAW(valloc, size); \
54 void *p = user_valloc(thr, pc, size)
55 #define COMMON_MALLOC_FREE(ptr) \
56 if (cur_thread()->in_symbolizer) return InternalFree(ptr); \
57 SCOPED_INTERCEPTOR_RAW(free, ptr); \
58 user_free(thr, pc, ptr)
59 #define COMMON_MALLOC_SIZE(ptr) uptr size = user_alloc_usable_size(ptr);
60 #define COMMON_MALLOC_FILL_STATS(zone, stats)
61 #define COMMON_MALLOC_REPORT_UNKNOWN_REALLOC(ptr, zone_ptr, zone_name) \
63 Report("mz_realloc(%p) -- attempting to realloc unallocated memory.\n", ptr);
64 #define COMMON_MALLOC_NAMESPACE __tsan
66 #include "sanitizer_common/sanitizer_malloc_mac.inc"