blob: 744728d40df5395550be33baa705a767d69fe996 [file] [log] [blame]
Alexander Potapenko79fc3c02012-08-10 12:46:39 +00001//===-- asan_malloc_mac.cc ------------------------------------------------===//
Kostya Serebryany1e172b42011-11-30 01:07:02 +00002//
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
Evgeniy Stepanov24e13722013-03-19 14:33:38 +000015#include "sanitizer_common/sanitizer_platform.h"
Evgeniy Stepanov30e110e2013-03-19 14:54:17 +000016#if SANITIZER_MAC
Kostya Serebryanyd6567c52011-12-01 21:40:52 +000017
Kostya Serebryany1e172b42011-11-30 01:07:02 +000018#include "asan_interceptors.h"
Alexey Samsonov663c5012012-08-09 12:15:40 +000019#include "asan_report.h"
Kostya Serebryany1e172b42011-11-30 01:07:02 +000020#include "asan_stack.h"
Alexander Potapenkoca2cdd92012-09-12 15:29:50 +000021#include "asan_stats.h"
Kostya Serebryany1e172b42011-11-30 01:07:02 +000022
Pirama Arumuga Nainar799172d2016-03-03 15:50:30 -080023using 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; \
Alexander Potapenkoeba48032013-01-22 09:14:54 +000046 asan_free(ptr, &stack, FROM_MALLOC);
Pirama Arumuga Nainar799172d2016-03-03 15:50:30 -080047#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)); \
Alexander Potapenkoca2cdd92012-09-12 15:29:50 +000053 internal_memcpy(stats, &malloc_stats, sizeof(malloc_statistics_t));
Pirama Arumuga Nainar799172d2016-03-03 15:50:30 -080054#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
Kostya Serebryany1e172b42011-11-30 01:07:02 +000058
Pirama Arumuga Nainar799172d2016-03-03 15:50:30 -080059#include "sanitizer_common/sanitizer_malloc_mac.inc"
Kostya Serebryany1e172b42011-11-30 01:07:02 +000060
Pirama Arumuga Nainar799172d2016-03-03 15:50:30 -080061#endif