OLD | NEW |
1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "base/allocator/partition_allocator/partition_alloc.h" | 5 #include "base/allocator/partition_allocator/partition_alloc.h" |
6 | 6 |
7 #include <stdlib.h> | 7 #include <stdlib.h> |
8 #include <string.h> | 8 #include <string.h> |
9 | 9 |
10 #include <memory> | 10 #include <memory> |
(...skipping 2070 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2081 CheckPageInCore(ptr1 - kPointerOffset + (kSystemPageSize * 2), false); | 2081 CheckPageInCore(ptr1 - kPointerOffset + (kSystemPageSize * 2), false); |
2082 CheckPageInCore(ptr1 - kPointerOffset + (kSystemPageSize * 3), false); | 2082 CheckPageInCore(ptr1 - kPointerOffset + (kSystemPageSize * 3), false); |
2083 | 2083 |
2084 EXPECT_FALSE(page->freelist_head); | 2084 EXPECT_FALSE(page->freelist_head); |
2085 | 2085 |
2086 PartitionFreeGeneric(generic_allocator.root(), ptr1); | 2086 PartitionFreeGeneric(generic_allocator.root(), ptr1); |
2087 PartitionFreeGeneric(generic_allocator.root(), ptr2); | 2087 PartitionFreeGeneric(generic_allocator.root(), ptr2); |
2088 } | 2088 } |
2089 } | 2089 } |
2090 | 2090 |
| 2091 TEST(PartitionAllocTest, ReallocMovesCookies) { |
| 2092 TestSetup(); |
| 2093 |
| 2094 // Resize so as to be sure to hit a "resize in place" case, and ensure that |
| 2095 // use of the entire result is compatible with the debug mode's cookies, even |
| 2096 // when the bucket size is large enough to span more than one partition page |
| 2097 // and we can track the "raw" size. See https://crbug.com/709271 |
| 2098 const size_t kSize = base::kMaxSystemPagesPerSlotSpan * base::kSystemPageSize; |
| 2099 void* ptr = |
| 2100 PartitionAllocGeneric(generic_allocator.root(), kSize + 1, type_name); |
| 2101 EXPECT_TRUE(ptr); |
| 2102 |
| 2103 memset(ptr, 0xbd, kSize + 1); |
| 2104 ptr = PartitionReallocGeneric(generic_allocator.root(), ptr, kSize + 2, |
| 2105 type_name); |
| 2106 EXPECT_TRUE(ptr); |
| 2107 |
| 2108 memset(ptr, 0xbd, kSize + 2); |
| 2109 PartitionFreeGeneric(generic_allocator.root(), ptr); |
| 2110 } |
| 2111 |
2091 } // namespace base | 2112 } // namespace base |
2092 | 2113 |
2093 #endif // !defined(MEMORY_TOOL_REPLACES_ALLOCATOR) | 2114 #endif // !defined(MEMORY_TOOL_REPLACES_ALLOCATOR) |
OLD | NEW |