]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - contrib/compiler-rt/lib/asan/asan_activation.cc
Update mandoc to cvs snaphot from 20150302
[FreeBSD/FreeBSD.git] / contrib / compiler-rt / lib / asan / asan_activation.cc
1 //===-- asan_activation.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 // ASan activation/deactivation logic.
13 //===----------------------------------------------------------------------===//
14
15 #include "asan_activation.h"
16 #include "asan_allocator.h"
17 #include "asan_flags.h"
18 #include "asan_internal.h"
19 #include "sanitizer_common/sanitizer_flags.h"
20
21 namespace __asan {
22
23 static struct AsanDeactivatedFlags {
24   int quarantine_size;
25   int max_redzone;
26   int malloc_context_size;
27   bool poison_heap;
28   bool alloc_dealloc_mismatch;
29   bool allocator_may_return_null;
30 } asan_deactivated_flags;
31
32 static bool asan_is_deactivated;
33
34 void AsanStartDeactivated() {
35   VReport(1, "Deactivating ASan\n");
36   // Save flag values.
37   asan_deactivated_flags.quarantine_size = flags()->quarantine_size;
38   asan_deactivated_flags.max_redzone = flags()->max_redzone;
39   asan_deactivated_flags.poison_heap = flags()->poison_heap;
40   asan_deactivated_flags.malloc_context_size =
41       common_flags()->malloc_context_size;
42   asan_deactivated_flags.alloc_dealloc_mismatch =
43       flags()->alloc_dealloc_mismatch;
44   asan_deactivated_flags.allocator_may_return_null =
45       common_flags()->allocator_may_return_null;
46
47   flags()->quarantine_size = 0;
48   flags()->max_redzone = 16;
49   flags()->poison_heap = false;
50   common_flags()->malloc_context_size = 0;
51   flags()->alloc_dealloc_mismatch = false;
52   common_flags()->allocator_may_return_null = true;
53
54   asan_is_deactivated = true;
55 }
56
57 void AsanActivate() {
58   if (!asan_is_deactivated) return;
59   VReport(1, "Activating ASan\n");
60
61   // Restore flag values.
62   // FIXME: this is not atomic, and there may be other threads alive.
63   flags()->quarantine_size = asan_deactivated_flags.quarantine_size;
64   flags()->max_redzone = asan_deactivated_flags.max_redzone;
65   flags()->poison_heap = asan_deactivated_flags.poison_heap;
66   common_flags()->malloc_context_size =
67       asan_deactivated_flags.malloc_context_size;
68   flags()->alloc_dealloc_mismatch =
69       asan_deactivated_flags.alloc_dealloc_mismatch;
70   common_flags()->allocator_may_return_null =
71       asan_deactivated_flags.allocator_may_return_null;
72
73   ParseExtraActivationFlags();
74
75   ReInitializeAllocator();
76
77   asan_is_deactivated = false;
78   VReport(
79       1,
80       "quarantine_size %d, max_redzone %d, poison_heap %d, "
81       "malloc_context_size %d, alloc_dealloc_mismatch %d, "
82       "allocator_may_return_null %d\n",
83       flags()->quarantine_size, flags()->max_redzone, flags()->poison_heap,
84       common_flags()->malloc_context_size, flags()->alloc_dealloc_mismatch,
85       common_flags()->allocator_may_return_null);
86 }
87
88 }  // namespace __asan