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 27 matching lines...) Expand all Loading... | |
38 | 38 |
39 typedef HeapManagerInterface::HeapId HeapId; | 39 typedef HeapManagerInterface::HeapId HeapId; |
40 using heaps::LargeBlockHeap; | 40 using heaps::LargeBlockHeap; |
41 using heaps::ZebraBlockHeap; | 41 using heaps::ZebraBlockHeap; |
42 | 42 |
43 // For now, the overbudget size is always set to 20% of the size of the | 43 // For now, the overbudget size is always set to 20% of the size of the |
44 // quarantine. | 44 // quarantine. |
45 // TODO(georgesak): allow this to be changed through the parameters. | 45 // TODO(georgesak): allow this to be changed through the parameters. |
46 enum : uint32_t { kOverbudgetSizePercentage = 20 }; | 46 enum : uint32_t { kOverbudgetSizePercentage = 20 }; |
47 | 47 |
48 // The maximum allocation size that we can handle in SyzyAsan, this is | |
49 // constrained by the number of bits used to store the block size in the block | |
50 // header structure. | |
51 const size_t kMaxAllocSize = 0x8000000; | |
chrisha
2016/11/23 19:37:17
This should be part of block.h, and tied to a #def
Sébastien Marchand
2016/11/23 22:36:01
I've tried this but it doesn't seem to work, doing
chrisha
2016/11/24 17:23:22
Acknowledged.
| |
52 | |
48 // Return the position of the most significant bit in a 32 bit unsigned value. | 53 // Return the position of the most significant bit in a 32 bit unsigned value. |
49 size_t GetMSBIndex(size_t n) { | 54 size_t GetMSBIndex(size_t n) { |
50 // Algorithm taken from | 55 // Algorithm taken from |
51 // http://graphics.stanford.edu/~seander/bithacks.html#IntegerLog | 56 // http://graphics.stanford.edu/~seander/bithacks.html#IntegerLog |
52 size_t r = 0; | 57 size_t r = 0; |
53 size_t shift = 0; | 58 size_t shift = 0; |
54 r = (n > 0xFFFF) << 4; | 59 r = (n > 0xFFFF) << 4; |
55 n >>= r; | 60 n >>= r; |
56 shift = (n > 0xFF) << 3; | 61 shift = (n > 0xFF) << 3; |
57 n >>= shift; | 62 n >>= shift; |
(...skipping 111 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
169 heaps_.erase(heaps_.find(heap)); | 174 heaps_.erase(heaps_.find(heap)); |
170 } | 175 } |
171 | 176 |
172 return true; | 177 return true; |
173 } | 178 } |
174 | 179 |
175 void* BlockHeapManager::Allocate(HeapId heap_id, uint32_t bytes) { | 180 void* BlockHeapManager::Allocate(HeapId heap_id, uint32_t bytes) { |
176 DCHECK(initialized_); | 181 DCHECK(initialized_); |
177 DCHECK(IsValidHeapId(heap_id, false)); | 182 DCHECK(IsValidHeapId(heap_id, false)); |
178 | 183 |
184 // Prevent from trying to allocate a memory block bigger than what we can | |
185 // represent in the block header. | |
186 if (bytes > kMaxAllocSize) | |
187 return nullptr; | |
chrisha
2016/11/23 19:37:17
I'd just push this through to the underlying heap
Sébastien Marchand
2016/11/23 22:36:01
I think that this should live in block.cc::BlockPl
| |
188 | |
179 // Some allocations can pass through without instrumentation. | 189 // Some allocations can pass through without instrumentation. |
180 if (parameters_.allocation_guard_rate < 1.0 && | 190 if (parameters_.allocation_guard_rate < 1.0 && |
181 base::RandDouble() >= parameters_.allocation_guard_rate) { | 191 base::RandDouble() >= parameters_.allocation_guard_rate) { |
182 BlockHeapInterface* heap = GetHeapFromId(heap_id); | 192 BlockHeapInterface* heap = GetHeapFromId(heap_id); |
183 void* alloc = heap->Allocate(bytes); | 193 void* alloc = heap->Allocate(bytes); |
184 if ((heap->GetHeapFeatures() & | 194 if ((heap->GetHeapFeatures() & |
185 HeapInterface::kHeapReportsReservations) != 0) { | 195 HeapInterface::kHeapReportsReservations) != 0) { |
186 shadow_->Unpoison(alloc, bytes); | 196 shadow_->Unpoison(alloc, bytes); |
187 } | 197 } |
188 return alloc; | 198 return alloc; |
(...skipping 29 matching lines...) Expand all Loading... | |
218 alloc = heap->AllocateBlock( | 228 alloc = heap->AllocateBlock( |
219 bytes, | 229 bytes, |
220 0, | 230 0, |
221 parameters_.trailer_padding_size + sizeof(BlockTrailer), | 231 parameters_.trailer_padding_size + sizeof(BlockTrailer), |
222 &block_layout); | 232 &block_layout); |
223 if (alloc != nullptr) { | 233 if (alloc != nullptr) { |
224 heap_id = heaps[i]; | 234 heap_id = heaps[i]; |
225 break; | 235 break; |
226 } | 236 } |
227 } | 237 } |
228 | 238 |
chrisha
2016/11/24 17:23:22
If you're moving the logic to BlockPlanLayout, we
Sébastien Marchand
2016/11/25 02:38:21
Done.
| |
229 // The allocation can fail if we're out of memory. | 239 // The allocation can fail if we're out of memory. |
230 if (alloc == nullptr) | 240 if (alloc == nullptr) |
231 return nullptr; | 241 return nullptr; |
232 | 242 |
233 DCHECK_NE(static_cast<void*>(nullptr), alloc); | 243 DCHECK_NE(static_cast<void*>(nullptr), alloc); |
234 DCHECK_EQ(0u, reinterpret_cast<size_t>(alloc) % kShadowRatio); | 244 DCHECK_EQ(0u, reinterpret_cast<size_t>(alloc) % kShadowRatio); |
235 BlockInfo block = {}; | 245 BlockInfo block = {}; |
236 BlockInitialize(block_layout, alloc, &block); | 246 BlockInitialize(block_layout, alloc, &block); |
237 | 247 |
238 // Poison the redzones in the shadow memory as early as possible. | 248 // Poison the redzones in the shadow memory as early as possible. |
(...skipping 873 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1112 if (trailer_has_valid_heap_id) | 1122 if (trailer_has_valid_heap_id) |
1113 return block_info->trailer->heap_id; | 1123 return block_info->trailer->heap_id; |
1114 | 1124 |
1115 // Unfortunately, there's no way to know which heap this block belongs to. | 1125 // Unfortunately, there's no way to know which heap this block belongs to. |
1116 return 0; | 1126 return 0; |
1117 } | 1127 } |
1118 | 1128 |
1119 } // namespace heap_managers | 1129 } // namespace heap_managers |
1120 } // namespace asan | 1130 } // namespace asan |
1121 } // namespace agent | 1131 } // namespace agent |
OLD | NEW |