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 "tsan_interceptors.h"
17 #include "tsan_stack_trace.h"
19 using namespace __tsan
;
20 #define COMMON_MALLOC_ZONE_NAME "tsan"
21 #define COMMON_MALLOC_ENTER()
22 #define COMMON_MALLOC_SANITIZER_INITIALIZED (cur_thread()->is_inited)
23 #define COMMON_MALLOC_FORCE_LOCK()
24 #define COMMON_MALLOC_FORCE_UNLOCK()
25 #define COMMON_MALLOC_MEMALIGN(alignment, size) \
27 user_alloc(cur_thread(), StackTrace::GetCurrentPc(), size, alignment)
28 #define COMMON_MALLOC_MALLOC(size) \
29 if (cur_thread()->in_symbolizer) \
30 return REAL(malloc)(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) \
35 return REAL(realloc)(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) \
40 return REAL(calloc)(count, size); \
41 SCOPED_INTERCEPTOR_RAW(calloc, size, count); \
42 void *p = user_calloc(thr, pc, size, count)
43 #define COMMON_MALLOC_VALLOC(size) \
44 if (cur_thread()->in_symbolizer) \
45 return REAL(valloc)(size); \
46 SCOPED_INTERCEPTOR_RAW(valloc, size); \
47 void *p = user_alloc(thr, pc, size, GetPageSizeCached())
48 #define COMMON_MALLOC_FREE(ptr) \
49 if (cur_thread()->in_symbolizer) \
50 return REAL(free)(ptr); \
51 SCOPED_INTERCEPTOR_RAW(free, ptr); \
52 user_free(thr, pc, ptr)
53 #define COMMON_MALLOC_SIZE(ptr) \
54 uptr size = user_alloc_usable_size(ptr);
55 #define COMMON_MALLOC_FILL_STATS(zone, stats)
56 #define COMMON_MALLOC_REPORT_UNKNOWN_REALLOC(ptr, zone_ptr, zone_name) \
58 Report("mz_realloc(%p) -- attempting to realloc unallocated memory.\n", ptr);
59 #define COMMON_MALLOC_IGNORE_INVALID_FREE false
60 #define COMMON_MALLOC_REPORT_FREE_UNALLOCATED(ptr, zone_ptr, zone_name) \
62 Report("free_common(%p) -- attempting to free unallocated memory.\n", ptr);
63 #define COMMON_MALLOC_NAMESPACE __tsan
65 #include "sanitizer_common/sanitizer_malloc_mac.inc"