Path: blob/main/contrib/llvm-project/compiler-rt/lib/asan/asan_internal.h
35233 views
//===-- asan_internal.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 which defines various general utilities.11//===----------------------------------------------------------------------===//12#ifndef ASAN_INTERNAL_H13#define ASAN_INTERNAL_H1415#include "asan_flags.h"16#include "asan_interface_internal.h"17#include "sanitizer_common/sanitizer_common.h"18#include "sanitizer_common/sanitizer_internal_defs.h"19#include "sanitizer_common/sanitizer_libc.h"20#include "sanitizer_common/sanitizer_stacktrace.h"2122#if __has_feature(address_sanitizer) || defined(__SANITIZE_ADDRESS__)23# error \24"The AddressSanitizer run-time should not be instrumented by AddressSanitizer"25#endif2627// Build-time configuration options.2829// If set, asan will intercept C++ exception api call(s).30#ifndef ASAN_HAS_EXCEPTIONS31# define ASAN_HAS_EXCEPTIONS 132#endif3334// If set, values like allocator chunk size, as well as defaults for some flags35// will be changed towards less memory overhead.36#ifndef ASAN_LOW_MEMORY37# if SANITIZER_IOS || SANITIZER_ANDROID38# define ASAN_LOW_MEMORY 139# else40# define ASAN_LOW_MEMORY 041# endif42#endif4344#ifndef ASAN_DYNAMIC45# ifdef PIC46# define ASAN_DYNAMIC 147# else48# define ASAN_DYNAMIC 049# endif50#endif5152// All internal functions in asan reside inside the __asan namespace53// to avoid namespace collisions with the user programs.54// Separate namespace also makes it simpler to distinguish the asan run-time55// functions from the instrumented user code in a profile.56namespace __asan {5758class AsanThread;59using __sanitizer::StackTrace;6061void AsanInitFromRtl();62bool TryAsanInitFromRtl();6364// asan_win.cpp65void InitializePlatformExceptionHandlers();66// Returns whether an address is a valid allocated system heap block.67// 'addr' must point to the beginning of the block.68bool IsSystemHeapAddress(uptr addr);6970// asan_rtl.cpp71void PrintAddressSpaceLayout();72void NORETURN ShowStatsAndAbort();7374// asan_shadow_setup.cpp75void InitializeShadowMemory();7677// asan_malloc_linux.cpp / asan_malloc_mac.cpp78void ReplaceSystemMalloc();7980// asan_linux.cpp / asan_mac.cpp / asan_win.cpp81uptr FindDynamicShadowStart();82void AsanCheckDynamicRTPrereqs();83void AsanCheckIncompatibleRT();8485// Unpoisons platform-specific stacks.86// Returns true if all stacks have been unpoisoned.87bool PlatformUnpoisonStacks();8889// asan_rtl.cpp90// Unpoison a region containing a stack.91// Performs a sanity check and warns if the bounds don't look right.92// The warning contains the type string to identify the stack type.93void UnpoisonStack(uptr bottom, uptr top, const char *type);9495// asan_thread.cpp96AsanThread *CreateMainThread();9798// Support function for __asan_(un)register_image_globals. Searches for the99// loaded image containing `needle' and then enumerates all global metadata100// structures declared in that image, applying `op' (e.g.,101// __asan_(un)register_globals) to them.102typedef void (*globals_op_fptr)(__asan_global *, uptr);103void AsanApplyToGlobals(globals_op_fptr op, const void *needle);104105void AsanOnDeadlySignal(int, void *siginfo, void *context);106107void SignContextStack(void *context);108void ReadContextStack(void *context, uptr *stack, uptr *ssize);109void StopInitOrderChecking();110111// Wrapper for TLS/TSD.112void AsanTSDInit(void (*destructor)(void *tsd));113void *AsanTSDGet();114void AsanTSDSet(void *tsd);115void PlatformTSDDtor(void *tsd);116117void AppendToErrorMessageBuffer(const char *buffer);118119void *AsanDlSymNext(const char *sym);120121// Returns `true` iff most of ASan init process should be skipped due to the122// ASan library being loaded via `dlopen()`. Platforms may perform any123// `dlopen()` specific initialization inside this function.124bool HandleDlopenInit();125126void InstallAtExitCheckLeaks();127void InstallAtForkHandler();128129#define ASAN_ON_ERROR() \130if (&__asan_on_error) \131__asan_on_error()132133bool AsanInited();134extern bool replace_intrin_cached;135extern void (*death_callback)(void);136// These magic values are written to shadow for better error137// reporting.138const int kAsanHeapLeftRedzoneMagic = 0xfa;139const int kAsanHeapFreeMagic = 0xfd;140const int kAsanStackLeftRedzoneMagic = 0xf1;141const int kAsanStackMidRedzoneMagic = 0xf2;142const int kAsanStackRightRedzoneMagic = 0xf3;143const int kAsanStackAfterReturnMagic = 0xf5;144const int kAsanInitializationOrderMagic = 0xf6;145const int kAsanUserPoisonedMemoryMagic = 0xf7;146const int kAsanContiguousContainerOOBMagic = 0xfc;147const int kAsanStackUseAfterScopeMagic = 0xf8;148const int kAsanGlobalRedzoneMagic = 0xf9;149const int kAsanInternalHeapMagic = 0xfe;150const int kAsanArrayCookieMagic = 0xac;151const int kAsanIntraObjectRedzone = 0xbb;152const int kAsanAllocaLeftMagic = 0xca;153const int kAsanAllocaRightMagic = 0xcb;154155static const uptr kCurrentStackFrameMagic = 0x41B58AB3;156static const uptr kRetiredStackFrameMagic = 0x45E0360E;157158} // namespace __asan159160#endif // ASAN_INTERNAL_H161162163