2012-08-10 20:46:39 +08:00
|
|
|
//===-- asan_malloc_mac.cc ------------------------------------------------===//
|
2011-11-30 09:07:02 +08:00
|
|
|
//
|
|
|
|
// The LLVM Compiler Infrastructure
|
|
|
|
//
|
|
|
|
// This file is distributed under the University of Illinois Open Source
|
|
|
|
// License. See LICENSE.TXT for details.
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
//
|
|
|
|
// This file is a part of AddressSanitizer, an address sanity checker.
|
|
|
|
//
|
|
|
|
// Mac-specific malloc interception.
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
2013-03-19 22:33:38 +08:00
|
|
|
#include "sanitizer_common/sanitizer_platform.h"
|
2013-03-19 22:54:17 +08:00
|
|
|
#if SANITIZER_MAC
|
2011-12-02 05:40:52 +08:00
|
|
|
|
2011-11-30 09:07:02 +08:00
|
|
|
#include "asan_interceptors.h"
|
2012-08-09 20:15:40 +08:00
|
|
|
#include "asan_report.h"
|
2011-11-30 09:07:02 +08:00
|
|
|
#include "asan_stack.h"
|
2012-09-12 23:29:50 +08:00
|
|
|
#include "asan_stats.h"
|
2012-08-29 20:36:24 +08:00
|
|
|
|
2015-11-04 23:43:45 +08:00
|
|
|
using namespace __asan;
|
|
|
|
#define COMMON_MALLOC_ZONE_NAME "asan"
|
|
|
|
#define COMMON_MALLOC_ENTER() ENSURE_ASAN_INITED()
|
|
|
|
#define COMMON_MALLOC_SANITIZER_INITIALIZED asan_inited
|
|
|
|
#define COMMON_MALLOC_FORCE_LOCK() asan_mz_force_lock()
|
|
|
|
#define COMMON_MALLOC_FORCE_UNLOCK() asan_mz_force_unlock()
|
|
|
|
#define COMMON_MALLOC_MEMALIGN(alignment, size) \
|
|
|
|
GET_STACK_TRACE_MALLOC; \
|
|
|
|
void *p = asan_memalign(alignment, size, &stack, FROM_MALLOC)
|
|
|
|
#define COMMON_MALLOC_MALLOC(size) \
|
|
|
|
GET_STACK_TRACE_MALLOC; \
|
|
|
|
void *p = asan_malloc(size, &stack)
|
|
|
|
#define COMMON_MALLOC_REALLOC(ptr, size) \
|
|
|
|
GET_STACK_TRACE_MALLOC; \
|
|
|
|
void *p = asan_realloc(ptr, size, &stack);
|
|
|
|
#define COMMON_MALLOC_CALLOC(count, size) \
|
|
|
|
GET_STACK_TRACE_MALLOC; \
|
|
|
|
void *p = asan_calloc(count, size, &stack);
|
2018-03-13 05:59:06 +08:00
|
|
|
#define COMMON_MALLOC_POSIX_MEMALIGN(memptr, alignment, size) \
|
|
|
|
GET_STACK_TRACE_MALLOC; \
|
|
|
|
int res = asan_posix_memalign(memptr, alignment, size, &stack);
|
2015-11-04 23:43:45 +08:00
|
|
|
#define COMMON_MALLOC_VALLOC(size) \
|
|
|
|
GET_STACK_TRACE_MALLOC; \
|
|
|
|
void *p = asan_memalign(GetPageSizeCached(), size, &stack, FROM_MALLOC);
|
|
|
|
#define COMMON_MALLOC_FREE(ptr) \
|
|
|
|
GET_STACK_TRACE_FREE; \
|
2013-01-22 17:14:54 +08:00
|
|
|
asan_free(ptr, &stack, FROM_MALLOC);
|
2015-11-04 23:43:45 +08:00
|
|
|
#define COMMON_MALLOC_SIZE(ptr) \
|
|
|
|
uptr size = asan_mz_size(ptr);
|
|
|
|
#define COMMON_MALLOC_FILL_STATS(zone, stats) \
|
|
|
|
AsanMallocStats malloc_stats; \
|
|
|
|
FillMallocStatistics(&malloc_stats); \
|
|
|
|
CHECK(sizeof(malloc_statistics_t) == sizeof(AsanMallocStats)); \
|
2012-09-12 23:29:50 +08:00
|
|
|
internal_memcpy(stats, &malloc_stats, sizeof(malloc_statistics_t));
|
2015-11-04 23:43:45 +08:00
|
|
|
#define COMMON_MALLOC_REPORT_UNKNOWN_REALLOC(ptr, zone_ptr, zone_name) \
|
|
|
|
GET_STACK_TRACE_FREE; \
|
|
|
|
ReportMacMzReallocUnknown((uptr)ptr, (uptr)zone_ptr, zone_name, &stack);
|
|
|
|
#define COMMON_MALLOC_NAMESPACE __asan
|
2012-07-06 21:24:28 +08:00
|
|
|
|
2015-11-04 23:43:45 +08:00
|
|
|
#include "sanitizer_common/sanitizer_malloc_mac.inc"
|
2011-11-30 09:07:02 +08:00
|
|
|
|
2015-11-04 23:43:45 +08:00
|
|
|
#endif
|