blob: 7a9b0d401e067857ad4906fd7b4f60355ffde366 [file] [log] [blame]
Kostya Serebryany019b76f2011-11-30 01:07:021//===-- asan_rtl.cc ---------------------------------------------*- 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// Main file of the ASan run-time library.
13//===----------------------------------------------------------------------===//
14#include "asan_allocator.h"
15#include "asan_interceptors.h"
16#include "asan_interface.h"
17#include "asan_internal.h"
18#include "asan_lock.h"
Kostya Serebryany019b76f2011-11-30 01:07:0219#include "asan_mapping.h"
Kostya Serebryanycd271f52012-01-05 00:44:3320#include "asan_procmaps.h"
Kostya Serebryany019b76f2011-11-30 01:07:0221#include "asan_stack.h"
22#include "asan_stats.h"
23#include "asan_thread.h"
24#include "asan_thread_registry.h"
25
Kostya Serebryany019b76f2011-11-30 01:07:0226namespace __asan {
27
28// -------------------------- Flags ------------------------- {{{1
29static const size_t kMallocContextSize = 30;
30static int FLAG_atexit;
31bool FLAG_fast_unwind = true;
32
33size_t FLAG_redzone; // power of two, >= 32
Kostya Serebryany019b76f2011-11-30 01:07:0234size_t FLAG_quarantine_size;
35int FLAG_demangle;
36bool FLAG_symbolize;
37int FLAG_v;
38int FLAG_debug;
39bool FLAG_poison_shadow;
40int FLAG_report_globals;
41size_t FLAG_malloc_context_size = kMallocContextSize;
42uintptr_t FLAG_large_malloc;
Kostya Serebryany019b76f2011-11-30 01:07:0243bool FLAG_handle_segv;
Kostya Serebryany019b76f2011-11-30 01:07:0244bool FLAG_replace_str;
45bool FLAG_replace_intrin;
46bool FLAG_replace_cfallocator; // Used on Mac only.
Kostya Serebryany019b76f2011-11-30 01:07:0247size_t FLAG_max_malloc_fill_size = 0;
48bool FLAG_use_fake_stack;
49int FLAG_exitcode = EXIT_FAILURE;
50bool FLAG_allow_user_poisoning;
51
52// -------------------------- Globals --------------------- {{{1
53int asan_inited;
54bool asan_init_is_running;
55
Kostya Serebryany019b76f2011-11-30 01:07:0256// -------------------------- Misc ---------------- {{{1
57void ShowStatsAndAbort() {
58 __asan_print_accumulated_stats();
Kostya Serebryanyedb4a8a2012-01-09 23:11:2659 AsanDie();
Kostya Serebryany019b76f2011-11-30 01:07:0260}
61
62static void PrintBytes(const char *before, uintptr_t *a) {
63 uint8_t *bytes = (uint8_t*)a;
64 size_t byte_num = (__WORDSIZE) / 8;
65 Printf("%s%p:", before, (uintptr_t)a);
66 for (size_t i = 0; i < byte_num; i++) {
67 Printf(" %lx%lx", bytes[i] >> 4, bytes[i] & 15);
68 }
69 Printf("\n");
70}
71
Kostya Serebryanyedb4a8a2012-01-09 23:11:2672size_t ReadFileToBuffer(const char *file_name, char **buff,
Kostya Serebryanycd271f52012-01-05 00:44:3373 size_t *buff_size, size_t max_len) {
Kostya Serebryany6c4bd802011-12-28 22:58:0174 const size_t kMinFileLen = kPageSize;
Kostya Serebryanyedb4a8a2012-01-09 23:11:2675 size_t read_len = 0;
Kostya Serebryany6c4bd802011-12-28 22:58:0176 *buff = 0;
Kostya Serebryanycd271f52012-01-05 00:44:3377 *buff_size = 0;
Kostya Serebryany6c4bd802011-12-28 22:58:0178 // The files we usually open are not seekable, so try different buffer sizes.
79 for (size_t size = kMinFileLen; size <= max_len; size *= 2) {
80 int fd = AsanOpenReadonly(file_name);
81 if (fd < 0) return -1;
Kostya Serebryanycd271f52012-01-05 00:44:3382 AsanUnmapOrDie(*buff, *buff_size);
Kostya Serebryany6c4bd802011-12-28 22:58:0183 *buff = (char*)AsanMmapSomewhereOrDie(size, __FUNCTION__);
Kostya Serebryanycd271f52012-01-05 00:44:3384 *buff_size = size;
Kostya Serebryany86d44922012-01-17 18:00:0785 // Read up to one page at a time.
86 read_len = 0;
87 bool reached_eof = false;
88 while (read_len + kPageSize <= size) {
89 size_t just_read = AsanRead(fd, *buff + read_len, kPageSize);
90 if (just_read == 0) {
91 reached_eof = true;
92 break;
93 }
94 read_len += just_read;
95 }
Kostya Serebryany6c4bd802011-12-28 22:58:0196 AsanClose(fd);
Kostya Serebryany86d44922012-01-17 18:00:0797 if (reached_eof) // We've read the whole file.
Kostya Serebryany6c4bd802011-12-28 22:58:0198 break;
99 }
100 return read_len;
101}
102
Kostya Serebryany019b76f2011-11-30 01:07:02103// ---------------------- mmap -------------------- {{{1
Kostya Serebryany6c4bd802011-12-28 22:58:01104void OutOfMemoryMessageAndDie(const char *mem_type, size_t size) {
Kostya Serebryany019b76f2011-11-30 01:07:02105 Report("ERROR: AddressSanitizer failed to allocate "
106 "0x%lx (%ld) bytes of %s\n",
107 size, size, mem_type);
Kostya Serebryany6c4bd802011-12-28 22:58:01108 PRINT_CURRENT_STACK();
109 ShowStatsAndAbort();
Kostya Serebryany019b76f2011-11-30 01:07:02110}
111
Kostya Serebryanya7720962011-12-28 23:28:54112// Reserve memory range [beg, end].
113static void ReserveShadowMemoryRange(uintptr_t beg, uintptr_t end) {
Kostya Serebryany019b76f2011-11-30 01:07:02114 CHECK((beg % kPageSize) == 0);
115 CHECK(((end + 1) % kPageSize) == 0);
Kostya Serebryanya7720962011-12-28 23:28:54116 size_t size = end - beg + 1;
117 void *res = AsanMmapFixedNoReserve(beg, size);
118 CHECK(res == (void*)beg && "ReserveShadowMemoryRange failed");
Kostya Serebryany019b76f2011-11-30 01:07:02119}
120
Kostya Serebryanye4bada22011-12-02 21:02:20121// ---------------------- LowLevelAllocator ------------- {{{1
122void *LowLevelAllocator::Allocate(size_t size) {
123 CHECK((size & (size - 1)) == 0 && "size must be a power of two");
124 if (allocated_end_ - allocated_current_ < size) {
125 size_t size_to_allocate = Max(size, kPageSize);
Kostya Serebryany6c4bd802011-12-28 22:58:01126 allocated_current_ =
127 (char*)AsanMmapSomewhereOrDie(size_to_allocate, __FUNCTION__);
Kostya Serebryanye4bada22011-12-02 21:02:20128 allocated_end_ = allocated_current_ + size_to_allocate;
Kostya Serebryany7fb33a32011-12-15 17:41:30129 PoisonShadow((uintptr_t)allocated_current_, size_to_allocate,
130 kAsanInternalHeapMagic);
Kostya Serebryanye4bada22011-12-02 21:02:20131 }
132 CHECK(allocated_end_ - allocated_current_ >= size);
133 void *res = allocated_current_;
134 allocated_current_ += size;
135 return res;
136}
137
Kostya Serebryany019b76f2011-11-30 01:07:02138// ---------------------- DescribeAddress -------------------- {{{1
139static bool DescribeStackAddress(uintptr_t addr, uintptr_t access_size) {
140 AsanThread *t = asanThreadRegistry().FindThreadByStackAddress(addr);
141 if (!t) return false;
142 const intptr_t kBufSize = 4095;
143 char buf[kBufSize];
144 uintptr_t offset = 0;
145 const char *frame_descr = t->GetFrameNameByAddr(addr, &offset);
146 // This string is created by the compiler and has the following form:
147 // "FunctioName n alloc_1 alloc_2 ... alloc_n"
148 // where alloc_i looks like "offset size len ObjectName ".
149 CHECK(frame_descr);
150 // Report the function name and the offset.
151 const char *name_end = real_strchr(frame_descr, ' ');
152 CHECK(name_end);
153 buf[0] = 0;
Kostya Serebryany65518012012-01-09 22:20:49154 internal_strncat(buf, frame_descr,
155 Min(kBufSize,
156 static_cast<intptr_t>(name_end - frame_descr)));
Kostya Serebryany019b76f2011-11-30 01:07:02157 Printf("Address %p is located at offset %ld "
158 "in frame <%s> of T%d's stack:\n",
159 addr, offset, buf, t->tid());
160 // Report the number of stack objects.
161 char *p;
162 size_t n_objects = strtol(name_end, &p, 10);
163 CHECK(n_objects > 0);
164 Printf(" This frame has %ld object(s):\n", n_objects);
165 // Report all objects in this frame.
166 for (size_t i = 0; i < n_objects; i++) {
167 size_t beg, size;
168 intptr_t len;
169 beg = strtol(p, &p, 10);
170 size = strtol(p, &p, 10);
171 len = strtol(p, &p, 10);
172 if (beg <= 0 || size <= 0 || len < 0 || *p != ' ') {
173 Printf("AddressSanitizer can't parse the stack frame descriptor: |%s|\n",
174 frame_descr);
175 break;
176 }
177 p++;
178 buf[0] = 0;
Kostya Serebryany65518012012-01-09 22:20:49179 internal_strncat(buf, p, Min(kBufSize, len));
Kostya Serebryany019b76f2011-11-30 01:07:02180 p += len;
181 Printf(" [%ld, %ld) '%s'\n", beg, beg + size, buf);
182 }
183 Printf("HINT: this may be a false positive if your program uses "
184 "some custom stack unwind mechanism\n"
185 " (longjmp and C++ exceptions *are* supported)\n");
186 t->summary()->Announce();
187 return true;
188}
189
190__attribute__((noinline))
191static void DescribeAddress(uintptr_t addr, uintptr_t access_size) {
192 // Check if this is a global.
193 if (DescribeAddrIfGlobal(addr))
194 return;
195
196 if (DescribeStackAddress(addr, access_size))
197 return;
198
199 // finally, check if this is a heap.
200 DescribeHeapAddress(addr, access_size);
201}
202
203// -------------------------- Run-time entry ------------------- {{{1
Kostya Serebryany019b76f2011-11-30 01:07:02204// exported functions
Kostya Serebryany46c70d32011-12-28 00:59:39205#define ASAN_REPORT_ERROR(type, is_write, size) \
206extern "C" void __asan_report_ ## type ## size(uintptr_t addr) \
207 __attribute__((visibility("default"))) __attribute__((noinline)); \
208extern "C" void __asan_report_ ## type ## size(uintptr_t addr) { \
209 GET_BP_PC_SP; \
210 __asan_report_error(pc, bp, sp, addr, is_write, size); \
Kostya Serebryany019b76f2011-11-30 01:07:02211}
212
213ASAN_REPORT_ERROR(load, false, 1)
214ASAN_REPORT_ERROR(load, false, 2)
215ASAN_REPORT_ERROR(load, false, 4)
216ASAN_REPORT_ERROR(load, false, 8)
217ASAN_REPORT_ERROR(load, false, 16)
218ASAN_REPORT_ERROR(store, true, 1)
219ASAN_REPORT_ERROR(store, true, 2)
220ASAN_REPORT_ERROR(store, true, 4)
221ASAN_REPORT_ERROR(store, true, 8)
222ASAN_REPORT_ERROR(store, true, 16)
223
224// Force the linker to keep the symbols for various ASan interface functions.
225// We want to keep those in the executable in order to let the instrumented
226// dynamic libraries access the symbol even if it is not used by the executable
227// itself. This should help if the build system is removing dead code at link
228// time.
Kostya Serebryany46c70d32011-12-28 00:59:39229static void force_interface_symbols() {
Kostya Serebryany019b76f2011-11-30 01:07:02230 volatile int fake_condition = 0; // prevent dead condition elimination.
231 if (fake_condition) {
232 __asan_report_load1(NULL);
233 __asan_report_load2(NULL);
234 __asan_report_load4(NULL);
235 __asan_report_load8(NULL);
236 __asan_report_load16(NULL);
237 __asan_report_store1(NULL);
238 __asan_report_store2(NULL);
239 __asan_report_store4(NULL);
240 __asan_report_store8(NULL);
241 __asan_report_store16(NULL);
242 __asan_register_global(0, 0, NULL);
243 __asan_register_globals(NULL, 0);
Kostya Serebryanyd2d043b2011-12-28 23:35:46244 __asan_unregister_globals(NULL, 0);
Kostya Serebryany019b76f2011-11-30 01:07:02245 }
246}
247
248// -------------------------- Init ------------------- {{{1
249static int64_t IntFlagValue(const char *flags, const char *flag,
250 int64_t default_val) {
251 if (!flags) return default_val;
Kostya Serebryany65518012012-01-09 22:20:49252 const char *str = internal_strstr(flags, flag);
Kostya Serebryany019b76f2011-11-30 01:07:02253 if (!str) return default_val;
254 return atoll(str + internal_strlen(flag));
255}
256
257static void asan_atexit() {
258 Printf("AddressSanitizer exit stats:\n");
259 __asan_print_accumulated_stats();
260}
261
262void CheckFailed(const char *cond, const char *file, int line) {
Kostya Serebryany5be458c2012-01-09 19:18:27263 Report("CHECK failed: %s at %s:%d\n", cond, file, line);
Kostya Serebryany019b76f2011-11-30 01:07:02264 PRINT_CURRENT_STACK();
265 ShowStatsAndAbort();
266}
267
268} // namespace __asan
269
Kostya Serebryany9fd01e52012-01-09 18:53:15270// ---------------------- Interface ---------------- {{{1
Kostya Serebryany019b76f2011-11-30 01:07:02271using namespace __asan; // NOLINT
272
Kostya Serebryany019b76f2011-11-30 01:07:02273int __asan_set_error_exit_code(int exit_code) {
274 int old = FLAG_exitcode;
275 FLAG_exitcode = exit_code;
276 return old;
277}
278
279void __asan_report_error(uintptr_t pc, uintptr_t bp, uintptr_t sp,
280 uintptr_t addr, bool is_write, size_t access_size) {
281 // Do not print more than one report, otherwise they will mix up.
282 static int num_calls = 0;
283 if (AtomicInc(&num_calls) > 1) return;
284
285 Printf("=================================================================\n");
286 const char *bug_descr = "unknown-crash";
287 if (AddrIsInMem(addr)) {
288 uint8_t *shadow_addr = (uint8_t*)MemToShadow(addr);
Kostya Serebryanyf0d799a2011-12-07 21:30:20289 // If we are accessing 16 bytes, look at the second shadow byte.
290 if (*shadow_addr == 0 && access_size > SHADOW_GRANULARITY)
291 shadow_addr++;
292 // If we are in the partial right redzone, look at the next shadow byte.
293 if (*shadow_addr > 0 && *shadow_addr < 128)
294 shadow_addr++;
295 switch (*shadow_addr) {
Kostya Serebryany019b76f2011-11-30 01:07:02296 case kAsanHeapLeftRedzoneMagic:
297 case kAsanHeapRightRedzoneMagic:
298 bug_descr = "heap-buffer-overflow";
299 break;
300 case kAsanHeapFreeMagic:
301 bug_descr = "heap-use-after-free";
302 break;
303 case kAsanStackLeftRedzoneMagic:
304 bug_descr = "stack-buffer-underflow";
305 break;
306 case kAsanStackMidRedzoneMagic:
307 case kAsanStackRightRedzoneMagic:
308 case kAsanStackPartialRedzoneMagic:
309 bug_descr = "stack-buffer-overflow";
310 break;
311 case kAsanStackAfterReturnMagic:
312 bug_descr = "stack-use-after-return";
313 break;
314 case kAsanUserPoisonedMemoryMagic:
315 bug_descr = "use-after-poison";
316 break;
317 case kAsanGlobalRedzoneMagic:
318 bug_descr = "global-buffer-overflow";
319 break;
320 }
321 }
322
Kostya Serebryany72fde372011-12-09 01:49:31323 AsanThread *curr_thread = asanThreadRegistry().GetCurrent();
324 int curr_tid = asanThreadRegistry().GetCurrentTidOrMinusOne();
325
326 if (curr_thread) {
327 // We started reporting an error message. Stop using the fake stack
328 // in case we will call an instrumented function from a symbolizer.
329 curr_thread->fake_stack().StopUsingFakeStack();
330 }
331
Kostya Serebryany019b76f2011-11-30 01:07:02332 Report("ERROR: AddressSanitizer %s on address "
333 "%p at pc 0x%lx bp 0x%lx sp 0x%lx\n",
334 bug_descr, addr, pc, bp, sp);
335
336 Printf("%s of size %d at %p thread T%d\n",
337 access_size ? (is_write ? "WRITE" : "READ") : "ACCESS",
Kostya Serebryany72fde372011-12-09 01:49:31338 access_size, addr, curr_tid);
Kostya Serebryany019b76f2011-11-30 01:07:02339
340 if (FLAG_debug) {
341 PrintBytes("PC: ", (uintptr_t*)pc);
342 }
343
344 GET_STACK_TRACE_WITH_PC_AND_BP(kStackTraceMax,
345 false, // FLAG_fast_unwind,
346 pc, bp);
347 stack.PrintStack();
348
349 CHECK(AddrIsInMem(addr));
350
351 DescribeAddress(addr, access_size);
352
353 uintptr_t shadow_addr = MemToShadow(addr);
354 Report("ABORTING\n");
355 __asan_print_accumulated_stats();
356 Printf("Shadow byte and word:\n");
357 Printf(" %p: %x\n", shadow_addr, *(unsigned char*)shadow_addr);
358 uintptr_t aligned_shadow = shadow_addr & ~(kWordSize - 1);
359 PrintBytes(" ", (uintptr_t*)(aligned_shadow));
360 Printf("More shadow bytes:\n");
361 PrintBytes(" ", (uintptr_t*)(aligned_shadow-4*kWordSize));
362 PrintBytes(" ", (uintptr_t*)(aligned_shadow-3*kWordSize));
363 PrintBytes(" ", (uintptr_t*)(aligned_shadow-2*kWordSize));
364 PrintBytes(" ", (uintptr_t*)(aligned_shadow-1*kWordSize));
365 PrintBytes("=>", (uintptr_t*)(aligned_shadow+0*kWordSize));
366 PrintBytes(" ", (uintptr_t*)(aligned_shadow+1*kWordSize));
367 PrintBytes(" ", (uintptr_t*)(aligned_shadow+2*kWordSize));
368 PrintBytes(" ", (uintptr_t*)(aligned_shadow+3*kWordSize));
369 PrintBytes(" ", (uintptr_t*)(aligned_shadow+4*kWordSize));
Kostya Serebryanyedb4a8a2012-01-09 23:11:26370 AsanDie();
Kostya Serebryany019b76f2011-11-30 01:07:02371}
372
373void __asan_init() {
374 if (asan_inited) return;
375 asan_init_is_running = true;
376
377 // Make sure we are not statically linked.
378 AsanDoesNotSupportStaticLinkage();
379
380 // flags
Alexander Potapenko553c2082012-01-13 12:59:48381 const char *options = AsanGetEnv("ASAN_OPTIONS");
Kostya Serebryany019b76f2011-11-30 01:07:02382 FLAG_malloc_context_size =
383 IntFlagValue(options, "malloc_context_size=", kMallocContextSize);
384 CHECK(FLAG_malloc_context_size <= kMallocContextSize);
385
386 FLAG_max_malloc_fill_size =
387 IntFlagValue(options, "max_malloc_fill_size=", 0);
388
389 FLAG_v = IntFlagValue(options, "verbosity=", 0);
390
391 FLAG_redzone = IntFlagValue(options, "redzone=", 128);
392 CHECK(FLAG_redzone >= 32);
393 CHECK((FLAG_redzone & (FLAG_redzone - 1)) == 0);
394
395 FLAG_atexit = IntFlagValue(options, "atexit=", 0);
396 FLAG_poison_shadow = IntFlagValue(options, "poison_shadow=", 1);
397 FLAG_report_globals = IntFlagValue(options, "report_globals=", 1);
Kostya Serebryanyb50a5392011-12-08 18:30:42398 FLAG_handle_segv = IntFlagValue(options, "handle_segv=", ASAN_NEEDS_SEGV);
Kostya Serebryany019b76f2011-11-30 01:07:02399 FLAG_symbolize = IntFlagValue(options, "symbolize=", 1);
400 FLAG_demangle = IntFlagValue(options, "demangle=", 1);
401 FLAG_debug = IntFlagValue(options, "debug=", 0);
402 FLAG_replace_cfallocator = IntFlagValue(options, "replace_cfallocator=", 1);
403 FLAG_fast_unwind = IntFlagValue(options, "fast_unwind=", 1);
Kostya Serebryany019b76f2011-11-30 01:07:02404 FLAG_replace_str = IntFlagValue(options, "replace_str=", 1);
Kostya Serebryany76eca5e2011-12-28 19:55:30405 FLAG_replace_intrin = IntFlagValue(options, "replace_intrin=", 1);
Kostya Serebryany019b76f2011-11-30 01:07:02406 FLAG_use_fake_stack = IntFlagValue(options, "use_fake_stack=", 1);
407 FLAG_exitcode = IntFlagValue(options, "exitcode=", EXIT_FAILURE);
408 FLAG_allow_user_poisoning = IntFlagValue(options,
409 "allow_user_poisoning=", 1);
410
411 if (FLAG_atexit) {
412 atexit(asan_atexit);
413 }
414
415 FLAG_quarantine_size =
416 IntFlagValue(options, "quarantine_size=", 1UL << 28);
417
418 // interceptors
419 InitializeAsanInterceptors();
420
421 ReplaceSystemMalloc();
Kostya Serebryany5be458c2012-01-09 19:18:27422 InstallSignalHandlers();
Kostya Serebryany019b76f2011-11-30 01:07:02423
424 if (FLAG_v) {
425 Printf("|| `[%p, %p]` || HighMem ||\n", kHighMemBeg, kHighMemEnd);
426 Printf("|| `[%p, %p]` || HighShadow ||\n",
427 kHighShadowBeg, kHighShadowEnd);
428 Printf("|| `[%p, %p]` || ShadowGap ||\n",
429 kShadowGapBeg, kShadowGapEnd);
430 Printf("|| `[%p, %p]` || LowShadow ||\n",
431 kLowShadowBeg, kLowShadowEnd);
432 Printf("|| `[%p, %p]` || LowMem ||\n", kLowMemBeg, kLowMemEnd);
433 Printf("MemToShadow(shadow): %p %p %p %p\n",
434 MEM_TO_SHADOW(kLowShadowBeg),
435 MEM_TO_SHADOW(kLowShadowEnd),
436 MEM_TO_SHADOW(kHighShadowBeg),
437 MEM_TO_SHADOW(kHighShadowEnd));
438 Printf("red_zone=%ld\n", FLAG_redzone);
439 Printf("malloc_context_size=%ld\n", (int)FLAG_malloc_context_size);
440 Printf("fast_unwind=%d\n", (int)FLAG_fast_unwind);
441
442 Printf("SHADOW_SCALE: %lx\n", SHADOW_SCALE);
443 Printf("SHADOW_GRANULARITY: %lx\n", SHADOW_GRANULARITY);
444 Printf("SHADOW_OFFSET: %lx\n", SHADOW_OFFSET);
445 CHECK(SHADOW_SCALE >= 3 && SHADOW_SCALE <= 7);
446 }
447
448 if (__WORDSIZE == 64) {
449 // Disable core dumper -- it makes little sense to dump 16T+ core.
Kostya Serebryany2b087182012-01-06 02:12:25450 AsanDisableCoreDumper();
Kostya Serebryany019b76f2011-11-30 01:07:02451 }
452
453 {
Kostya Serebryany5be458c2012-01-09 19:18:27454 if (kLowShadowBeg != kLowShadowEnd) {
455 // mmap the low shadow plus one page.
456 ReserveShadowMemoryRange(kLowShadowBeg - kPageSize, kLowShadowEnd);
Kostya Serebryany019b76f2011-11-30 01:07:02457 }
Kostya Serebryany5be458c2012-01-09 19:18:27458 // mmap the high shadow.
459 ReserveShadowMemoryRange(kHighShadowBeg, kHighShadowEnd);
Kostya Serebryany019b76f2011-11-30 01:07:02460 // protect the gap
Kostya Serebryanya7720962011-12-28 23:28:54461 void *prot = AsanMprotect(kShadowGapBeg, kShadowGapEnd - kShadowGapBeg + 1);
462 CHECK(prot == (void*)kShadowGapBeg);
Kostya Serebryany019b76f2011-11-30 01:07:02463 }
464
465 // On Linux AsanThread::ThreadStart() calls malloc() that's why asan_inited
466 // should be set to 1 prior to initializing the threads.
467 asan_inited = 1;
468 asan_init_is_running = false;
469
470 asanThreadRegistry().Init();
471 asanThreadRegistry().GetMain()->ThreadStart();
Kostya Serebryany46c70d32011-12-28 00:59:39472 force_interface_symbols(); // no-op.
Kostya Serebryany019b76f2011-11-30 01:07:02473
474 if (FLAG_v) {
Kostya Serebryany5dfa4da2011-12-01 21:40:52475 Report("AddressSanitizer Init done\n");
Kostya Serebryany019b76f2011-11-30 01:07:02476 }
477}
Evgeniy Stepanov837fe5b2012-01-11 08:17:19478
479#if defined(ASAN_USE_PREINIT_ARRAY)
480// On Linux, we force __asan_init to be called before anyone else
481// by placing it into .preinit_array section.
482// FIXME: do we have anything like this on Mac?
483__attribute__((section(".preinit_array")))
484 typeof(__asan_init) *__asan_preinit =__asan_init;
485#endif