1 //===-- asan_activation.cc --------------------------------------*- C++ -*-===//
3 // The LLVM Compiler Infrastructure
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
10 // This file is a part of AddressSanitizer, an address sanity checker.
12 // ASan activation/deactivation logic.
13 //===----------------------------------------------------------------------===//
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"
23 static struct AsanDeactivatedFlags {
26 int malloc_context_size;
28 bool alloc_dealloc_mismatch;
29 bool allocator_may_return_null;
30 } asan_deactivated_flags;
32 static bool asan_is_deactivated;
34 void AsanStartDeactivated() {
35 VReport(1, "Deactivating ASan\n");
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;
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;
54 asan_is_deactivated = true;
58 if (!asan_is_deactivated) return;
59 VReport(1, "Activating ASan\n");
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;
73 ParseExtraActivationFlags();
75 ReInitializeAllocator();
77 asan_is_deactivated = false;
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);