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 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
67 } | 67 } |
68 | 68 |
69 #if !defined(ARCH_CPU_64_BITS) || defined(OS_POSIX) | 69 #if !defined(ARCH_CPU_64_BITS) || defined(OS_POSIX) |
70 bool SetAddressSpaceLimit() { | 70 bool SetAddressSpaceLimit() { |
71 #if !defined(ARCH_CPU_64_BITS) | 71 #if !defined(ARCH_CPU_64_BITS) |
72 // 32 bits => address space is limited already. | 72 // 32 bits => address space is limited already. |
73 return true; | 73 return true; |
74 #elif defined(OS_POSIX) && !defined(OS_MACOSX) | 74 #elif defined(OS_POSIX) && !defined(OS_MACOSX) |
75 // Mac will accept RLIMIT_AS changes but it is not enforced. | 75 // Mac will accept RLIMIT_AS changes but it is not enforced. |
76 // See https://crbug.com/435269 and rdar://17576114. | 76 // See https://crbug.com/435269 and rdar://17576114. |
77 const size_t kAddressSpaceLimit = static_cast<size_t>(4096) * 1024 * 1024; | 77 // Note: this number must be not less than 6 GB, because with |
| 78 // sanitizer_coverage_flags=edge, it reserves > 5 GB of address |
| 79 // space, see https://crbug.com/674665. |
| 80 const size_t kAddressSpaceLimit = static_cast<size_t>(6144) * 1024 * 1024; |
78 struct rlimit limit; | 81 struct rlimit limit; |
79 if (getrlimit(RLIMIT_AS, &limit) != 0) | 82 if (getrlimit(RLIMIT_AS, &limit) != 0) |
80 return false; | 83 return false; |
81 if (limit.rlim_cur == RLIM_INFINITY || limit.rlim_cur > kAddressSpaceLimit) { | 84 if (limit.rlim_cur == RLIM_INFINITY || limit.rlim_cur > kAddressSpaceLimit) { |
82 limit.rlim_cur = kAddressSpaceLimit; | 85 limit.rlim_cur = kAddressSpaceLimit; |
83 if (setrlimit(RLIMIT_AS, &limit) != 0) | 86 if (setrlimit(RLIMIT_AS, &limit) != 0) |
84 return false; | 87 return false; |
85 } | 88 } |
86 return true; | 89 return true; |
87 #else | 90 #else |
(...skipping 1204 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1292 | 1295 |
1293 partitionFreeGeneric(genericAllocator.root(), ptrs); | 1296 partitionFreeGeneric(genericAllocator.root(), ptrs); |
1294 | 1297 |
1295 EXPECT_TRUE(ClearAddressSpaceLimit()); | 1298 EXPECT_TRUE(ClearAddressSpaceLimit()); |
1296 | 1299 |
1297 TestShutdown(); | 1300 TestShutdown(); |
1298 } | 1301 } |
1299 | 1302 |
1300 // Tests that if an allocation fails in "return null" mode, repeating it doesn't | 1303 // Tests that if an allocation fails in "return null" mode, repeating it doesn't |
1301 // crash, and still returns null. The test tries to allocate 6 GB of memory in | 1304 // crash, and still returns null. The test tries to allocate 6 GB of memory in |
1302 // 512 kB blocks. On 64-bit POSIX systems, the address space is limited to 4 GB | 1305 // 512 kB blocks. On 64-bit POSIX systems, the address space is limited to 6 GB |
1303 // using setrlimit() first. | 1306 // using setrlimit() first. |
1304 // | 1307 // |
1305 // Disable this test on Android because, due to its allocation-heavy behavior, | 1308 // Disable this test on Android because, due to its allocation-heavy behavior, |
1306 // it tends to get OOM-killed rather than pass. | 1309 // it tends to get OOM-killed rather than pass. |
1307 #if defined(OS_MACOSX) || defined(OS_ANDROID) | 1310 #if defined(OS_MACOSX) || defined(OS_ANDROID) |
1308 #define MAYBE_RepeatedReturnNull DISABLED_RepeatedReturnNull | 1311 #define MAYBE_RepeatedReturnNull DISABLED_RepeatedReturnNull |
1309 #else | 1312 #else |
1310 #define MAYBE_RepeatedReturnNull RepeatedReturnNull | 1313 #define MAYBE_RepeatedReturnNull RepeatedReturnNull |
1311 #endif | 1314 #endif |
1312 TEST(PartitionAllocTest, MAYBE_RepeatedReturnNull) { | 1315 TEST(PartitionAllocTest, MAYBE_RepeatedReturnNull) { |
(...skipping 785 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2098 partitionFreeGeneric(genericAllocator.root(), ptr1); | 2101 partitionFreeGeneric(genericAllocator.root(), ptr1); |
2099 partitionFreeGeneric(genericAllocator.root(), ptr2); | 2102 partitionFreeGeneric(genericAllocator.root(), ptr2); |
2100 } | 2103 } |
2101 | 2104 |
2102 TestShutdown(); | 2105 TestShutdown(); |
2103 } | 2106 } |
2104 | 2107 |
2105 } // namespace base | 2108 } // namespace base |
2106 | 2109 |
2107 #endif // !defined(MEMORY_TOOL_REPLACES_ALLOCATOR) | 2110 #endif // !defined(MEMORY_TOOL_REPLACES_ALLOCATOR) |
OLD | NEW |