xref: /freebsd/contrib/llvm-project/compiler-rt/lib/lsan/lsan_malloc_mac.cpp (revision 5ca8e32633c4ffbbcd6762e5888b6a4ba0708c6c)
1 //===-- lsan_malloc_mac.cpp -----------------------------------------------===//
2 //
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6 //
7 //===----------------------------------------------------------------------===//
8 //
9 // This file is a part of LeakSanitizer (LSan), a memory leak detector.
10 //
11 // Mac-specific malloc interception.
12 //===----------------------------------------------------------------------===//
13 
14 #include "sanitizer_common/sanitizer_platform.h"
15 #if SANITIZER_APPLE
16 
17 #include "lsan.h"
18 #include "lsan_allocator.h"
19 #include "lsan_thread.h"
20 
21 using namespace __lsan;
22 #define COMMON_MALLOC_ZONE_NAME "lsan"
23 #define COMMON_MALLOC_ENTER() ENSURE_LSAN_INITED
24 #define COMMON_MALLOC_SANITIZER_INITIALIZED lsan_inited
25 #define COMMON_MALLOC_FORCE_LOCK()
26 #define COMMON_MALLOC_FORCE_UNLOCK()
27 #define COMMON_MALLOC_MEMALIGN(alignment, size) \
28   GET_STACK_TRACE_MALLOC; \
29   void *p = lsan_memalign(alignment, size, stack)
30 #define COMMON_MALLOC_MALLOC(size) \
31   GET_STACK_TRACE_MALLOC; \
32   void *p = lsan_malloc(size, stack)
33 #define COMMON_MALLOC_REALLOC(ptr, size) \
34   GET_STACK_TRACE_MALLOC; \
35   void *p = lsan_realloc(ptr, size, stack)
36 #define COMMON_MALLOC_CALLOC(count, size) \
37   GET_STACK_TRACE_MALLOC; \
38   void *p = lsan_calloc(count, size, stack)
39 #define COMMON_MALLOC_POSIX_MEMALIGN(memptr, alignment, size) \
40   GET_STACK_TRACE_MALLOC; \
41   int res = lsan_posix_memalign(memptr, alignment, size, stack)
42 #define COMMON_MALLOC_VALLOC(size) \
43   GET_STACK_TRACE_MALLOC; \
44   void *p = lsan_valloc(size, stack)
45 #define COMMON_MALLOC_FREE(ptr) \
46   lsan_free(ptr)
47 #define COMMON_MALLOC_SIZE(ptr) \
48   uptr size = lsan_mz_size(ptr)
49 #define COMMON_MALLOC_FILL_STATS(zone, stats)
50 #define COMMON_MALLOC_REPORT_UNKNOWN_REALLOC(ptr, zone_ptr, zone_name) \
51   (void)zone_name; \
52   Report("mz_realloc(%p) -- attempting to realloc unallocated memory.\n", ptr);
53 #define COMMON_MALLOC_NAMESPACE __lsan
54 #define COMMON_MALLOC_HAS_ZONE_ENUMERATOR 0
55 #define COMMON_MALLOC_HAS_EXTRA_INTROSPECTION_INIT 0
56 
57 #include "sanitizer_common/sanitizer_malloc_mac.inc"
58 
59 #endif // SANITIZER_APPLE
60