| Index: base/process/memory_linux.cc
|
| diff --git a/base/process/memory_linux.cc b/base/process/memory_linux.cc
|
| index 6bed68bd8320346b1ff98a39417e604e0339b020..83b434e3b82a23448c0a96589fe820a118411d0f 100644
|
| --- a/base/process/memory_linux.cc
|
| +++ b/base/process/memory_linux.cc
|
| @@ -12,6 +12,10 @@
|
| #include "base/process/internal_linux.h"
|
| #include "base/strings/string_number_conversions.h"
|
|
|
| +#if defined(USE_TCMALLOC)
|
| +#include "third_party/tcmalloc/chromium/src/gperftools/tcmalloc.h"
|
| +#endif
|
| +
|
| namespace base {
|
|
|
| size_t g_oom_size = 0U;
|
| @@ -125,6 +129,37 @@ int posix_memalign(void** ptr, size_t alignment, size_t size) {
|
|
|
| #endif // !*_SANITIZER
|
|
|
| +bool UncheckedMalloc(size_t size, void** result) {
|
| +#if defined(ADDRESS_SANITIZER) || defined(MEMORY_SANITIZER) || \
|
| + defined(THREAD_SANITIZER) || defined(LEAK_SANITIZER) || \
|
| + (!defined(LIBC_GLIBC) && !defined(USE_TCMALLOC))
|
| + *result = malloc(size);
|
| +#elif defined(LIBC_GLIBC) && !defined(USE_TCMALLOC)
|
| + *result = __libc_malloc(size);
|
| +#elif defined(USE_TCMALLOC)
|
| + *result = tc_malloc_skip_new_handler(size);
|
| +#else
|
| +#error Not implemented
|
| +#endif
|
| + return *result;
|
| +}
|
| +
|
| +bool UncheckedCalloc(size_t num_items, size_t size, void** result) {
|
| + const size_t alloc_size = num_items * size;
|
| +
|
| + // Overflow check
|
| + if (size && ((alloc_size / size) != num_items)) {
|
| + result = NULL;
|
| + return false;
|
| + }
|
| +
|
| + if (!UncheckedMalloc(alloc_size, result))
|
| + return false;
|
| +
|
| + memset(result, 0, alloc_size);
|
| + return true;
|
| +}
|
| +
|
| void EnableTerminationOnHeapCorruption() {
|
| // On Linux, there nothing to do AFAIK.
|
| }
|
|
|