OLD | NEW |
1 /* | 1 /* |
2 * Copyright (C) 2013 Google Inc. All rights reserved. | 2 * Copyright (C) 2013 Google Inc. All rights reserved. |
3 * | 3 * |
4 * Redistribution and use in source and binary forms, with or without | 4 * Redistribution and use in source and binary forms, with or without |
5 * modification, are permitted provided that the following conditions are | 5 * modification, are permitted provided that the following conditions are |
6 * met: | 6 * met: |
7 * | 7 * |
8 * * Redistributions of source code must retain the above copyright | 8 * * Redistributions of source code must retain the above copyright |
9 * notice, this list of conditions and the following disclaimer. | 9 * notice, this list of conditions and the following disclaimer. |
10 * * Redistributions in binary form must reproduce the above | 10 * * Redistributions in binary form must reproduce the above |
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
81 // - No double-free detection (tcmalloc has some but it may be only a detection | 81 // - No double-free detection (tcmalloc has some but it may be only a detection |
82 // and not a defense). | 82 // and not a defense). |
83 // - No randomness in freelist pointers. | 83 // - No randomness in freelist pointers. |
84 // - Per-object bucketing (instead of per-size) is mostly available at the API, | 84 // - Per-object bucketing (instead of per-size) is mostly available at the API, |
85 // but not used yet. | 85 // but not used yet. |
86 // - No randomness of freelist entries or bucket position. | 86 // - No randomness of freelist entries or bucket position. |
87 // - No specific protection against corruption of page header metadata. | 87 // - No specific protection against corruption of page header metadata. |
88 | 88 |
89 #include "wtf/Assertions.h" | 89 #include "wtf/Assertions.h" |
90 #include "wtf/FastMalloc.h" | 90 #include "wtf/FastMalloc.h" |
| 91 #include "wtf/PageAllocator.h" |
91 #include "wtf/SpinLock.h" | 92 #include "wtf/SpinLock.h" |
| 93 #include "wtf/UnusedParam.h" |
92 | 94 |
93 #if defined(MEMORY_TOOL_REPLACES_ALLOCATOR) | 95 #if defined(MEMORY_TOOL_REPLACES_ALLOCATOR) |
94 #include <stdlib.h> | 96 #include <stdlib.h> |
95 #endif | 97 #endif |
96 | 98 |
97 namespace WTF { | 99 namespace WTF { |
98 | 100 |
99 // Maximum size of a partition's mappings. 1GB. Note that the total amount of | 101 // Maximum size of a partition's mappings. 1GB. Note that the total amount of |
100 // bytes allocatable at the API will be smaller. This is because things like | 102 // bytes allocatable at the API will be smaller. This is because things like |
101 // guard pages, metadata, page headers and wasted space come out of the total. | 103 // guard pages, metadata, page headers and wasted space come out of the total. |
(...skipping 163 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
265 PartitionFreelistEntry* entry = static_cast<PartitionFreelistEntry*>(ptr); | 267 PartitionFreelistEntry* entry = static_cast<PartitionFreelistEntry*>(ptr); |
266 entry->next = partitionFreelistMask(page->freelistHead); | 268 entry->next = partitionFreelistMask(page->freelistHead); |
267 page->freelistHead = entry; | 269 page->freelistHead = entry; |
268 --page->numAllocatedSlots; | 270 --page->numAllocatedSlots; |
269 if (UNLIKELY(page->numAllocatedSlots <= 0)) | 271 if (UNLIKELY(page->numAllocatedSlots <= 0)) |
270 partitionFreeSlowPath(page); | 272 partitionFreeSlowPath(page); |
271 } | 273 } |
272 | 274 |
273 ALWAYS_INLINE bool partitionPointerIsValid(PartitionRoot* root, void* ptr) | 275 ALWAYS_INLINE bool partitionPointerIsValid(PartitionRoot* root, void* ptr) |
274 { | 276 { |
| 277 // On 32-bit systems, we have an optimization where we have a bitmap that |
| 278 // can instantly tell us if a pointer is in a super page or not. |
| 279 // It is a global bitmap instead of a per-partition bitmap but this is a |
| 280 // reasonable space vs. accuracy trade off. |
| 281 if (SuperPageBitmap::isAvailable()) |
| 282 return SuperPageBitmap::isPointerInSuperPage(ptr); |
| 283 |
| 284 // On 64-bit systems, we check the list of super page extents. Due to the |
| 285 // massive address space, we typically have a single extent. |
275 // Dominant case: the pointer is in the first extent, which grew without any
collision. | 286 // Dominant case: the pointer is in the first extent, which grew without any
collision. |
276 if (LIKELY(ptr >= root->firstExtent.superPageBase) && LIKELY(ptr < root->fir
stExtent.superPagesEnd)) | 287 if (LIKELY(ptr >= root->firstExtent.superPageBase) && LIKELY(ptr < root->fir
stExtent.superPagesEnd)) |
277 return true; | 288 return true; |
278 | 289 |
279 // Otherwise, scan through the extent list. | 290 // Otherwise, scan through the extent list. |
280 PartitionSuperPageExtentEntry* entry = root->firstExtent.next; | 291 PartitionSuperPageExtentEntry* entry = root->firstExtent.next; |
281 while (UNLIKELY(entry != 0)) { | 292 while (UNLIKELY(entry != 0)) { |
282 if (ptr >= entry->superPageBase && ptr < entry->superPagesEnd) | 293 if (ptr >= entry->superPageBase && ptr < entry->superPagesEnd) |
283 return true; | 294 return true; |
284 entry = entry->next; | 295 entry = entry->next; |
(...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
362 using WTF::PartitionRoot; | 373 using WTF::PartitionRoot; |
363 using WTF::partitionAllocInit; | 374 using WTF::partitionAllocInit; |
364 using WTF::partitionAllocShutdown; | 375 using WTF::partitionAllocShutdown; |
365 using WTF::partitionAlloc; | 376 using WTF::partitionAlloc; |
366 using WTF::partitionFree; | 377 using WTF::partitionFree; |
367 using WTF::partitionAllocGeneric; | 378 using WTF::partitionAllocGeneric; |
368 using WTF::partitionFreeGeneric; | 379 using WTF::partitionFreeGeneric; |
369 using WTF::partitionReallocGeneric; | 380 using WTF::partitionReallocGeneric; |
370 | 381 |
371 #endif // WTF_PartitionAlloc_h | 382 #endif // WTF_PartitionAlloc_h |
OLD | NEW |