diff options
author | agl@chromium.org <agl@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-01-08 21:28:27 +0000 |
---|---|---|
committer | agl@chromium.org <agl@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-01-08 21:28:27 +0000 |
commit | 78711ce43ea5cefa47f9b066b5cbafeaaf2641cc (patch) | |
tree | 386b9c80891f38b0bfb22f5d97d9cd29b69c4434 /base/process_util_unittest.cc | |
parent | 7e08009603d63ce4ff7914a3b984c7b9c99c0556 (diff) | |
download | chromium_src-78711ce43ea5cefa47f9b066b5cbafeaaf2641cc.zip chromium_src-78711ce43ea5cefa47f9b066b5cbafeaaf2641cc.tar.gz chromium_src-78711ce43ea5cefa47f9b066b5cbafeaaf2641cc.tar.bz2 |
Linux: reenable malloc overrides.
(These were disabled in r35804 and r35810.)
This time we are using the __libc_* names to get at the real glibc
functions rather than dlsym. This now means that code that calls
__libc_* gets the raw functions, not 'safe' ones. Also, this sets the
visibility correctly. Previously we were not overriding malloc calls
made in shared libraries.
BUG=31809
TEST=Covered by unittests.
http://codereview.chromium.org/533001
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@35823 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'base/process_util_unittest.cc')
-rw-r--r-- | base/process_util_unittest.cc | 52 |
1 files changed, 11 insertions, 41 deletions
diff --git a/base/process_util_unittest.cc b/base/process_util_unittest.cc index 366c794..da84c227 100644 --- a/base/process_util_unittest.cc +++ b/base/process_util_unittest.cc @@ -19,6 +19,7 @@ #include <dlfcn.h> #include <errno.h> #include <malloc.h> +#include <glib.h> #endif #if defined(OS_POSIX) #include <fcntl.h> @@ -388,10 +389,6 @@ TEST_F(ProcessUtilTest, ParseProcStatCPU) { #endif // defined(OS_POSIX) -#if 0 - -// See comments in process_util_linux.cc about why these are removed for now. - // TODO(vandebo) make this work on Windows and Mac too. #if defined(OS_LINUX) @@ -455,6 +452,16 @@ TEST_F(OutOfMemoryTest, Memalign) { ASSERT_DEATH(value_ = memalign(4, test_size_), ""); } +TEST_F(OutOfMemoryTest, ViaSharedLibraries) { + // g_try_malloc is documented to return NULL on failure. (g_malloc is the + // 'safe' default that crashes if allocation fails). However, since we have + // hopefully overridden malloc, even g_try_malloc should fail. This tests + // that the run-time symbol resolution is overriding malloc for shared + // libraries as well as for our code. + ASSERT_DEATH(value_ = g_try_malloc(test_size_), ""); +} + + TEST_F(OutOfMemoryTest, Posix_memalign) { // Grab the return value of posix_memalign to silence a compiler warning // about unused return values. We don't actually care about the return @@ -462,43 +469,6 @@ TEST_F(OutOfMemoryTest, Posix_memalign) { ASSERT_DEATH(EXPECT_EQ(ENOMEM, posix_memalign(&value_, 8, test_size_)), ""); } -extern "C" { - -void* __libc_malloc(size_t size); -void* __libc_realloc(void* ptr, size_t size); -void* __libc_calloc(size_t nmemb, size_t size); -void* __libc_valloc(size_t size); -void* __libc_pvalloc(size_t size); -void* __libc_memalign(size_t alignment, size_t size); - -} // extern "C" - -TEST_F(OutOfMemoryTest, __libc_malloc) { - ASSERT_DEATH(value_ = __libc_malloc(test_size_), ""); -} - -TEST_F(OutOfMemoryTest, __libc_realloc) { - ASSERT_DEATH(value_ = __libc_realloc(NULL, test_size_), ""); -} - -TEST_F(OutOfMemoryTest, __libc_calloc) { - ASSERT_DEATH(value_ = __libc_calloc(1024, test_size_ / 1024L), ""); -} - -TEST_F(OutOfMemoryTest, __libc_valloc) { - ASSERT_DEATH(value_ = __libc_valloc(test_size_), ""); -} - -TEST_F(OutOfMemoryTest, __libc_pvalloc) { - ASSERT_DEATH(value_ = __libc_pvalloc(test_size_), ""); -} - -TEST_F(OutOfMemoryTest, __libc_memalign) { - ASSERT_DEATH(value_ = __libc_memalign(4, test_size_), ""); -} - #endif // defined(OS_LINUX) -#endif - } // namespace base |