Pirama Arumuga Nainar | 799172d | 2016-03-03 15:50:30 -0800 | [diff] [blame^] | 1 | //===-- tsan_malloc_mac.cc ------------------------------------------------===// |
| 2 | // |
| 3 | // The LLVM Compiler Infrastructure |
| 4 | // |
| 5 | // This file is distributed under the University of Illinois Open Source |
| 6 | // License. See LICENSE.TXT for details. |
| 7 | // |
| 8 | //===----------------------------------------------------------------------===// |
| 9 | // |
| 10 | // This file is a part of ThreadSanitizer (TSan), a race detector. |
| 11 | // |
| 12 | // Mac-specific malloc interception. |
| 13 | //===----------------------------------------------------------------------===// |
| 14 | |
| 15 | #include "sanitizer_common/sanitizer_platform.h" |
| 16 | #if SANITIZER_MAC |
| 17 | |
| 18 | #include "tsan_interceptors.h" |
| 19 | #include "tsan_stack_trace.h" |
| 20 | |
| 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) \ |
| 28 | void *p = \ |
| 29 | user_alloc(cur_thread(), StackTrace::GetCurrentPc(), size, alignment) |
| 30 | #define COMMON_MALLOC_MALLOC(size) \ |
| 31 | if (cur_thread()->in_symbolizer) \ |
| 32 | return REAL(malloc)(size); \ |
| 33 | SCOPED_INTERCEPTOR_RAW(malloc, size); \ |
| 34 | void *p = user_alloc(thr, pc, size) |
| 35 | #define COMMON_MALLOC_REALLOC(ptr, size) \ |
| 36 | if (cur_thread()->in_symbolizer) \ |
| 37 | return REAL(realloc)(ptr, size); \ |
| 38 | SCOPED_INTERCEPTOR_RAW(realloc, ptr, size); \ |
| 39 | void *p = user_realloc(thr, pc, ptr, size) |
| 40 | #define COMMON_MALLOC_CALLOC(count, size) \ |
| 41 | if (cur_thread()->in_symbolizer) \ |
| 42 | return REAL(calloc)(count, size); \ |
| 43 | SCOPED_INTERCEPTOR_RAW(calloc, size, count); \ |
| 44 | void *p = user_calloc(thr, pc, size, count) |
| 45 | #define COMMON_MALLOC_VALLOC(size) \ |
| 46 | if (cur_thread()->in_symbolizer) \ |
| 47 | return REAL(valloc)(size); \ |
| 48 | SCOPED_INTERCEPTOR_RAW(valloc, size); \ |
| 49 | void *p = user_alloc(thr, pc, size, GetPageSizeCached()) |
| 50 | #define COMMON_MALLOC_FREE(ptr) \ |
| 51 | if (cur_thread()->in_symbolizer) \ |
| 52 | return REAL(free)(ptr); \ |
| 53 | SCOPED_INTERCEPTOR_RAW(free, ptr); \ |
| 54 | user_free(thr, pc, ptr) |
| 55 | #define COMMON_MALLOC_SIZE(ptr) \ |
| 56 | uptr size = user_alloc_usable_size(ptr); |
| 57 | #define COMMON_MALLOC_FILL_STATS(zone, stats) |
| 58 | #define COMMON_MALLOC_REPORT_UNKNOWN_REALLOC(ptr, zone_ptr, zone_name) \ |
| 59 | (void)zone_name; \ |
| 60 | Report("mz_realloc(%p) -- attempting to realloc unallocated memory.\n", ptr); |
| 61 | #define COMMON_MALLOC_NAMESPACE __tsan |
| 62 | |
| 63 | #include "sanitizer_common/sanitizer_malloc_mac.inc" |
| 64 | |
| 65 | #endif |