| OLD | NEW |
| 1 // Copyright 2014 Google Inc. All Rights Reserved. | 1 // Copyright 2014 Google Inc. All Rights Reserved. |
| 2 // | 2 // |
| 3 // Licensed under the Apache License, Version 2.0 (the "License"); | 3 // Licensed under the Apache License, Version 2.0 (the "License"); |
| 4 // you may not use this file except in compliance with the License. | 4 // you may not use this file except in compliance with the License. |
| 5 // You may obtain a copy of the License at | 5 // You may obtain a copy of the License at |
| 6 // | 6 // |
| 7 // http://www.apache.org/licenses/LICENSE-2.0 | 7 // http://www.apache.org/licenses/LICENSE-2.0 |
| 8 // | 8 // |
| 9 // Unless required by applicable law or agreed to in writing, software | 9 // Unless required by applicable law or agreed to in writing, software |
| 10 // distributed under the License is distributed on an "AS IS" BASIS, | 10 // distributed under the License is distributed on an "AS IS" BASIS, |
| (...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 75 stack_cache_(stack_cache), | 75 stack_cache_(stack_cache), |
| 76 memory_notifier_(memory_notifier), | 76 memory_notifier_(memory_notifier), |
| 77 initialized_(false), | 77 initialized_(false), |
| 78 process_heap_(nullptr), | 78 process_heap_(nullptr), |
| 79 process_heap_underlying_heap_(nullptr), | 79 process_heap_underlying_heap_(nullptr), |
| 80 process_heap_id_(0), | 80 process_heap_id_(0), |
| 81 zebra_block_heap_(nullptr), | 81 zebra_block_heap_(nullptr), |
| 82 zebra_block_heap_id_(0), | 82 zebra_block_heap_id_(0), |
| 83 large_block_heap_id_(0), | 83 large_block_heap_id_(0), |
| 84 locked_heaps_(nullptr), | 84 locked_heaps_(nullptr), |
| 85 enable_page_protections_(true), | 85 enable_page_protections_(true) { |
| 86 corrupt_block_registry_cache_(L"SyzyAsanCorruptBlocks") { | |
| 87 DCHECK_NE(static_cast<Shadow*>(nullptr), shadow); | 86 DCHECK_NE(static_cast<Shadow*>(nullptr), shadow); |
| 88 DCHECK_NE(static_cast<StackCaptureCache*>(nullptr), stack_cache); | 87 DCHECK_NE(static_cast<StackCaptureCache*>(nullptr), stack_cache); |
| 89 DCHECK_NE(static_cast<MemoryNotifierInterface*>(nullptr), memory_notifier); | 88 DCHECK_NE(static_cast<MemoryNotifierInterface*>(nullptr), memory_notifier); |
| 90 SetDefaultAsanParameters(¶meters_); | 89 SetDefaultAsanParameters(¶meters_); |
| 91 | 90 |
| 92 // Initialize the allocation-filter flag (using Thread Local Storage). | 91 // Initialize the allocation-filter flag (using Thread Local Storage). |
| 93 allocation_filter_flag_tls_ = ::TlsAlloc(); | 92 allocation_filter_flag_tls_ = ::TlsAlloc(); |
| 94 CHECK_NE(TLS_OUT_OF_INDEXES, allocation_filter_flag_tls_); | 93 CHECK_NE(TLS_OUT_OF_INDEXES, allocation_filter_flag_tls_); |
| 95 // And disable it by default. | 94 // And disable it by default. |
| 96 set_allocation_filter_flag(false); | 95 set_allocation_filter_flag(false); |
| 97 } | 96 } |
| 98 | 97 |
| 99 BlockHeapManager::~BlockHeapManager() { | 98 BlockHeapManager::~BlockHeapManager() { |
| 100 TearDownHeapManager(); | 99 TearDownHeapManager(); |
| 101 } | 100 } |
| 102 | 101 |
| 103 void BlockHeapManager::Init() { | 102 void BlockHeapManager::Init() { |
| 104 DCHECK(!initialized_); | 103 DCHECK(!initialized_); |
| 105 | 104 |
| 106 { | 105 { |
| 107 base::AutoLock lock(lock_); | 106 base::AutoLock lock(lock_); |
| 108 InitInternalHeap(); | 107 InitInternalHeap(); |
| 109 corrupt_block_registry_cache_.Init(); | 108 |
| 109 // Only create a registry cache if the registry is available. It is not |
| 110 // available in sandboxed Chrome renderer processes. |
| 111 if (RegistryCache::RegistryAvailable()) { |
| 112 corrupt_block_registry_cache_.reset( |
| 113 new RegistryCache(L"SyzyAsanCorruptBlocks")); |
| 114 corrupt_block_registry_cache_->Init(); |
| 115 } |
| 110 } | 116 } |
| 111 | 117 |
| 112 // This takes care of its own locking, as its reentrant. | 118 // This takes care of its own locking, as its reentrant. |
| 113 PropagateParameters(); | 119 PropagateParameters(); |
| 114 | 120 |
| 115 { | 121 { |
| 116 base::AutoLock lock(lock_); | 122 base::AutoLock lock(lock_); |
| 117 InitProcessHeap(); | 123 InitProcessHeap(); |
| 118 initialized_ = true; | 124 initialized_ = true; |
| 119 } | 125 } |
| (...skipping 825 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 945 DCHECK_NE(static_cast<const BlockInfo*>(nullptr), block_info); | 951 DCHECK_NE(static_cast<const BlockInfo*>(nullptr), block_info); |
| 946 | 952 |
| 947 if (!parameters_.prevent_duplicate_corruption_crashes) | 953 if (!parameters_.prevent_duplicate_corruption_crashes) |
| 948 return true; | 954 return true; |
| 949 | 955 |
| 950 const common::StackCapture* alloc_stack = block_info->header->alloc_stack; | 956 const common::StackCapture* alloc_stack = block_info->header->alloc_stack; |
| 951 StackId relative_alloc_stack_id = alloc_stack->relative_stack_id(); | 957 StackId relative_alloc_stack_id = alloc_stack->relative_stack_id(); |
| 952 | 958 |
| 953 // Look at the registry cache to see if an error has already been reported | 959 // Look at the registry cache to see if an error has already been reported |
| 954 // for this allocation stack trace, if so prevent from reporting another one. | 960 // for this allocation stack trace, if so prevent from reporting another one. |
| 955 if (corrupt_block_registry_cache_.DoesIdExist(relative_alloc_stack_id)) | 961 if (corrupt_block_registry_cache_.get()) { |
| 956 return false; | 962 if (corrupt_block_registry_cache_->DoesIdExist(relative_alloc_stack_id)) |
| 963 return false; |
| 957 | 964 |
| 958 // Update the corrupt block registry cache to prevent from crashing if we | 965 // Update the corrupt block registry cache to prevent from crashing if we |
| 959 // encounter a corrupt block that has the same allocation stack trace. | 966 // encounter a corrupt block that has the same allocation stack trace. |
| 960 corrupt_block_registry_cache_.AddOrUpdateStackId(relative_alloc_stack_id); | 967 corrupt_block_registry_cache_->AddOrUpdateStackId(relative_alloc_stack_id); |
| 968 } |
| 969 |
| 961 return true; | 970 return true; |
| 962 } | 971 } |
| 963 | 972 |
| 964 void BlockHeapManager::TrimOrScheduleIfNecessary( | 973 void BlockHeapManager::TrimOrScheduleIfNecessary( |
| 965 TrimStatus trim_status, | 974 TrimStatus trim_status, |
| 966 BlockQuarantineInterface* quarantine) { | 975 BlockQuarantineInterface* quarantine) { |
| 967 // If no trimming is required, nothing to do. | 976 // If no trimming is required, nothing to do. |
| 968 if (trim_status == TRIM_NOT_REQUIRED) | 977 if (trim_status == TRIM_NOT_REQUIRED) |
| 969 return; | 978 return; |
| 970 | 979 |
| (...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1011 | 1020 |
| 1012 // Create the thread and wait for it to start. | 1021 // Create the thread and wait for it to start. |
| 1013 base::AutoLock lock(deferred_free_thread_lock_); | 1022 base::AutoLock lock(deferred_free_thread_lock_); |
| 1014 deferred_free_thread_.reset(new DeferredFreeThread(deferred_free_callback)); | 1023 deferred_free_thread_.reset(new DeferredFreeThread(deferred_free_callback)); |
| 1015 deferred_free_thread_->Start(); | 1024 deferred_free_thread_->Start(); |
| 1016 } | 1025 } |
| 1017 | 1026 |
| 1018 } // namespace heap_managers | 1027 } // namespace heap_managers |
| 1019 } // namespace asan | 1028 } // namespace asan |
| 1020 } // namespace agent | 1029 } // namespace agent |
| OLD | NEW |