Alexander Potapenko | 79fc3c0 | 2012-08-10 12:46:39 +0000 | [diff] [blame] | 1 | //===-- asan_malloc_mac.cc ------------------------------------------------===// |
Kostya Serebryany | 1e172b4 | 2011-11-30 01:07:02 +0000 | [diff] [blame] | 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 | |
Evgeniy Stepanov | 24e1372 | 2013-03-19 14:33:38 +0000 | [diff] [blame] | 15 | #include "sanitizer_common/sanitizer_platform.h" |
Evgeniy Stepanov | 30e110e | 2013-03-19 14:54:17 +0000 | [diff] [blame] | 16 | #if SANITIZER_MAC |
Kostya Serebryany | d6567c5 | 2011-12-01 21:40:52 +0000 | [diff] [blame] | 17 | |
Kostya Serebryany | 1e172b4 | 2011-11-30 01:07:02 +0000 | [diff] [blame] | 18 | #include "asan_interceptors.h" |
Alexey Samsonov | 663c501 | 2012-08-09 12:15:40 +0000 | [diff] [blame] | 19 | #include "asan_report.h" |
Kostya Serebryany | 1e172b4 | 2011-11-30 01:07:02 +0000 | [diff] [blame] | 20 | #include "asan_stack.h" |
Alexander Potapenko | ca2cdd9 | 2012-09-12 15:29:50 +0000 | [diff] [blame] | 21 | #include "asan_stats.h" |
Kostya Serebryany | 1e172b4 | 2011-11-30 01:07:02 +0000 | [diff] [blame] | 22 | |
Pirama Arumuga Nainar | 799172d | 2016-03-03 15:50:30 -0800 | [diff] [blame^] | 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; \ |
Alexander Potapenko | eba4803 | 2013-01-22 09:14:54 +0000 | [diff] [blame] | 46 | asan_free(ptr, &stack, FROM_MALLOC); |
Pirama Arumuga Nainar | 799172d | 2016-03-03 15:50:30 -0800 | [diff] [blame^] | 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)); \ |
Alexander Potapenko | ca2cdd9 | 2012-09-12 15:29:50 +0000 | [diff] [blame] | 53 | internal_memcpy(stats, &malloc_stats, sizeof(malloc_statistics_t)); |
Pirama Arumuga Nainar | 799172d | 2016-03-03 15:50:30 -0800 | [diff] [blame^] | 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 |
Kostya Serebryany | 1e172b4 | 2011-11-30 01:07:02 +0000 | [diff] [blame] | 58 | |
Pirama Arumuga Nainar | 799172d | 2016-03-03 15:50:30 -0800 | [diff] [blame^] | 59 | #include "sanitizer_common/sanitizer_malloc_mac.inc" |
Kostya Serebryany | 1e172b4 | 2011-11-30 01:07:02 +0000 | [diff] [blame] | 60 | |
Pirama Arumuga Nainar | 799172d | 2016-03-03 15:50:30 -0800 | [diff] [blame^] | 61 | #endif |