| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 #define _CRT_SECURE_NO_WARNINGS | 5 #define _CRT_SECURE_NO_WARNINGS |
| 6 | 6 |
| 7 #include "base/process/memory.h" | 7 #include "base/process/memory.h" |
| 8 | 8 |
| 9 #include <limits> | 9 #include <limits> |
| 10 | 10 |
| (...skipping 113 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 124 "\\*\\*\\* error: can't allocate region.*" | 124 "\\*\\*\\* error: can't allocate region.*" |
| 125 "(Terminating process due to a potential for future heap " | 125 "(Terminating process due to a potential for future heap " |
| 126 "corruption){0}"); | 126 "corruption){0}"); |
| 127 | 127 |
| 128 base::debug::Alias(buf); | 128 base::debug::Alias(buf); |
| 129 } | 129 } |
| 130 #endif // !defined(ADDRESS_SANITIZER) | 130 #endif // !defined(ADDRESS_SANITIZER) |
| 131 | 131 |
| 132 TEST(ProcessMemoryTest, MacTerminateOnHeapCorruption) { | 132 TEST(ProcessMemoryTest, MacTerminateOnHeapCorruption) { |
| 133 // Assert that freeing an unallocated pointer will crash the process. | 133 // Assert that freeing an unallocated pointer will crash the process. |
| 134 char buf[3]; | 134 char buf[9]; |
| 135 asm("" : "=r" (buf)); // Prevent clang from being too smart. | 135 asm("" : "=r" (buf)); // Prevent clang from being too smart. |
| 136 #if ARCH_CPU_64_BITS | 136 #if ARCH_CPU_64_BITS |
| 137 // On 64 bit Macs, the malloc system automatically abort()s on heap corruption | 137 // On 64 bit Macs, the malloc system automatically abort()s on heap corruption |
| 138 // but does not output anything. | 138 // but does not output anything. |
| 139 ASSERT_DEATH(free(buf), ""); | 139 ASSERT_DEATH(free(buf), ""); |
| 140 #elif defined(ADDRESS_SANITIZER) | 140 #elif defined(ADDRESS_SANITIZER) |
| 141 // AddressSanitizer replaces malloc() and prints a different error message on | 141 // AddressSanitizer replaces malloc() and prints a different error message on |
| 142 // heap corruption. | 142 // heap corruption. |
| 143 ASSERT_DEATH(free(buf), "attempting free on address which " | 143 ASSERT_DEATH(free(buf), "attempting free on address which " |
| 144 "was not malloc\\(\\)-ed"); | 144 "was not malloc\\(\\)-ed"); |
| (...skipping 225 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 370 SetUpInDeathAssert(); | 370 SetUpInDeathAssert(); |
| 371 while ((value_ = base::AllocatePsychoticallyBigObjCObject())) {} | 371 while ((value_ = base::AllocatePsychoticallyBigObjCObject())) {} |
| 372 }, ""); | 372 }, ""); |
| 373 } | 373 } |
| 374 | 374 |
| 375 #endif // !ARCH_CPU_64_BITS | 375 #endif // !ARCH_CPU_64_BITS |
| 376 #endif // OS_MACOSX | 376 #endif // OS_MACOSX |
| 377 | 377 |
| 378 #endif // !defined(OS_ANDROID) && !defined(OS_OPENBSD) && | 378 #endif // !defined(OS_ANDROID) && !defined(OS_OPENBSD) && |
| 379 // !defined(OS_WIN) && !defined(ADDRESS_SANITIZER) | 379 // !defined(OS_WIN) && !defined(ADDRESS_SANITIZER) |
| OLD | NEW |