| 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 1302 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1313 EXPECT_DEATH(partitionFreeGeneric(genericAllocator.root(), ptr), ""); | 1313 EXPECT_DEATH(partitionFreeGeneric(genericAllocator.root(), ptr), ""); |
| 1314 | 1314 |
| 1315 TestShutdown(); | 1315 TestShutdown(); |
| 1316 } | 1316 } |
| 1317 | 1317 |
| 1318 // Check that guard pages are present where expected. | 1318 // Check that guard pages are present where expected. |
| 1319 TEST(PartitionAllocDeathTest, GuardPages) | 1319 TEST(PartitionAllocDeathTest, GuardPages) |
| 1320 { | 1320 { |
| 1321 TestSetup(); | 1321 TestSetup(); |
| 1322 | 1322 |
| 1323 // This large size will result in a direct mapped allocation with guard | 1323 // partitionAlloc adds kPartitionPageSize to the requested size |
| 1324 // pages at either end. | 1324 // (for metadata), and then rounds that size to kPageAllocationGranularity. |
| 1325 size_t size = (kGenericMaxBucketed + kSystemPageSize) - kExtraAllocSize; | 1325 // To be able to reliably write one past a direct allocation, choose a size |
| 1326 // that's |
| 1327 // a) larger than kGenericMaxBucketed (to make the allocation direct) |
| 1328 // b) aligned at kPageAllocationGranularity boundaries after |
| 1329 // kPartitionPageSize has been added to it. |
| 1330 // (On 32-bit, partitionAlloc adds another kSystemPageSize to the |
| 1331 // allocation size before rounding, but there it marks the memory right |
| 1332 // after size as inaccessible, so it's fine to write 1 past the size we |
| 1333 // hand to partitionAlloc and we don't need to worry about allocation |
| 1334 // granularities.) |
| 1335 #define ALIGN(N, A) (((N) + (A) - 1) / (A) * (A)) |
| 1336 const int kSize = ALIGN(kGenericMaxBucketed + 1 + kPartitionPageSize, kPageA
llocationGranularity) - kPartitionPageSize; |
| 1337 #undef ALIGN |
| 1338 static_assert(kSize > kGenericMaxBucketed, "allocation not large enough for
direct allocation"); |
| 1339 size_t size = kSize - kExtraAllocSize; |
| 1326 void* ptr = partitionAllocGeneric(genericAllocator.root(), size); | 1340 void* ptr = partitionAllocGeneric(genericAllocator.root(), size); |
| 1341 |
| 1327 EXPECT_TRUE(ptr); | 1342 EXPECT_TRUE(ptr); |
| 1328 char* charPtr = reinterpret_cast<char*>(ptr) - kPointerOffset; | 1343 char* charPtr = reinterpret_cast<char*>(ptr) - kPointerOffset; |
| 1329 | 1344 |
| 1330 EXPECT_DEATH(*(charPtr - 1) = 'A', ""); | 1345 EXPECT_DEATH(*(charPtr - 1) = 'A', ""); |
| 1331 EXPECT_DEATH(*(charPtr + size + kExtraAllocSize) = 'A', ""); | 1346 EXPECT_DEATH(*(charPtr + size + kExtraAllocSize) = 'A', ""); |
| 1332 | 1347 |
| 1333 partitionFreeGeneric(genericAllocator.root(), ptr); | 1348 partitionFreeGeneric(genericAllocator.root(), ptr); |
| 1334 | 1349 |
| 1335 TestShutdown(); | 1350 TestShutdown(); |
| 1336 } | 1351 } |
| (...skipping 605 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1942 EXPECT_EQ(32u, countLeadingZerosSizet(0u)); | 1957 EXPECT_EQ(32u, countLeadingZerosSizet(0u)); |
| 1943 EXPECT_EQ(31u, countLeadingZerosSizet(1u)); | 1958 EXPECT_EQ(31u, countLeadingZerosSizet(1u)); |
| 1944 EXPECT_EQ(1u, countLeadingZerosSizet(1u << 30)); | 1959 EXPECT_EQ(1u, countLeadingZerosSizet(1u << 30)); |
| 1945 EXPECT_EQ(0u, countLeadingZerosSizet(1u << 31)); | 1960 EXPECT_EQ(0u, countLeadingZerosSizet(1u << 31)); |
| 1946 #endif | 1961 #endif |
| 1947 } | 1962 } |
| 1948 | 1963 |
| 1949 } // namespace WTF | 1964 } // namespace WTF |
| 1950 | 1965 |
| 1951 #endif // !defined(MEMORY_TOOL_REPLACES_ALLOCATOR) | 1966 #endif // !defined(MEMORY_TOOL_REPLACES_ALLOCATOR) |
| OLD | NEW |