Path: blob/main/contrib/llvm-project/compiler-rt/lib/tsan/rtl/tsan_malloc_mac.cpp
35269 views
//===-- tsan_malloc_mac.cpp -----------------------------------------------===//1//2// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.3// See https://llvm.org/LICENSE.txt for license information.4// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception5//6//===----------------------------------------------------------------------===//7//8// This file is a part of ThreadSanitizer (TSan), a race detector.9//10// Mac-specific malloc interception.11//===----------------------------------------------------------------------===//1213#include "sanitizer_common/sanitizer_platform.h"14#if SANITIZER_APPLE1516#include "sanitizer_common/sanitizer_errno.h"17#include "tsan_interceptors.h"18#include "tsan_stack_trace.h"19#include "tsan_mman.h"2021using namespace __tsan;22#define COMMON_MALLOC_ZONE_NAME "tsan"23#define COMMON_MALLOC_ENTER()24#define COMMON_MALLOC_SANITIZER_INITIALIZED (cur_thread()->is_inited)25#define COMMON_MALLOC_FORCE_LOCK()26#define COMMON_MALLOC_FORCE_UNLOCK()27#define COMMON_MALLOC_MEMALIGN(alignment, size) \28void *p = \29user_memalign(cur_thread(), StackTrace::GetCurrentPc(), alignment, size)30#define COMMON_MALLOC_MALLOC(size) \31if (in_symbolizer()) return InternalAlloc(size); \32void *p = 0; \33{ \34SCOPED_INTERCEPTOR_RAW(malloc, size); \35p = user_alloc(thr, pc, size); \36} \37invoke_malloc_hook(p, size)38#define COMMON_MALLOC_REALLOC(ptr, size) \39if (in_symbolizer()) return InternalRealloc(ptr, size); \40if (ptr) \41invoke_free_hook(ptr); \42void *p = 0; \43{ \44SCOPED_INTERCEPTOR_RAW(realloc, ptr, size); \45p = user_realloc(thr, pc, ptr, size); \46} \47invoke_malloc_hook(p, size)48#define COMMON_MALLOC_CALLOC(count, size) \49if (in_symbolizer()) return InternalCalloc(count, size); \50void *p = 0; \51{ \52SCOPED_INTERCEPTOR_RAW(calloc, size, count); \53p = user_calloc(thr, pc, size, count); \54} \55invoke_malloc_hook(p, size * count)56#define COMMON_MALLOC_POSIX_MEMALIGN(memptr, alignment, size) \57if (in_symbolizer()) { \58void *p = InternalAlloc(size, nullptr, alignment); \59if (!p) return errno_ENOMEM; \60*memptr = p; \61return 0; \62} \63SCOPED_INTERCEPTOR_RAW(posix_memalign, memptr, alignment, size); \64int res = user_posix_memalign(thr, pc, memptr, alignment, size);65#define COMMON_MALLOC_VALLOC(size) \66if (in_symbolizer()) \67return InternalAlloc(size, nullptr, GetPageSizeCached()); \68SCOPED_INTERCEPTOR_RAW(valloc, size); \69void *p = user_valloc(thr, pc, size)70#define COMMON_MALLOC_FREE(ptr) \71if (in_symbolizer()) return InternalFree(ptr); \72invoke_free_hook(ptr); \73SCOPED_INTERCEPTOR_RAW(free, ptr); \74user_free(thr, pc, ptr)75#define COMMON_MALLOC_SIZE(ptr) uptr size = user_alloc_usable_size(ptr);76#define COMMON_MALLOC_FILL_STATS(zone, stats)77#define COMMON_MALLOC_REPORT_UNKNOWN_REALLOC(ptr, zone_ptr, zone_name) \78(void)zone_name; \79Report("mz_realloc(%p) -- attempting to realloc unallocated memory.\n", ptr);80#define COMMON_MALLOC_NAMESPACE __tsan81#define COMMON_MALLOC_HAS_ZONE_ENUMERATOR 082#define COMMON_MALLOC_HAS_EXTRA_INTROSPECTION_INIT 08384#include "sanitizer_common/sanitizer_malloc_mac.inc"8586#endif878889