2018-01-30 Thomas Koenig <tkoenig@gcc.gnu.org>
[official-gcc.git] / libsanitizer / tsan / tsan_malloc_mac.cc
blobb418a211b58aaa743330cd02fa38baa7b06d17fb
1 //===-- tsan_malloc_mac.cc ------------------------------------------------===//
2 //
3 // This file is distributed under the University of Illinois Open Source
4 // License. See LICENSE.TXT for details.
5 //
6 //===----------------------------------------------------------------------===//
7 //
8 // This file is a part of ThreadSanitizer (TSan), a race detector.
9 //
10 // Mac-specific malloc interception.
11 //===----------------------------------------------------------------------===//
13 #include "sanitizer_common/sanitizer_platform.h"
14 #if SANITIZER_MAC
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) \
26 void *p = \
27 user_memalign(cur_thread(), StackTrace::GetCurrentPc(), alignment, size)
28 #define COMMON_MALLOC_MALLOC(size) \
29 if (cur_thread()->in_symbolizer) return InternalAlloc(size); \
30 SCOPED_INTERCEPTOR_RAW(malloc, size); \
31 void *p = user_alloc(thr, pc, size)
32 #define COMMON_MALLOC_REALLOC(ptr, size) \
33 if (cur_thread()->in_symbolizer) return InternalRealloc(ptr, size); \
34 SCOPED_INTERCEPTOR_RAW(realloc, ptr, size); \
35 void *p = user_realloc(thr, pc, ptr, size)
36 #define COMMON_MALLOC_CALLOC(count, size) \
37 if (cur_thread()->in_symbolizer) return InternalCalloc(count, size); \
38 SCOPED_INTERCEPTOR_RAW(calloc, size, count); \
39 void *p = user_calloc(thr, pc, size, count)
40 #define COMMON_MALLOC_VALLOC(size) \
41 if (cur_thread()->in_symbolizer) \
42 return InternalAlloc(size, nullptr, GetPageSizeCached()); \
43 SCOPED_INTERCEPTOR_RAW(valloc, size); \
44 void *p = user_valloc(thr, pc, size)
45 #define COMMON_MALLOC_FREE(ptr) \
46 if (cur_thread()->in_symbolizer) return InternalFree(ptr); \
47 SCOPED_INTERCEPTOR_RAW(free, ptr); \
48 user_free(thr, pc, ptr)
49 #define COMMON_MALLOC_SIZE(ptr) uptr size = user_alloc_usable_size(ptr);
50 #define COMMON_MALLOC_FILL_STATS(zone, stats)
51 #define COMMON_MALLOC_REPORT_UNKNOWN_REALLOC(ptr, zone_ptr, zone_name) \
52 (void)zone_name; \
53 Report("mz_realloc(%p) -- attempting to realloc unallocated memory.\n", ptr);
54 #define COMMON_MALLOC_NAMESPACE __tsan
56 #include "sanitizer_common/sanitizer_malloc_mac.inc"
58 #endif