Home | History | Annotate | Line # | Download | only in rtl
      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 "sanitizer_common/sanitizer_errno.h"
     19 #include "tsan_interceptors.h"
     20 #include "tsan_stack_trace.h"
     21 
     22 using namespace __tsan;
     23 #define COMMON_MALLOC_ZONE_NAME "tsan"
     24 #define COMMON_MALLOC_ENTER()
     25 #define COMMON_MALLOC_SANITIZER_INITIALIZED (cur_thread()->is_inited)
     26 #define COMMON_MALLOC_FORCE_LOCK()
     27 #define COMMON_MALLOC_FORCE_UNLOCK()
     28 #define COMMON_MALLOC_MEMALIGN(alignment, size) \
     29   void *p =                                     \
     30       user_memalign(cur_thread(), StackTrace::GetCurrentPc(), alignment, size)
     31 #define COMMON_MALLOC_MALLOC(size)                             \
     32   if (cur_thread()->in_symbolizer) return InternalAlloc(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) return InternalRealloc(ptr, size); \
     37   SCOPED_INTERCEPTOR_RAW(realloc, ptr, size);                         \
     38   void *p = user_realloc(thr, pc, ptr, size)
     39 #define COMMON_MALLOC_CALLOC(count, size)                              \
     40   if (cur_thread()->in_symbolizer) return InternalCalloc(count, size); \
     41   SCOPED_INTERCEPTOR_RAW(calloc, size, count);                         \
     42   void *p = user_calloc(thr, pc, size, count)
     43 #define COMMON_MALLOC_POSIX_MEMALIGN(memptr, alignment, size)      \
     44   if (cur_thread()->in_symbolizer) {                               \
     45     void *p = InternalAlloc(size, nullptr, alignment);             \
     46     if (!p) return errno_ENOMEM;                                   \
     47     *memptr = p;                                                   \
     48     return 0;                                                      \
     49   }                                                                \
     50   SCOPED_INTERCEPTOR_RAW(posix_memalign, memptr, alignment, size); \
     51   int res = user_posix_memalign(thr, pc, memptr, alignment, size);
     52 #define COMMON_MALLOC_VALLOC(size)                            \
     53   if (cur_thread()->in_symbolizer)                            \
     54     return InternalAlloc(size, nullptr, GetPageSizeCached()); \
     55   SCOPED_INTERCEPTOR_RAW(valloc, size);                       \
     56   void *p = user_valloc(thr, pc, size)
     57 #define COMMON_MALLOC_FREE(ptr)                              \
     58   if (cur_thread()->in_symbolizer) return InternalFree(ptr); \
     59   SCOPED_INTERCEPTOR_RAW(free, ptr);                         \
     60   user_free(thr, pc, ptr)
     61 #define COMMON_MALLOC_SIZE(ptr) uptr size = user_alloc_usable_size(ptr);
     62 #define COMMON_MALLOC_FILL_STATS(zone, stats)
     63 #define COMMON_MALLOC_REPORT_UNKNOWN_REALLOC(ptr, zone_ptr, zone_name) \
     64   (void)zone_name; \
     65   Report("mz_realloc(%p) -- attempting to realloc unallocated memory.\n", ptr);
     66 #define COMMON_MALLOC_NAMESPACE __tsan
     67 
     68 #include "sanitizer_common/sanitizer_malloc_mac.inc"
     69 
     70 #endif
     71