]> git.proxmox.com Git - rustc.git/blame - src/compiler-rt/lib/asan/asan_internal.h
Imported Upstream version 1.6.0+dfsg1
[rustc.git] / src / compiler-rt / lib / asan / asan_internal.h
CommitLineData
1a4d82fc
JJ
1//===-- asan_internal.h -----------------------------------------*- C++ -*-===//
2//
3// The LLVM Compiler Infrastructure
4//
5// This file is distributed under the University of Illinois Open Source
6// License. See LICENSE.TXT for details.
7//
8//===----------------------------------------------------------------------===//
9//
10// This file is a part of AddressSanitizer, an address sanity checker.
11//
12// ASan-private header which defines various general utilities.
13//===----------------------------------------------------------------------===//
14#ifndef ASAN_INTERNAL_H
15#define ASAN_INTERNAL_H
16
17#include "asan_flags.h"
18#include "asan_interface_internal.h"
19#include "sanitizer_common/sanitizer_common.h"
20#include "sanitizer_common/sanitizer_internal_defs.h"
21#include "sanitizer_common/sanitizer_stacktrace.h"
22#include "sanitizer_common/sanitizer_libc.h"
23
1a4d82fc
JJ
24#if __has_feature(address_sanitizer) || defined(__SANITIZE_ADDRESS__)
25# error "The AddressSanitizer run-time should not be"
26 " instrumented by AddressSanitizer"
27#endif
28
29// Build-time configuration options.
30
31// If set, asan will intercept C++ exception api call(s).
32#ifndef ASAN_HAS_EXCEPTIONS
33# define ASAN_HAS_EXCEPTIONS 1
34#endif
35
36// If set, values like allocator chunk size, as well as defaults for some flags
37// will be changed towards less memory overhead.
38#ifndef ASAN_LOW_MEMORY
39#if SANITIZER_WORDSIZE == 32
40# define ASAN_LOW_MEMORY 1
41#else
42# define ASAN_LOW_MEMORY 0
43# endif
44#endif
45
1a4d82fc 46#ifndef ASAN_DYNAMIC
92a42be0
SL
47# ifdef PIC
48# define ASAN_DYNAMIC 1
49# else
50# define ASAN_DYNAMIC 0
51# endif
1a4d82fc
JJ
52#endif
53
54// All internal functions in asan reside inside the __asan namespace
55// to avoid namespace collisions with the user programs.
92a42be0 56// Separate namespace also makes it simpler to distinguish the asan run-time
1a4d82fc
JJ
57// functions from the instrumented user code in a profile.
58namespace __asan {
59
60class AsanThread;
61using __sanitizer::StackTrace;
62
63void AsanInitFromRtl();
64
65// asan_rtl.cc
66void NORETURN ShowStatsAndAbort();
67
1a4d82fc
JJ
68// asan_malloc_linux.cc / asan_malloc_mac.cc
69void ReplaceSystemMalloc();
70
71// asan_linux.cc / asan_mac.cc / asan_win.cc
72void *AsanDoesNotSupportStaticLinkage();
73void AsanCheckDynamicRTPrereqs();
74void AsanCheckIncompatibleRT();
75
92a42be0 76void AsanOnDeadlySignal(int, void *siginfo, void *context);
1a4d82fc 77
92a42be0 78void DisableReexec();
1a4d82fc 79void MaybeReexec();
1a4d82fc 80void ReadContextStack(void *context, uptr *stack, uptr *ssize);
1a4d82fc
JJ
81void StopInitOrderChecking();
82
83// Wrapper for TLS/TSD.
84void AsanTSDInit(void (*destructor)(void *tsd));
85void *AsanTSDGet();
86void AsanTSDSet(void *tsd);
87void PlatformTSDDtor(void *tsd);
88
89void AppendToErrorMessageBuffer(const char *buffer);
90
92a42be0
SL
91void *AsanDlSymNext(const char *sym);
92
93void ReserveShadowMemoryRange(uptr beg, uptr end, const char *name);
1a4d82fc 94
92a42be0 95// Platform-specific options.
1a4d82fc
JJ
96#if SANITIZER_MAC
97bool PlatformHasDifferentMemcpyAndMemmove();
98# define PLATFORM_HAS_DIFFERENT_MEMCPY_AND_MEMMOVE \
99 (PlatformHasDifferentMemcpyAndMemmove())
100#else
101# define PLATFORM_HAS_DIFFERENT_MEMCPY_AND_MEMMOVE true
102#endif // SANITIZER_MAC
103
104// Add convenient macro for interface functions that may be represented as
105// weak hooks.
106#define ASAN_MALLOC_HOOK(ptr, size) \
92a42be0 107 if (&__sanitizer_malloc_hook) __sanitizer_malloc_hook(ptr, size)
1a4d82fc 108#define ASAN_FREE_HOOK(ptr) \
92a42be0 109 if (&__sanitizer_free_hook) __sanitizer_free_hook(ptr)
1a4d82fc
JJ
110#define ASAN_ON_ERROR() \
111 if (&__asan_on_error) __asan_on_error()
112
113extern int asan_inited;
114// Used to avoid infinite recursion in __asan_init().
115extern bool asan_init_is_running;
116extern void (*death_callback)(void);
117
118// These magic values are written to shadow for better error reporting.
119const int kAsanHeapLeftRedzoneMagic = 0xfa;
120const int kAsanHeapRightRedzoneMagic = 0xfb;
121const int kAsanHeapFreeMagic = 0xfd;
122const int kAsanStackLeftRedzoneMagic = 0xf1;
123const int kAsanStackMidRedzoneMagic = 0xf2;
124const int kAsanStackRightRedzoneMagic = 0xf3;
125const int kAsanStackPartialRedzoneMagic = 0xf4;
126const int kAsanStackAfterReturnMagic = 0xf5;
127const int kAsanInitializationOrderMagic = 0xf6;
128const int kAsanUserPoisonedMemoryMagic = 0xf7;
129const int kAsanContiguousContainerOOBMagic = 0xfc;
130const int kAsanStackUseAfterScopeMagic = 0xf8;
131const int kAsanGlobalRedzoneMagic = 0xf9;
132const int kAsanInternalHeapMagic = 0xfe;
92a42be0
SL
133const int kAsanArrayCookieMagic = 0xac;
134const int kAsanIntraObjectRedzone = 0xbb;
135const int kAsanAllocaLeftMagic = 0xca;
136const int kAsanAllocaRightMagic = 0xcb;
1a4d82fc
JJ
137
138static const uptr kCurrentStackFrameMagic = 0x41B58AB3;
139static const uptr kRetiredStackFrameMagic = 0x45E0360E;
140
141} // namespace __asan
142
143#endif // ASAN_INTERNAL_H