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