1//===-- lsan_malloc_mac.cc ------------------------------------------------===//
2//
3// This file is distributed under the University of Illinois Open Source
4// License. See LICENSE.TXT for details.
5//
6//===----------------------------------------------------------------------===//
7//
8// This file is a part of LeakSanitizer (LSan), a memory leak detector.
9//
10// Mac-specific malloc interception.
11//===----------------------------------------------------------------------===//
12
13#include "sanitizer_common/sanitizer_platform.h"
14#if SANITIZER_MAC
15
16#include "lsan.h"
17#include "lsan_allocator.h"
18#include "lsan_thread.h"
19
20using namespace __lsan;
21#define COMMON_MALLOC_ZONE_NAME "lsan"
22#define COMMON_MALLOC_ENTER() ENSURE_LSAN_INITED
23#define COMMON_MALLOC_SANITIZER_INITIALIZED lsan_inited
24#define COMMON_MALLOC_FORCE_LOCK()
25#define COMMON_MALLOC_FORCE_UNLOCK()
26#define COMMON_MALLOC_MEMALIGN(alignment, size) \
27  GET_STACK_TRACE_MALLOC; \
28  void *p = lsan_memalign(alignment, size, stack)
29#define COMMON_MALLOC_MALLOC(size) \
30  GET_STACK_TRACE_MALLOC; \
31  void *p = lsan_malloc(size, stack)
32#define COMMON_MALLOC_REALLOC(ptr, size) \
33  GET_STACK_TRACE_MALLOC; \
34  void *p = lsan_realloc(ptr, size, stack)
35#define COMMON_MALLOC_CALLOC(count, size) \
36  GET_STACK_TRACE_MALLOC; \
37  void *p = lsan_calloc(count, size, stack)
38#define COMMON_MALLOC_POSIX_MEMALIGN(memptr, alignment, size) \
39  GET_STACK_TRACE_MALLOC; \
40  int res = lsan_posix_memalign(memptr, alignment, size, stack)
41#define COMMON_MALLOC_VALLOC(size) \
42  GET_STACK_TRACE_MALLOC; \
43  void *p = lsan_valloc(size, stack)
44#define COMMON_MALLOC_FREE(ptr) \
45  lsan_free(ptr)
46#define COMMON_MALLOC_SIZE(ptr) \
47  uptr size = lsan_mz_size(ptr)
48#define COMMON_MALLOC_FILL_STATS(zone, stats)
49#define COMMON_MALLOC_REPORT_UNKNOWN_REALLOC(ptr, zone_ptr, zone_name) \
50  (void)zone_name; \
51  Report("mz_realloc(%p) -- attempting to realloc unallocated memory.\n", ptr);
52#define COMMON_MALLOC_NAMESPACE __lsan
53
54#include "sanitizer_common/sanitizer_malloc_mac.inc"
55
56#endif // SANITIZER_MAC
57