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 <fcntl.h> | 5 #include <fcntl.h> |
6 #include <stdio.h> | 6 #include <stdio.h> |
7 #include <stdlib.h> | 7 #include <stdlib.h> |
8 #include <string.h> | 8 #include <string.h> |
9 #include <sys/stat.h> | 9 #include <sys/stat.h> |
10 #include <sys/types.h> | 10 #include <sys/types.h> |
(...skipping 24 matching lines...) Expand all Loading... |
35 #if defined(OS_WIN) | 35 #if defined(OS_WIN) |
36 // This is a permitted size but exhausts memory pretty quickly. | 36 // This is a permitted size but exhausts memory pretty quickly. |
37 const size_t kLargePermittedAllocation = 0x7FFFE000; | 37 const size_t kLargePermittedAllocation = 0x7FFFE000; |
38 | 38 |
39 int OnNoMemory(size_t) { | 39 int OnNoMemory(size_t) { |
40 _exit(1); | 40 _exit(1); |
41 } | 41 } |
42 | 42 |
43 void ExhaustMemoryWithMalloc() { | 43 void ExhaustMemoryWithMalloc() { |
44 for (;;) { | 44 for (;;) { |
45 void* buf = malloc(kLargePermittedAllocation); | 45 // Without the |volatile|, clang optimizes away the allocation. |
| 46 void* volatile buf = malloc(kLargePermittedAllocation); |
46 if (!buf) | 47 if (!buf) |
47 break; | 48 break; |
48 } | 49 } |
49 } | 50 } |
50 | 51 |
51 void ExhaustMemoryWithRealloc() { | 52 void ExhaustMemoryWithRealloc() { |
52 size_t size = kLargePermittedAllocation; | 53 size_t size = kLargePermittedAllocation; |
53 void* buf = malloc(size); | 54 void* buf = malloc(size); |
54 if (!buf) | 55 if (!buf) |
55 return; | 56 return; |
(...skipping 310 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
366 // kRandomMask, so we use it as an additional detection mechanism. | 367 // kRandomMask, so we use it as an additional detection mechanism. |
367 const uintptr_t kRandomMask = 0x3fffffffffffULL; | 368 const uintptr_t kRandomMask = 0x3fffffffffffULL; |
368 bool impossible_random_address = | 369 bool impossible_random_address = |
369 reinterpret_cast<uintptr_t>(ptr.get()) & ~kRandomMask; | 370 reinterpret_cast<uintptr_t>(ptr.get()) & ~kRandomMask; |
370 EXPECT_FALSE(impossible_random_address); | 371 EXPECT_FALSE(impossible_random_address); |
371 } | 372 } |
372 | 373 |
373 #endif // defined(OS_LINUX) && defined(__x86_64__) | 374 #endif // defined(OS_LINUX) && defined(__x86_64__) |
374 | 375 |
375 } // namespace | 376 } // namespace |
OLD | NEW |