1229109Sed//===-- asan_internal.h -----------------------------------------*- C++ -*-===//
2229109Sed//
3229109Sed//                     The LLVM Compiler Infrastructure
4229109Sed//
5229109Sed// This file is distributed under the University of Illinois Open Source
6229109Sed// License. See LICENSE.TXT for details.
7229109Sed//
8229109Sed//===----------------------------------------------------------------------===//
9229109Sed//
10229109Sed// This file is a part of AddressSanitizer, an address sanity checker.
11229109Sed//
12229109Sed// ASan-private header which defines various general utilities.
13229109Sed//===----------------------------------------------------------------------===//
14229109Sed#ifndef ASAN_INTERNAL_H
15229109Sed#define ASAN_INTERNAL_H
16229109Sed
17238901Sandrew#include "asan_flags.h"
18251034Sed#include "asan_interface_internal.h"
19238901Sandrew#include "sanitizer_common/sanitizer_common.h"
20238901Sandrew#include "sanitizer_common/sanitizer_internal_defs.h"
21245614Sandrew#include "sanitizer_common/sanitizer_stacktrace.h"
22238901Sandrew#include "sanitizer_common/sanitizer_libc.h"
23238901Sandrew
24251034Sed#if __has_feature(address_sanitizer) || defined(__SANITIZE_ADDRESS__)
25229109Sed# error "The AddressSanitizer run-time should not be"
26229109Sed        " instrumented by AddressSanitizer"
27229109Sed#endif
28229109Sed
29229109Sed// Build-time configuration options.
30229109Sed
31229109Sed// If set, asan will intercept C++ exception api call(s).
32229109Sed#ifndef ASAN_HAS_EXCEPTIONS
33229109Sed# define ASAN_HAS_EXCEPTIONS 1
34229109Sed#endif
35229109Sed
36238901Sandrew// If set, values like allocator chunk size, as well as defaults for some flags
37238901Sandrew// will be changed towards less memory overhead.
38238901Sandrew#ifndef ASAN_LOW_MEMORY
39245614Sandrew#if SANITIZER_WORDSIZE == 32
40245614Sandrew#  define ASAN_LOW_MEMORY 1
41245614Sandrew#else
42245614Sandrew#  define ASAN_LOW_MEMORY 0
43245614Sandrew# endif
44238901Sandrew#endif
45238901Sandrew
46276789Sdim#ifndef ASAN_DYNAMIC
47276789Sdim# ifdef PIC
48276789Sdim#  define ASAN_DYNAMIC 1
49276789Sdim# else
50276789Sdim#  define ASAN_DYNAMIC 0
51276789Sdim# endif
52251034Sed#endif
53251034Sed
54229109Sed// All internal functions in asan reside inside the __asan namespace
55229109Sed// to avoid namespace collisions with the user programs.
56276789Sdim// Separate namespace also makes it simpler to distinguish the asan run-time
57229109Sed// functions from the instrumented user code in a profile.
58229109Sednamespace __asan {
59229109Sed
60229109Sedclass AsanThread;
61245614Sandrewusing __sanitizer::StackTrace;
62229109Sed
63276789Sdimvoid AsanInitFromRtl();
64276789Sdim
65229109Sed// asan_rtl.cc
66238901Sandrewvoid NORETURN ShowStatsAndAbort();
67229109Sed
68229109Sed// asan_malloc_linux.cc / asan_malloc_mac.cc
69229109Sedvoid ReplaceSystemMalloc();
70229109Sed
71238901Sandrew// asan_linux.cc / asan_mac.cc / asan_win.cc
72229109Sedvoid *AsanDoesNotSupportStaticLinkage();
73276789Sdimvoid AsanCheckDynamicRTPrereqs();
74276789Sdimvoid AsanCheckIncompatibleRT();
75229109Sed
76296417Sdimvoid AsanOnDeadlySignal(int, void *siginfo, void *context);
77229109Sed
78245614Sandrewvoid ReadContextStack(void *context, uptr *stack, uptr *ssize);
79251034Sedvoid StopInitOrderChecking();
80229109Sed
81238901Sandrew// Wrapper for TLS/TSD.
82238901Sandrewvoid AsanTSDInit(void (*destructor)(void *tsd));
83238901Sandrewvoid *AsanTSDGet();
84238901Sandrewvoid AsanTSDSet(void *tsd);
85274201Sdimvoid PlatformTSDDtor(void *tsd);
86238901Sandrew
87238901Sandrewvoid AppendToErrorMessageBuffer(const char *buffer);
88229109Sed
89276789Sdimvoid *AsanDlSymNext(const char *sym);
90276789Sdim
91288943Sdimvoid ReserveShadowMemoryRange(uptr beg, uptr end, const char *name);
92280031Sdim
93276789Sdim// Platform-specific options.
94251034Sed#if SANITIZER_MAC
95238901Sandrewbool PlatformHasDifferentMemcpyAndMemmove();
96238901Sandrew# define PLATFORM_HAS_DIFFERENT_MEMCPY_AND_MEMMOVE \
97238901Sandrew    (PlatformHasDifferentMemcpyAndMemmove())
98238901Sandrew#else
99238901Sandrew# define PLATFORM_HAS_DIFFERENT_MEMCPY_AND_MEMMOVE true
100251034Sed#endif  // SANITIZER_MAC
101229109Sed
102245614Sandrew// Add convenient macro for interface functions that may be represented as
103245614Sandrew// weak hooks.
104245614Sandrew#define ASAN_MALLOC_HOOK(ptr, size) \
105276789Sdim  if (&__sanitizer_malloc_hook) __sanitizer_malloc_hook(ptr, size)
106245614Sandrew#define ASAN_FREE_HOOK(ptr) \
107276789Sdim  if (&__sanitizer_free_hook) __sanitizer_free_hook(ptr)
108245614Sandrew#define ASAN_ON_ERROR() \
109245614Sandrew  if (&__asan_on_error) __asan_on_error()
110245614Sandrew
111229109Sedextern int asan_inited;
112229109Sed// Used to avoid infinite recursion in __asan_init().
113229109Sedextern bool asan_init_is_running;
114238901Sandrewextern void (*death_callback)(void);
115229109Sed
116229109Sed// These magic values are written to shadow for better error reporting.
117229109Sedconst int kAsanHeapLeftRedzoneMagic = 0xfa;
118229109Sedconst int kAsanHeapRightRedzoneMagic = 0xfb;
119229109Sedconst int kAsanHeapFreeMagic = 0xfd;
120229109Sedconst int kAsanStackLeftRedzoneMagic = 0xf1;
121229109Sedconst int kAsanStackMidRedzoneMagic = 0xf2;
122229109Sedconst int kAsanStackRightRedzoneMagic = 0xf3;
123229109Sedconst int kAsanStackPartialRedzoneMagic = 0xf4;
124229109Sedconst int kAsanStackAfterReturnMagic = 0xf5;
125245614Sandrewconst int kAsanInitializationOrderMagic = 0xf6;
126229109Sedconst int kAsanUserPoisonedMemoryMagic = 0xf7;
127276789Sdimconst int kAsanContiguousContainerOOBMagic = 0xfc;
128245614Sandrewconst int kAsanStackUseAfterScopeMagic = 0xf8;
129229109Sedconst int kAsanGlobalRedzoneMagic = 0xf9;
130229109Sedconst int kAsanInternalHeapMagic = 0xfe;
131276789Sdimconst int kAsanArrayCookieMagic = 0xac;
132276789Sdimconst int kAsanIntraObjectRedzone = 0xbb;
133276789Sdimconst int kAsanAllocaLeftMagic = 0xca;
134276789Sdimconst int kAsanAllocaRightMagic = 0xcb;
135229109Sed
136238901Sandrewstatic const uptr kCurrentStackFrameMagic = 0x41B58AB3;
137238901Sandrewstatic const uptr kRetiredStackFrameMagic = 0x45E0360E;
138229109Sed
139229109Sed}  // namespace __asan
140229109Sed
141229109Sed#endif  // ASAN_INTERNAL_H
142