Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(14)

Side by Side Diff: base/process/memory_unittest.cc

Issue 2674253003: Populate allocation size into OOM exception on Windows. (Closed)
Patch Set: Created 3 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | base/process/memory_win.cc » ('j') | base/process/memory_win.cc » ('J')
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 <stddef.h> 9 #include <stddef.h>
10 10
(...skipping 391 matching lines...) Expand 10 before | Expand all | Expand 10 after
402 void SetUp() override { 402 void SetUp() override {
403 OutOfMemoryTest::SetUp(); 403 OutOfMemoryTest::SetUp();
404 404
405 // We enable termination on OOM - just as Chrome does at early 405 // We enable termination on OOM - just as Chrome does at early
406 // initialization - and test that UncheckedMalloc and UncheckedCalloc 406 // initialization - and test that UncheckedMalloc and UncheckedCalloc
407 // properly by-pass this in order to allow the caller to handle OOM. 407 // properly by-pass this in order to allow the caller to handle OOM.
408 base::EnableTerminationOnOutOfMemory(); 408 base::EnableTerminationOnOutOfMemory();
409 } 409 }
410 }; 410 };
411 411
412 #if defined(OS_WIN)
413
414 namespace {
415
416 DWORD HandleOutOfMemoryException(EXCEPTION_POINTERS* exception_ptrs,
417 size_t expected_size) {
418 EXPECT_EQ(base::win::kOomExceptionCode,
419 exception_ptrs->ExceptionRecord->ExceptionCode);
420 EXPECT_LE(1U, exception_ptrs->ExceptionRecord->NumberParameters);
421 EXPECT_EQ(expected_size,
422 exception_ptrs->ExceptionRecord->ExceptionInformation[0]);
423 return EXCEPTION_EXECUTE_HANDLER;
424 }
425
426 } // namespace
427
428 TEST_F(OutOfMemoryTest, TerminateBecauseOutOfMemoryReportsAllocSize) {
429 // On Windows, TerminateBecauseOutOfMemory reports the attempted allocation
430 // size in the exception raised.
431 const size_t kAttemptedAllocationSize = 0xBADA55;
Will Harris 2017/02/06 18:24:03 Can you test with a value that does not fit in 32b
Sigurður Ásgeirsson 2017/02/06 19:43:58 Done.
432 __try {
433 base::TerminateBecauseOutOfMemory(kAttemptedAllocationSize);
434 } __except (HandleOutOfMemoryException(GetExceptionInformation(),
435 kAttemptedAllocationSize)) {
436 }
437 }
438 #endif // OS_WIN
439
412 // TODO(b.kelemen): make UncheckedMalloc and UncheckedCalloc work 440 // TODO(b.kelemen): make UncheckedMalloc and UncheckedCalloc work
413 // on Windows as well. 441 // on Windows as well.
414 TEST_F(OutOfMemoryHandledTest, UncheckedMalloc) { 442 TEST_F(OutOfMemoryHandledTest, UncheckedMalloc) {
415 EXPECT_TRUE(base::UncheckedMalloc(kSafeMallocSize, &value_)); 443 EXPECT_TRUE(base::UncheckedMalloc(kSafeMallocSize, &value_));
416 EXPECT_TRUE(value_ != NULL); 444 EXPECT_TRUE(value_ != NULL);
417 free(value_); 445 free(value_);
418 446
419 EXPECT_FALSE(base::UncheckedMalloc(test_size_, &value_)); 447 EXPECT_FALSE(base::UncheckedMalloc(test_size_, &value_));
420 EXPECT_TRUE(value_ == NULL); 448 EXPECT_TRUE(value_ == NULL);
421 } 449 }
(...skipping 12 matching lines...) Expand all
434 bytes = static_cast<const char*>(value_); 462 bytes = static_cast<const char*>(value_);
435 for (size_t i = 0; i < (kSafeCallocItems * kSafeCallocSize); ++i) 463 for (size_t i = 0; i < (kSafeCallocItems * kSafeCallocSize); ++i)
436 EXPECT_EQ(0, bytes[i]); 464 EXPECT_EQ(0, bytes[i]);
437 free(value_); 465 free(value_);
438 466
439 EXPECT_FALSE(base::UncheckedCalloc(1, test_size_, &value_)); 467 EXPECT_FALSE(base::UncheckedCalloc(1, test_size_, &value_));
440 EXPECT_TRUE(value_ == NULL); 468 EXPECT_TRUE(value_ == NULL);
441 } 469 }
442 #endif // !defined(OS_OPENBSD) && BUILDFLAG(ENABLE_WIN_ALLOCATOR_SHIM_TESTS) && 470 #endif // !defined(OS_OPENBSD) && BUILDFLAG(ENABLE_WIN_ALLOCATOR_SHIM_TESTS) &&
443 // !defined(MEMORY_TOOL_REPLACES_ALLOCATOR) 471 // !defined(MEMORY_TOOL_REPLACES_ALLOCATOR)
OLDNEW
« no previous file with comments | « no previous file | base/process/memory_win.cc » ('j') | base/process/memory_win.cc » ('J')

Powered by Google App Engine
This is Rietveld 408576698