63 lines · cpp
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-exception6//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_APPLE16 17#include "lsan.h"18#include "lsan_allocator.h"19#include "lsan_thread.h"20 21using namespace __lsan;22#define COMMON_MALLOC_ZONE_NAME "lsan"23#define COMMON_MALLOC_ENTER() ENSURE_LSAN_INITED24#define COMMON_MALLOC_SANITIZER_INITIALIZED lsan_inited25#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_FREE_SIZED(ptr, size) lsan_free_sized(ptr, size)48# define COMMON_MALLOC_FREE_ALIGNED_SIZED(ptr, alignment, size) \49 lsan_free_aligned_sized(ptr, alignment, size)50# define COMMON_MALLOC_SIZE(ptr) uptr size = lsan_mz_size(ptr)51# define COMMON_MALLOC_FILL_STATS(zone, stats)52# define COMMON_MALLOC_REPORT_UNKNOWN_REALLOC(ptr, zone_ptr, zone_name) \53 (void)zone_name; \54 Report("mz_realloc(%p) -- attempting to realloc unallocated memory.\n", \55 ptr);56# define COMMON_MALLOC_NAMESPACE __lsan57# define COMMON_MALLOC_HAS_ZONE_ENUMERATOR 058# define COMMON_MALLOC_HAS_EXTRA_INTROSPECTION_INIT 059 60# include "sanitizer_common/sanitizer_malloc_mac.inc"61 62#endif // SANITIZER_APPLE63