Commit e24b74fe authored by earthdok@chromium.org's avatar earthdok@chromium.org

Update code related to OOM errors in sanitizer builds.

Remove outdated comment and enable OOM tests under sanitizers. Also, document
the fact that the newly introduced UncheckedMalloc()/UncheckedCalloc() don't
work as intended in sanitizer builds.

BUG=357732
R=thakis@chromium.org

Review URL: https://codereview.chromium.org/217343002

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@260379 0039d316-1c4b-4281-b951-d872f2087c98
parent dbe2ca2b
...@@ -67,6 +67,8 @@ BASE_EXPORT bool AdjustOOMScore(ProcessId process, int score); ...@@ -67,6 +67,8 @@ BASE_EXPORT bool AdjustOOMScore(ProcessId process, int score);
// This can be useful for huge and/or unpredictable size memory allocations. // This can be useful for huge and/or unpredictable size memory allocations.
// Please only use this if you really handle the case when the allocation // Please only use this if you really handle the case when the allocation
// fails. Doing otherwise would risk security. // fails. Doing otherwise would risk security.
// These functions may still crash on OOM when running under memory tools,
// specifically ASan and other sanitizers.
// Return value tells whether the allocation succeeded. If it fails |result| is // Return value tells whether the allocation succeeded. If it fails |result| is
// set to NULL, otherwise it holds the memory address. // set to NULL, otherwise it holds the memory address.
BASE_EXPORT WARN_UNUSED_RESULT bool UncheckedMalloc(size_t size, BASE_EXPORT WARN_UNUSED_RESULT bool UncheckedMalloc(size_t size,
......
...@@ -199,8 +199,7 @@ bool AdjustOOMScore(ProcessId process, int score) { ...@@ -199,8 +199,7 @@ bool AdjustOOMScore(ProcessId process, int score) {
} }
bool UncheckedMalloc(size_t size, void** result) { bool UncheckedMalloc(size_t size, void** result) {
#if defined(ADDRESS_SANITIZER) || defined(MEMORY_SANITIZER) || \ #if defined(MEMORY_TOOL_REPLACES_ALLOCATOR) || \
defined(THREAD_SANITIZER) || defined(LEAK_SANITIZER) || \
(!defined(LIBC_GLIBC) && !defined(USE_TCMALLOC)) (!defined(LIBC_GLIBC) && !defined(USE_TCMALLOC))
*result = malloc(size); *result = malloc(size);
#elif defined(LIBC_GLIBC) && !defined(USE_TCMALLOC) #elif defined(LIBC_GLIBC) && !defined(USE_TCMALLOC)
......
...@@ -152,13 +152,9 @@ TEST(ProcessMemoryTest, MacTerminateOnHeapCorruption) { ...@@ -152,13 +152,9 @@ TEST(ProcessMemoryTest, MacTerminateOnHeapCorruption) {
// Android doesn't implement set_new_handler, so we can't use the // Android doesn't implement set_new_handler, so we can't use the
// OutOfMemoryTest cases. // OutOfMemoryTest cases.
// OpenBSD does not support these tests either. // OpenBSD does not support these tests either.
// AddressSanitizer and ThreadSanitizer define the malloc()/free()/etc.
// functions so that they don't crash if the program is out of memory, so the
// OOM tests aren't supposed to work.
// TODO(vandebo) make this work on Windows too. // TODO(vandebo) make this work on Windows too.
#if !defined(OS_ANDROID) && !defined(OS_OPENBSD) && \ #if !defined(OS_ANDROID) && !defined(OS_OPENBSD) && \
!defined(OS_WIN) && \ !defined(OS_WIN)
!defined(ADDRESS_SANITIZER) && !defined(THREAD_SANITIZER)
#if defined(USE_TCMALLOC) #if defined(USE_TCMALLOC)
extern "C" { extern "C" {
...@@ -397,7 +393,9 @@ class OutOfMemoryHandledTest : public OutOfMemoryTest { ...@@ -397,7 +393,9 @@ class OutOfMemoryHandledTest : public OutOfMemoryTest {
// TODO(b.kelemen): make UncheckedMalloc and UncheckedCalloc work // TODO(b.kelemen): make UncheckedMalloc and UncheckedCalloc work
// on Windows as well. // on Windows as well.
// UncheckedMalloc() and UncheckedCalloc() work as regular malloc()/calloc()
// under sanitizer tools.
#if !defined(MEMORY_TOOL_REPLACES_ALLOCATOR)
TEST_F(OutOfMemoryHandledTest, UncheckedMalloc) { TEST_F(OutOfMemoryHandledTest, UncheckedMalloc) {
EXPECT_TRUE(base::UncheckedMalloc(kSafeMallocSize, &value_)); EXPECT_TRUE(base::UncheckedMalloc(kSafeMallocSize, &value_));
EXPECT_TRUE(value_ != NULL); EXPECT_TRUE(value_ != NULL);
...@@ -426,6 +424,5 @@ TEST_F(OutOfMemoryHandledTest, UncheckedCalloc) { ...@@ -426,6 +424,5 @@ TEST_F(OutOfMemoryHandledTest, UncheckedCalloc) {
EXPECT_FALSE(base::UncheckedCalloc(1, test_size_, &value_)); EXPECT_FALSE(base::UncheckedCalloc(1, test_size_, &value_));
EXPECT_TRUE(value_ == NULL); EXPECT_TRUE(value_ == NULL);
} }
#endif // !defined(MEMORY_TOOL_REPLACES_ALLOCATOR)
#endif // !defined(OS_ANDROID) && !defined(OS_OPENBSD) && #endif // !defined(OS_ANDROID) && !defined(OS_OPENBSD) && !defined(OS_WIN)
// !defined(OS_WIN) && !defined(ADDRESS_SANITIZER)
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment