15
15
#if SANITIZER_FREEBSD || SANITIZER_LINUX || SANITIZER_NETBSD || \
16
16
SANITIZER_SOLARIS
17
17
18
- #include " asan_interceptors.h "
19
- #include " asan_internal.h "
20
- #include " asan_premap_shadow.h "
21
- #include " asan_thread.h "
22
- #include " sanitizer_common/sanitizer_flags.h "
23
- #include " sanitizer_common/sanitizer_freebsd.h "
24
- #include " sanitizer_common/sanitizer_libc.h "
25
- #include " sanitizer_common/sanitizer_procmaps.h "
26
-
27
- #include < sys/time .h>
28
- #include < sys/resource .h>
29
- #include < sys/mman .h>
30
- # include < sys/syscall.h >
31
- #include < sys/types.h >
32
- #include < dlfcn.h >
33
- #include < fcntl.h >
34
- #include < limits.h >
35
- #include < pthread.h >
36
- #include < stdio.h >
37
- #include < unistd.h >
38
- #include < unwind.h >
39
-
40
- #if SANITIZER_FREEBSD
41
- #include < sys/link_elf.h>
42
- #endif
43
-
44
- #if SANITIZER_SOLARIS
45
- #include < link.h>
46
- #endif
47
-
48
- #if SANITIZER_ANDROID || SANITIZER_FREEBSD || SANITIZER_SOLARIS
49
- #include < ucontext.h>
50
- extern " C" void * _DYNAMIC;
51
- #elif SANITIZER_NETBSD
52
- #include < link_elf.h>
53
- #include < ucontext.h>
18
+ # include < dlfcn.h >
19
+ # include < fcntl.h >
20
+ # include < limits.h >
21
+ # include < pthread.h >
22
+ # include < stdio.h >
23
+ # include < sys/mman.h >
24
+ # include < sys/resource.h >
25
+ # include < sys/syscall.h >
26
+ # include < sys/time.h >
27
+ # include < sys/types .h>
28
+ # include < unistd .h>
29
+ # include < unwind .h>
30
+
31
+ # include " asan_interceptors.h "
32
+ # include " asan_internal.h "
33
+ # include " asan_premap_shadow.h "
34
+ # include " asan_thread.h "
35
+ # include " sanitizer_common/sanitizer_flags.h "
36
+ # include " sanitizer_common/sanitizer_freebsd.h "
37
+ # include " sanitizer_common/sanitizer_libc.h "
38
+ # include " sanitizer_common/sanitizer_procmaps.h "
39
+
40
+ # if SANITIZER_FREEBSD
41
+ # include < sys/link_elf.h>
42
+ # endif
43
+
44
+ # if SANITIZER_SOLARIS
45
+ # include < link.h>
46
+ # endif
47
+
48
+ # if SANITIZER_ANDROID || SANITIZER_FREEBSD || SANITIZER_SOLARIS
49
+ # include < ucontext.h>
50
+ extern " C" void * _DYNAMIC;
51
+ # elif SANITIZER_NETBSD
52
+ # include < link_elf.h>
53
+ # include < ucontext.h>
54
54
extern Elf_Dyn _DYNAMIC;
55
- #else
56
- #include < sys/ucontext .h>
57
- #include < link .h>
55
+ # else
56
+ # include < link .h>
57
+ # include < sys/ucontext .h>
58
58
extern ElfW (Dyn) _DYNAMIC[];
59
- #endif
59
+ # endif
60
60
61
61
// x86-64 FreeBSD 9.2 and older define 'ucontext_t' incorrectly in
62
62
// 32-bit mode.
63
- #if SANITIZER_FREEBSD && (SANITIZER_WORDSIZE == 32) && \
64
- __FreeBSD_version <= 902001 // v9.2
65
- #define ucontext_t xucontext_t
66
- #endif
63
+ # if SANITIZER_FREEBSD && (SANITIZER_WORDSIZE == 32) && \
64
+ __FreeBSD_version <= 902001 // v9.2
65
+ # define ucontext_t xucontext_t
66
+ # endif
67
67
68
68
typedef enum {
69
69
ASAN_RT_VERSION_UNDEFINED = 0 ,
@@ -74,21 +74,21 @@ typedef enum {
74
74
// FIXME: perhaps also store abi version here?
75
75
extern " C" {
76
76
SANITIZER_INTERFACE_ATTRIBUTE
77
- asan_rt_version_t __asan_rt_version;
77
+ asan_rt_version_t __asan_rt_version;
78
78
}
79
79
80
80
namespace __asan {
81
81
82
82
void InitializePlatformInterceptors () {}
83
83
void InitializePlatformExceptionHandlers () {}
84
- bool IsSystemHeapAddress (uptr addr) { return false ; }
84
+ bool IsSystemHeapAddress (uptr addr) { return false ; }
85
85
86
86
void *AsanDoesNotSupportStaticLinkage () {
87
87
// This will fail to link with -static.
88
88
return &_DYNAMIC;
89
89
}
90
90
91
- #if ASAN_PREMAP_SHADOW
91
+ # if ASAN_PREMAP_SHADOW
92
92
uptr FindPremappedShadowStart (uptr shadow_size_bytes) {
93
93
uptr granularity = GetMmapGranularity ();
94
94
uptr shadow_start = reinterpret_cast <uptr>(&__asan_shadow);
@@ -98,14 +98,14 @@ uptr FindPremappedShadowStart(uptr shadow_size_bytes) {
98
98
UnmapFromTo (shadow_start + shadow_size, shadow_start + premap_shadow_size);
99
99
return shadow_start;
100
100
}
101
- #endif
101
+ # endif
102
102
103
103
uptr FindDynamicShadowStart () {
104
104
uptr shadow_size_bytes = MemToShadowSize (kHighMemEnd );
105
- #if ASAN_PREMAP_SHADOW
105
+ # if ASAN_PREMAP_SHADOW
106
106
if (!PremapShadowFailed ())
107
107
return FindPremappedShadowStart (shadow_size_bytes);
108
- #endif
108
+ # endif
109
109
110
110
return MapDynamicShadow (shadow_size_bytes, ASAN_SHADOW_SCALE,
111
111
/* min_shadow_base_alignment*/ 0 , kHighMemEnd );
@@ -121,11 +121,11 @@ void FlushUnneededASanShadowMemory(uptr p, uptr size) {
121
121
ReleaseMemoryPagesToOS (MemToShadow (p), MemToShadow (p + size));
122
122
}
123
123
124
- #if SANITIZER_ANDROID
124
+ # if SANITIZER_ANDROID
125
125
// FIXME: should we do anything for Android?
126
126
void AsanCheckDynamicRTPrereqs () {}
127
127
void AsanCheckIncompatibleRT () {}
128
- #else
128
+ # else
129
129
static int FindFirstDSOCallback (struct dl_phdr_info *info, size_t size,
130
130
void *data) {
131
131
VReport (2 , " info->dlpi_name = %s\t info->dlpi_addr = %p\n " , info->dlpi_name ,
@@ -154,7 +154,7 @@ static int FindFirstDSOCallback(struct dl_phdr_info *info, size_t size,
154
154
155
155
static bool IsDynamicRTName (const char *libname) {
156
156
return internal_strstr (libname, " libclang_rt.asan" ) ||
157
- internal_strstr (libname, " libasan.so" );
157
+ internal_strstr (libname, " libasan.so" );
158
158
}
159
159
160
160
static void ReportIncompatibleRT () {
@@ -170,9 +170,10 @@ void AsanCheckDynamicRTPrereqs() {
170
170
const char *first_dso_name = nullptr ;
171
171
dl_iterate_phdr (FindFirstDSOCallback, &first_dso_name);
172
172
if (first_dso_name && first_dso_name[0 ] && !IsDynamicRTName (first_dso_name)) {
173
- Report (" ASan runtime does not come first in initial library list; "
174
- " you should either link runtime to your application or "
175
- " manually preload it with LD_PRELOAD.\n " );
173
+ Report (
174
+ " ASan runtime does not come first in initial library list; "
175
+ " you should either link runtime to your application or "
176
+ " manually preload it with LD_PRELOAD.\n " );
176
177
Die ();
177
178
}
178
179
}
@@ -190,13 +191,14 @@ void AsanCheckIncompatibleRT() {
190
191
// as early as possible, otherwise ASan interceptors could bind to
191
192
// the functions in dynamic ASan runtime instead of the functions in
192
193
// system libraries, causing crashes later in ASan initialization.
193
- MemoryMappingLayout proc_maps (/* cache_enabled*/ true );
194
+ MemoryMappingLayout proc_maps (/* cache_enabled*/ true );
194
195
char filename[PATH_MAX];
195
196
MemoryMappedSegment segment (filename, sizeof (filename));
196
197
while (proc_maps.Next (&segment)) {
197
198
if (IsDynamicRTName (segment.filename )) {
198
- Report (" Your application is linked against "
199
- " incompatible ASan runtimes.\n " );
199
+ Report (
200
+ " Your application is linked against "
201
+ " incompatible ASan runtimes.\n " );
200
202
Die ();
201
203
}
202
204
}
@@ -206,11 +208,11 @@ void AsanCheckIncompatibleRT() {
206
208
}
207
209
}
208
210
}
209
- #endif // SANITIZER_ANDROID
211
+ # endif // SANITIZER_ANDROID
210
212
211
213
# if ASAN_INTERCEPT_SWAPCONTEXT
212
214
void ReadContextStack (void *context, uptr *stack, uptr *ssize) {
213
- ucontext_t *ucp = (ucontext_t *)context;
215
+ ucontext_t *ucp = (ucontext_t *)context;
214
216
*stack = (uptr)ucp->uc_stack .ss_sp ;
215
217
*ssize = ucp->uc_stack .ss_size ;
216
218
}
@@ -222,9 +224,7 @@ void ResetContextStack(void *context) {
222
224
}
223
225
# endif // ASAN_INTERCEPT_SWAPCONTEXT
224
226
225
- void *AsanDlSymNext (const char *sym) {
226
- return dlsym (RTLD_NEXT, sym);
227
- }
227
+ void *AsanDlSymNext (const char *sym) { return dlsym (RTLD_NEXT, sym); }
228
228
229
229
bool HandleDlopenInit () {
230
230
// Not supported on this platform.
@@ -233,7 +233,7 @@ bool HandleDlopenInit() {
233
233
return false ;
234
234
}
235
235
236
- } // namespace __asan
236
+ } // namespace __asan
237
237
238
238
#endif // SANITIZER_FREEBSD || SANITIZER_LINUX || SANITIZER_NETBSD ||
239
239
// SANITIZER_SOLARIS
0 commit comments