]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - contrib/compiler-rt/lib/asan/asan_malloc_mac.cc
Upgrade to OpenSSH 7.4p1.
[FreeBSD/FreeBSD.git] / contrib / compiler-rt / lib / asan / asan_malloc_mac.cc
1 //===-- asan_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 AddressSanitizer, an address sanity checker.
11 //
12 // Mac-specific malloc interception.
13 //===----------------------------------------------------------------------===//
14
15 #include "sanitizer_common/sanitizer_platform.h"
16 #if SANITIZER_MAC
17
18 #include "asan_interceptors.h"
19 #include "asan_report.h"
20 #include "asan_stack.h"
21 #include "asan_stats.h"
22
23 using namespace __asan;
24 #define COMMON_MALLOC_ZONE_NAME "asan"
25 #define COMMON_MALLOC_ENTER() ENSURE_ASAN_INITED()
26 #define COMMON_MALLOC_SANITIZER_INITIALIZED asan_inited
27 #define COMMON_MALLOC_FORCE_LOCK() asan_mz_force_lock()
28 #define COMMON_MALLOC_FORCE_UNLOCK() asan_mz_force_unlock()
29 #define COMMON_MALLOC_MEMALIGN(alignment, size) \
30   GET_STACK_TRACE_MALLOC; \
31   void *p = asan_memalign(alignment, size, &stack, FROM_MALLOC)
32 #define COMMON_MALLOC_MALLOC(size) \
33   GET_STACK_TRACE_MALLOC; \
34   void *p = asan_malloc(size, &stack)
35 #define COMMON_MALLOC_REALLOC(ptr, size) \
36   GET_STACK_TRACE_MALLOC; \
37   void *p = asan_realloc(ptr, size, &stack);
38 #define COMMON_MALLOC_CALLOC(count, size) \
39   GET_STACK_TRACE_MALLOC; \
40   void *p = asan_calloc(count, size, &stack);
41 #define COMMON_MALLOC_VALLOC(size) \
42   GET_STACK_TRACE_MALLOC; \
43   void *p = asan_memalign(GetPageSizeCached(), size, &stack, FROM_MALLOC);
44 #define COMMON_MALLOC_FREE(ptr) \
45   GET_STACK_TRACE_FREE; \
46   asan_free(ptr, &stack, FROM_MALLOC);
47 #define COMMON_MALLOC_SIZE(ptr) \
48   uptr size = asan_mz_size(ptr);
49 #define COMMON_MALLOC_FILL_STATS(zone, stats) \
50   AsanMallocStats malloc_stats; \
51   FillMallocStatistics(&malloc_stats); \
52   CHECK(sizeof(malloc_statistics_t) == sizeof(AsanMallocStats)); \
53   internal_memcpy(stats, &malloc_stats, sizeof(malloc_statistics_t));
54 #define COMMON_MALLOC_REPORT_UNKNOWN_REALLOC(ptr, zone_ptr, zone_name) \
55   GET_STACK_TRACE_FREE; \
56   ReportMacMzReallocUnknown((uptr)ptr, (uptr)zone_ptr, zone_name, &stack);
57 #define COMMON_MALLOC_NAMESPACE __asan
58
59 #include "sanitizer_common/sanitizer_malloc_mac.inc"
60
61 #endif