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 <limits> | 7 #include <limits> |
8 | 8 |
9 #include "base/command_line.h" | 9 #include "base/command_line.h" |
10 #include "base/debug/alias.h" | 10 #include "base/debug/alias.h" |
(...skipping 437 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
448 | 448 |
449 #endif // defined(OS_WIN) | 449 #endif // defined(OS_WIN) |
450 | 450 |
451 #if defined(OS_MACOSX) | 451 #if defined(OS_MACOSX) |
452 | 452 |
453 // For the following Mac tests: | 453 // For the following Mac tests: |
454 // Note that base::EnableTerminationOnHeapCorruption() is called as part of | 454 // Note that base::EnableTerminationOnHeapCorruption() is called as part of |
455 // test suite setup and does not need to be done again, else mach_override | 455 // test suite setup and does not need to be done again, else mach_override |
456 // will fail. | 456 // will fail. |
457 | 457 |
| 458 #if !defined(ADDRESS_SANITIZER) |
| 459 // The following code tests the system implementation of malloc() thus no need |
| 460 // to test it under AddressSanitizer. |
458 TEST_F(ProcessUtilTest, MacMallocFailureDoesNotTerminate) { | 461 TEST_F(ProcessUtilTest, MacMallocFailureDoesNotTerminate) { |
459 // Install the OOM killer. | 462 // Install the OOM killer. |
460 base::EnableTerminationOnOutOfMemory(); | 463 base::EnableTerminationOnOutOfMemory(); |
461 | 464 |
462 // Test that ENOMEM doesn't crash via CrMallocErrorBreak two ways: the exit | 465 // Test that ENOMEM doesn't crash via CrMallocErrorBreak two ways: the exit |
463 // code and lack of the error string. The number of bytes is one less than | 466 // code and lack of the error string. The number of bytes is one less than |
464 // MALLOC_ABSOLUTE_MAX_SIZE, more than which the system early-returns NULL and | 467 // MALLOC_ABSOLUTE_MAX_SIZE, more than which the system early-returns NULL and |
465 // does not call through malloc_error_break(). See the comment at | 468 // does not call through malloc_error_break(). See the comment at |
466 // EnableTerminationOnOutOfMemory() for more information. | 469 // EnableTerminationOnOutOfMemory() for more information. |
467 void* buf = NULL; | 470 void* buf = NULL; |
468 ASSERT_EXIT( | 471 ASSERT_EXIT( |
469 buf = malloc(std::numeric_limits<size_t>::max() - (2 * PAGE_SIZE) - 1), | 472 buf = malloc(std::numeric_limits<size_t>::max() - (2 * PAGE_SIZE) - 1), |
470 testing::KilledBySignal(SIGTRAP), | 473 testing::KilledBySignal(SIGTRAP), |
471 "\\*\\*\\* error: can't allocate region.*" | 474 "\\*\\*\\* error: can't allocate region.*" |
472 "(Terminating process due to a potential for future heap " | 475 "(Terminating process due to a potential for future heap " |
473 "corruption){0}"); | 476 "corruption){0}"); |
474 | 477 |
475 base::debug::Alias(buf); | 478 base::debug::Alias(buf); |
476 } | 479 } |
| 480 #endif // !defined(ADDRESS_SANITIZER) |
477 | 481 |
478 TEST_F(ProcessUtilTest, MacTerminateOnHeapCorruption) { | 482 TEST_F(ProcessUtilTest, MacTerminateOnHeapCorruption) { |
479 // Assert that freeing an unallocated pointer will crash the process. | 483 // Assert that freeing an unallocated pointer will crash the process. |
480 char buf[3]; | 484 char buf[3]; |
481 #ifndef ADDRESS_SANITIZER | 485 #if !defined(ADDRESS_SANITIZER) |
482 ASSERT_DEATH(free(buf), "being freed.*" | 486 ASSERT_DEATH(free(buf), "being freed.*" |
483 "\\*\\*\\* set a breakpoint in malloc_error_break to debug.*" | 487 "\\*\\*\\* set a breakpoint in malloc_error_break to debug.*" |
484 "Terminating process due to a potential for future heap corruption"); | 488 "Terminating process due to a potential for future heap corruption"); |
485 #else | 489 #else |
486 // AddressSanitizer replaces malloc() and prints a different error message on | 490 // AddressSanitizer replaces malloc() and prints a different error message on |
487 // heap corruption. | 491 // heap corruption. |
488 ASSERT_DEATH(free(buf), "attempting free on address which " | 492 ASSERT_DEATH(free(buf), "attempting free on address which " |
489 "was not malloc\\(\\)-ed"); | 493 "was not malloc\\(\\)-ed"); |
490 #endif | 494 #endif // !defined(ADDRESS_SANITIZER) |
491 } | 495 } |
492 | 496 |
493 #endif // defined(OS_MACOSX) | 497 #endif // defined(OS_MACOSX) |
494 | 498 |
495 #if defined(OS_POSIX) | 499 #if defined(OS_POSIX) |
496 | 500 |
497 namespace { | 501 namespace { |
498 | 502 |
499 // Returns the maximum number of files that a process can have open. | 503 // Returns the maximum number of files that a process can have open. |
500 // Returns 0 on error. | 504 // Returns 0 on error. |
(...skipping 679 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1180 SetUpInDeathAssert(); | 1184 SetUpInDeathAssert(); |
1181 while ((value_ = base::AllocatePsychoticallyBigObjCObject())) {} | 1185 while ((value_ = base::AllocatePsychoticallyBigObjCObject())) {} |
1182 }, ""); | 1186 }, ""); |
1183 } | 1187 } |
1184 | 1188 |
1185 #endif // !ARCH_CPU_64_BITS | 1189 #endif // !ARCH_CPU_64_BITS |
1186 #endif // OS_MACOSX | 1190 #endif // OS_MACOSX |
1187 | 1191 |
1188 #endif // !defined(OS_ANDROID) && !defined(OS_OPENBSD) && | 1192 #endif // !defined(OS_ANDROID) && !defined(OS_OPENBSD) && |
1189 // !defined(OS_WIN) && !defined(ADDRESS_SANITIZER) | 1193 // !defined(OS_WIN) && !defined(ADDRESS_SANITIZER) |
OLD | NEW |