brintos

brintos / llvm-project-archived public Read only

0
0
Text · 5.2 KiB · 35c887e Raw
164 lines · c
1//===-- asan_internal.h -----------------------------------------*- C++ -*-===//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 AddressSanitizer, an address sanity checker.10//11// ASan-private header which defines various general utilities.12//===----------------------------------------------------------------------===//13#ifndef ASAN_INTERNAL_H14#define ASAN_INTERNAL_H15 16#include "asan_flags.h"17#include "asan_interface_internal.h"18#include "sanitizer_common/sanitizer_common.h"19#include "sanitizer_common/sanitizer_internal_defs.h"20#include "sanitizer_common/sanitizer_libc.h"21#include "sanitizer_common/sanitizer_stacktrace.h"22 23#if __has_feature(address_sanitizer) || defined(__SANITIZE_ADDRESS__)24#  error \25      "The AddressSanitizer run-time should not be instrumented by AddressSanitizer"26#endif27 28// Build-time configuration options.29 30// If set, asan will intercept C++ exception api call(s).31#ifndef ASAN_HAS_EXCEPTIONS32#  define ASAN_HAS_EXCEPTIONS 133#endif34 35// If set, values like allocator chunk size, as well as defaults for some flags36// will be changed towards less memory overhead.37#ifndef ASAN_LOW_MEMORY38#  if SANITIZER_IOS || SANITIZER_ANDROID39#    define ASAN_LOW_MEMORY 140#  else41#    define ASAN_LOW_MEMORY 042#  endif43#endif44 45#ifndef ASAN_DYNAMIC46#  ifdef PIC47#    define ASAN_DYNAMIC 148#  else49#    define ASAN_DYNAMIC 050#  endif51#endif52 53// All internal functions in asan reside inside the __asan namespace54// to avoid namespace collisions with the user programs.55// Separate namespace also makes it simpler to distinguish the asan run-time56// functions from the instrumented user code in a profile.57namespace __asan {58 59class AsanThread;60using __sanitizer::StackTrace;61 62void AsanInitFromRtl();63bool TryAsanInitFromRtl();64void ApplyFlags();65 66// asan_win.cpp67void InitializePlatformExceptionHandlers();68// Returns whether an address is a valid allocated system heap block.69// 'addr' must point to the beginning of the block.70bool IsSystemHeapAddress(uptr addr);71 72// asan_rtl.cpp73void PrintAddressSpaceLayout();74void NORETURN ShowStatsAndAbort();75 76// asan_shadow_setup.cpp77void InitializeShadowMemory();78 79// asan_malloc_linux.cpp / asan_malloc_mac.cpp80void ReplaceSystemMalloc();81 82// asan_linux.cpp / asan_mac.cpp / asan_win.cpp83uptr FindDynamicShadowStart();84void AsanCheckDynamicRTPrereqs();85void AsanCheckIncompatibleRT();86void TryReExecWithoutASLR();87 88// Unpoisons platform-specific stacks.89// Returns true if all stacks have been unpoisoned.90bool PlatformUnpoisonStacks();91 92// asan_rtl.cpp93// Unpoison a region containing a stack.94// Performs a sanity check and warns if the bounds don't look right.95// The warning contains the type string to identify the stack type.96void UnpoisonStack(uptr bottom, uptr top, const char *type);97 98// asan_thread.cpp99AsanThread *CreateMainThread();100 101// Support function for __asan_(un)register_image_globals. Searches for the102// loaded image containing `needle' and then enumerates all global metadata103// structures declared in that image, applying `op' (e.g.,104// __asan_(un)register_globals) to them.105typedef void (*globals_op_fptr)(__asan_global *, uptr);106void AsanApplyToGlobals(globals_op_fptr op, const void *needle);107 108void AsanOnDeadlySignal(int, void *siginfo, void *context);109 110void SignContextStack(void *context);111void ReadContextStack(void *context, uptr *stack, uptr *ssize);112void StopInitOrderChecking();113 114// Wrapper for TLS/TSD.115void AsanTSDInit(void (*destructor)(void *tsd));116void *AsanTSDGet();117void AsanTSDSet(void *tsd);118void PlatformTSDDtor(void *tsd);119 120void AppendToErrorMessageBuffer(const char *buffer);121 122void *AsanDlSymNext(const char *sym);123 124// Returns `true` iff most of ASan init process should be skipped due to the125// ASan library being loaded via `dlopen()`. Platforms may perform any126// `dlopen()` specific initialization inside this function.127bool HandleDlopenInit();128 129void InstallAtExitCheckLeaks();130void InstallAtForkHandler();131 132#define ASAN_ON_ERROR() \133  if (&__asan_on_error) \134  __asan_on_error()135 136bool AsanInited();137extern bool replace_intrin_cached;138extern void (*death_callback)(void);139// These magic values are written to shadow for better error140// reporting.141const int kAsanHeapLeftRedzoneMagic = 0xfa;142const int kAsanHeapFreeMagic = 0xfd;143const int kAsanStackLeftRedzoneMagic = 0xf1;144const int kAsanStackMidRedzoneMagic = 0xf2;145const int kAsanStackRightRedzoneMagic = 0xf3;146const int kAsanStackAfterReturnMagic = 0xf5;147const int kAsanInitializationOrderMagic = 0xf6;148const int kAsanUserPoisonedMemoryMagic = 0xf7;149const int kAsanContiguousContainerOOBMagic = 0xfc;150const int kAsanStackUseAfterScopeMagic = 0xf8;151const int kAsanGlobalRedzoneMagic = 0xf9;152const int kAsanInternalHeapMagic = 0xfe;153const int kAsanArrayCookieMagic = 0xac;154const int kAsanIntraObjectRedzone = 0xbb;155const int kAsanAllocaLeftMagic = 0xca;156const int kAsanAllocaRightMagic = 0xcb;157 158static const uptr kCurrentStackFrameMagic = 0x41B58AB3;159static const uptr kRetiredStackFrameMagic = 0x45E0360E;160 161}  // namespace __asan162 163#endif  // ASAN_INTERNAL_H164