1//===-- asan_activation.cc --------------------------------------*- C++ -*-===// 2// 3// This file is distributed under the University of Illinois Open Source 4// License. See LICENSE.TXT for details. 5// 6//===----------------------------------------------------------------------===// 7// 8// This file is a part of AddressSanitizer, an address sanity checker. 9// 10// ASan activation/deactivation logic. 11//===----------------------------------------------------------------------===// 12 13#include "asan_activation.h" 14#include "asan_allocator.h" 15#include "asan_flags.h" 16#include "asan_internal.h" 17#include "sanitizer_common/sanitizer_flags.h" 18 19namespace __asan { 20 21static struct AsanDeactivatedFlags { 22 int quarantine_size; 23 int max_redzone; 24 int malloc_context_size; 25 bool poison_heap; 26} asan_deactivated_flags; 27 28static bool asan_is_deactivated; 29 30void AsanStartDeactivated() { 31 VReport(1, "Deactivating ASan\n"); 32 // Save flag values. 33 asan_deactivated_flags.quarantine_size = flags()->quarantine_size; 34 asan_deactivated_flags.max_redzone = flags()->max_redzone; 35 asan_deactivated_flags.poison_heap = flags()->poison_heap; 36 asan_deactivated_flags.malloc_context_size = 37 common_flags()->malloc_context_size; 38 39 flags()->quarantine_size = 0; 40 flags()->max_redzone = 16; 41 flags()->poison_heap = false; 42 common_flags()->malloc_context_size = 0; 43 44 asan_is_deactivated = true; 45} 46 47void AsanActivate() { 48 if (!asan_is_deactivated) return; 49 VReport(1, "Activating ASan\n"); 50 51 // Restore flag values. 52 // FIXME: this is not atomic, and there may be other threads alive. 53 flags()->quarantine_size = asan_deactivated_flags.quarantine_size; 54 flags()->max_redzone = asan_deactivated_flags.max_redzone; 55 flags()->poison_heap = asan_deactivated_flags.poison_heap; 56 common_flags()->malloc_context_size = 57 asan_deactivated_flags.malloc_context_size; 58 59 ParseExtraActivationFlags(); 60 61 ReInitializeAllocator(); 62 63 asan_is_deactivated = false; 64 VReport( 65 1, 66 "quarantine_size %d, max_redzone %d, poison_heap %d, malloc_context_size " 67 "%d\n", 68 flags()->quarantine_size, flags()->max_redzone, flags()->poison_heap, 69 common_flags()->malloc_context_size); 70} 71 72} // namespace __asan 73