| OLD | NEW |
| 1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2013 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 #include "base/process/memory.h" | 5 #include "base/process/memory.h" |
| 6 | 6 |
| 7 #include <new> | 7 #include <new> |
| 8 | 8 |
| 9 #include "base/file_util.h" | 9 #include "base/file_util.h" |
| 10 #include "base/files/file_path.h" | 10 #include "base/files/file_path.h" |
| (...skipping 26 matching lines...) Expand all Loading... |
| 37 #if !defined(ADDRESS_SANITIZER) && !defined(MEMORY_SANITIZER) && \ | 37 #if !defined(ADDRESS_SANITIZER) && !defined(MEMORY_SANITIZER) && \ |
| 38 !defined(THREAD_SANITIZER) && !defined(LEAK_SANITIZER) | 38 !defined(THREAD_SANITIZER) && !defined(LEAK_SANITIZER) |
| 39 | 39 |
| 40 #if defined(LIBC_GLIBC) && !defined(USE_TCMALLOC) | 40 #if defined(LIBC_GLIBC) && !defined(USE_TCMALLOC) |
| 41 | 41 |
| 42 extern "C" { | 42 extern "C" { |
| 43 void* __libc_malloc(size_t size); | 43 void* __libc_malloc(size_t size); |
| 44 void* __libc_realloc(void* ptr, size_t size); | 44 void* __libc_realloc(void* ptr, size_t size); |
| 45 void* __libc_calloc(size_t nmemb, size_t size); | 45 void* __libc_calloc(size_t nmemb, size_t size); |
| 46 void* __libc_valloc(size_t size); | 46 void* __libc_valloc(size_t size); |
| 47 #if PVALLOC_AVAILABLE == 1 |
| 47 void* __libc_pvalloc(size_t size); | 48 void* __libc_pvalloc(size_t size); |
| 49 #endif |
| 48 void* __libc_memalign(size_t alignment, size_t size); | 50 void* __libc_memalign(size_t alignment, size_t size); |
| 49 | 51 |
| 50 // Overriding the system memory allocation functions: | 52 // Overriding the system memory allocation functions: |
| 51 // | 53 // |
| 52 // For security reasons, we want malloc failures to be fatal. Too much code | 54 // For security reasons, we want malloc failures to be fatal. Too much code |
| 53 // doesn't check for a NULL return value from malloc and unconditionally uses | 55 // doesn't check for a NULL return value from malloc and unconditionally uses |
| 54 // the resulting pointer. If the first offset that they try to access is | 56 // the resulting pointer. If the first offset that they try to access is |
| 55 // attacker controlled, then the attacker can direct the code to access any | 57 // attacker controlled, then the attacker can direct the code to access any |
| 56 // part of memory. | 58 // part of memory. |
| 57 // | 59 // |
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 92 \ | 94 \ |
| 93 void* function_name(arg1_type arg1, size_t size) { \ | 95 void* function_name(arg1_type arg1, size_t size) { \ |
| 94 void* ret = __libc_##function_name(arg1, size); \ | 96 void* ret = __libc_##function_name(arg1, size); \ |
| 95 if (ret == NULL && size != 0) \ | 97 if (ret == NULL && size != 0) \ |
| 96 OnNoMemorySize(size); \ | 98 OnNoMemorySize(size); \ |
| 97 return ret; \ | 99 return ret; \ |
| 98 } | 100 } |
| 99 | 101 |
| 100 DIE_ON_OOM_1(malloc) | 102 DIE_ON_OOM_1(malloc) |
| 101 DIE_ON_OOM_1(valloc) | 103 DIE_ON_OOM_1(valloc) |
| 104 #if PVALLOC_AVAILABLE == 1 |
| 102 DIE_ON_OOM_1(pvalloc) | 105 DIE_ON_OOM_1(pvalloc) |
| 106 #endif |
| 103 | 107 |
| 104 DIE_ON_OOM_2(calloc, size_t) | 108 DIE_ON_OOM_2(calloc, size_t) |
| 105 DIE_ON_OOM_2(realloc, void*) | 109 DIE_ON_OOM_2(realloc, void*) |
| 106 DIE_ON_OOM_2(memalign, size_t) | 110 DIE_ON_OOM_2(memalign, size_t) |
| 107 | 111 |
| 108 // posix_memalign has a unique signature and doesn't have a __libc_ variant. | 112 // posix_memalign has a unique signature and doesn't have a __libc_ variant. |
| 109 int posix_memalign(void** ptr, size_t alignment, size_t size) | 113 int posix_memalign(void** ptr, size_t alignment, size_t size) |
| 110 __attribute__ ((visibility("default"))); | 114 __attribute__ ((visibility("default"))); |
| 111 | 115 |
| 112 int posix_memalign(void** ptr, size_t alignment, size_t size) { | 116 int posix_memalign(void** ptr, size_t alignment, size_t size) { |
| (...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 176 int score_len = static_cast<int>(score_str.length()); | 180 int score_len = static_cast<int>(score_str.length()); |
| 177 return (score_len == file_util::WriteFile(oom_file, | 181 return (score_len == file_util::WriteFile(oom_file, |
| 178 score_str.c_str(), | 182 score_str.c_str(), |
| 179 score_len)); | 183 score_len)); |
| 180 } | 184 } |
| 181 | 185 |
| 182 return false; | 186 return false; |
| 183 } | 187 } |
| 184 | 188 |
| 185 } // namespace base | 189 } // namespace base |
| OLD | NEW |