]> git.proxmox.com Git - rustc.git/blame - src/compiler-rt/lib/asan/asan_malloc_mac.cc
Imported Upstream version 1.6.0+dfsg1
[rustc.git] / src / compiler-rt / lib / asan / asan_malloc_mac.cc
CommitLineData
1a4d82fc
JJ
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
1a4d82fc 18#include "asan_interceptors.h"
1a4d82fc
JJ
19#include "asan_report.h"
20#include "asan_stack.h"
21#include "asan_stats.h"
1a4d82fc 22
92a42be0
SL
23using 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; \
1a4d82fc 46 asan_free(ptr, &stack, FROM_MALLOC);
92a42be0
SL
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)); \
1a4d82fc 53 internal_memcpy(stats, &malloc_stats, sizeof(malloc_statistics_t));
92a42be0
SL
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_IGNORE_INVALID_FREE flags()->mac_ignore_invalid_free
58#define COMMON_MALLOC_REPORT_FREE_UNALLOCATED(ptr, zone_ptr, zone_name) \
59 GET_STACK_TRACE_FREE; \
60 WarnMacFreeUnallocated((uptr)ptr, (uptr)zone_ptr, zone_name, &stack);
61#define COMMON_MALLOC_NAMESPACE __asan
1a4d82fc 62
92a42be0 63#include "sanitizer_common/sanitizer_malloc_mac.inc"
1a4d82fc 64
1a4d82fc 65#endif