Path: blob/main/contrib/llvm-project/compiler-rt/lib/asan/asan_interceptors.h
35233 views
//===-- asan_interceptors.h -------------------------------------*- C++ -*-===//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 AddressSanitizer, an address sanity checker.9//10// ASan-private header for asan_interceptors.cpp11//===----------------------------------------------------------------------===//12#ifndef ASAN_INTERCEPTORS_H13#define ASAN_INTERCEPTORS_H1415#include "asan_interceptors_memintrinsics.h"16#include "asan_internal.h"17#include "interception/interception.h"18#include "sanitizer_common/sanitizer_platform.h"19#include "sanitizer_common/sanitizer_platform_interceptors.h"2021namespace __asan {2223void InitializeAsanInterceptors();24void InitializePlatformInterceptors();2526} // namespace __asan2728// There is no general interception at all on Fuchsia.29// Only the functions in asan_interceptors_memintrinsics.h are30// really defined to replace libc functions.31#if !SANITIZER_FUCHSIA3233// Use macro to describe if specific function should be34// intercepted on a given platform.35#if !SANITIZER_WINDOWS36# define ASAN_INTERCEPT__LONGJMP 137# define ASAN_INTERCEPT_INDEX 138# define ASAN_INTERCEPT_PTHREAD_CREATE 139#else40# define ASAN_INTERCEPT__LONGJMP 041# define ASAN_INTERCEPT_INDEX 042# define ASAN_INTERCEPT_PTHREAD_CREATE 043#endif4445#if SANITIZER_FREEBSD || SANITIZER_LINUX || SANITIZER_NETBSD || \46SANITIZER_SOLARIS47# define ASAN_USE_ALIAS_ATTRIBUTE_FOR_INDEX 148#else49# define ASAN_USE_ALIAS_ATTRIBUTE_FOR_INDEX 050#endif5152#if SANITIZER_GLIBC || SANITIZER_SOLARIS53# define ASAN_INTERCEPT_SWAPCONTEXT 154#else55# define ASAN_INTERCEPT_SWAPCONTEXT 056#endif5758#if !SANITIZER_WINDOWS59# define ASAN_INTERCEPT_SIGLONGJMP 160#else61# define ASAN_INTERCEPT_SIGLONGJMP 062#endif6364#if SANITIZER_GLIBC65# define ASAN_INTERCEPT___LONGJMP_CHK 166#else67# define ASAN_INTERCEPT___LONGJMP_CHK 068#endif6970#if ASAN_HAS_EXCEPTIONS && !SANITIZER_SOLARIS && !SANITIZER_NETBSD && \71(!SANITIZER_WINDOWS || (defined(__MINGW32__) && defined(__i386__)))72# define ASAN_INTERCEPT___CXA_THROW 173# define ASAN_INTERCEPT___CXA_RETHROW_PRIMARY_EXCEPTION 174# if defined(_GLIBCXX_SJLJ_EXCEPTIONS) || (SANITIZER_IOS && defined(__arm__))75# define ASAN_INTERCEPT__UNWIND_SJLJ_RAISEEXCEPTION 176# else77# define ASAN_INTERCEPT__UNWIND_RAISEEXCEPTION 178# endif79#else80# define ASAN_INTERCEPT___CXA_THROW 081# define ASAN_INTERCEPT___CXA_RETHROW_PRIMARY_EXCEPTION 082# define ASAN_INTERCEPT__UNWIND_RAISEEXCEPTION 083# define ASAN_INTERCEPT__UNWIND_SJLJ_RAISEEXCEPTION 084#endif8586#if !SANITIZER_WINDOWS87# define ASAN_INTERCEPT___CXA_ATEXIT 188#else89# define ASAN_INTERCEPT___CXA_ATEXIT 090#endif9192#if SANITIZER_NETBSD93# define ASAN_INTERCEPT_ATEXIT 194#else95# define ASAN_INTERCEPT_ATEXIT 096#endif9798#if SANITIZER_GLIBC99# define ASAN_INTERCEPT___STRDUP 1100#else101# define ASAN_INTERCEPT___STRDUP 0102#endif103104#if SANITIZER_GLIBC && ASAN_INTERCEPT_PTHREAD_CREATE105# define ASAN_INTERCEPT_TIMEDJOIN 1106# define ASAN_INTERCEPT_TRYJOIN 1107#else108# define ASAN_INTERCEPT_TIMEDJOIN 0109# define ASAN_INTERCEPT_TRYJOIN 0110#endif111112#if SANITIZER_LINUX && \113(defined(__arm__) || defined(__aarch64__) || defined(__i386__) || \114defined(__x86_64__) || SANITIZER_RISCV64 || SANITIZER_LOONGARCH64)115# define ASAN_INTERCEPT_VFORK 1116#else117# define ASAN_INTERCEPT_VFORK 0118#endif119120#if SANITIZER_NETBSD121# define ASAN_INTERCEPT_PTHREAD_ATFORK 1122#else123# define ASAN_INTERCEPT_PTHREAD_ATFORK 0124#endif125126DECLARE_REAL(int, memcmp, const void *a1, const void *a2, uptr size)127DECLARE_REAL(char*, strchr, const char *str, int c)128DECLARE_REAL(SIZE_T, strlen, const char *s)129DECLARE_REAL(char*, strncpy, char *to, const char *from, uptr size)130DECLARE_REAL(uptr, strnlen, const char *s, uptr maxlen)131DECLARE_REAL(char*, strstr, const char *s1, const char *s2)132133# if !SANITIZER_APPLE134# define ASAN_INTERCEPT_FUNC(name) \135do { \136if (!INTERCEPT_FUNCTION(name)) \137VReport(1, "AddressSanitizer: failed to intercept '%s'\n", #name); \138} while (0)139# define ASAN_INTERCEPT_FUNC_VER(name, ver) \140do { \141if (!INTERCEPT_FUNCTION_VER(name, ver)) \142VReport(1, "AddressSanitizer: failed to intercept '%s@@%s'\n", \143#name, ver); \144} while (0)145# define ASAN_INTERCEPT_FUNC_VER_UNVERSIONED_FALLBACK(name, ver) \146do { \147if (!INTERCEPT_FUNCTION_VER(name, ver) && !INTERCEPT_FUNCTION(name)) \148VReport(1, \149"AddressSanitizer: failed to intercept '%s@@%s' or '%s'\n", \150#name, ver, #name); \151} while (0)152153# else154// OS X interceptors don't need to be initialized with INTERCEPT_FUNCTION.155# define ASAN_INTERCEPT_FUNC(name)156# endif // SANITIZER_APPLE157158#define ASAN_INTERCEPTOR_ENTER(ctx, func) \159AsanInterceptorContext _ctx = {#func}; \160ctx = (void *)&_ctx; \161(void) ctx;162#define COMMON_INTERCEPT_FUNCTION(name) ASAN_INTERCEPT_FUNC(name)163164#endif // !SANITIZER_FUCHSIA165166#endif // ASAN_INTERCEPTORS_H167168169