| 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 #ifndef BASE_PROCESS_MEMORY_H_ | 5 #ifndef BASE_PROCESS_MEMORY_H_ |
| 6 #define BASE_PROCESS_MEMORY_H_ | 6 #define BASE_PROCESS_MEMORY_H_ |
| 7 | 7 |
| 8 #include "base/base_export.h" | 8 #include "base/base_export.h" |
| 9 #include "base/basictypes.h" | 9 #include "base/basictypes.h" |
| 10 #include "base/process/process_handle.h" | 10 #include "base/process/process_handle.h" |
| 11 #include "build/build_config.h" | 11 #include "build/build_config.h" |
| 12 | 12 |
| 13 #if defined(OS_WIN) | |
| 14 #include <windows.h> | |
| 15 #endif | |
| 16 | |
| 17 #ifdef PVALLOC_AVAILABLE | 13 #ifdef PVALLOC_AVAILABLE |
| 18 // Build config explicitly tells us whether or not pvalloc is available. | 14 // Build config explicitly tells us whether or not pvalloc is available. |
| 19 #elif defined(LIBC_GLIBC) && !defined(USE_TCMALLOC) | 15 #elif defined(LIBC_GLIBC) && !defined(USE_TCMALLOC) |
| 20 #define PVALLOC_AVAILABLE 1 | 16 #define PVALLOC_AVAILABLE 1 |
| 21 #else | 17 #else |
| 22 #define PVALLOC_AVAILABLE 0 | 18 #define PVALLOC_AVAILABLE 0 |
| 23 #endif | 19 #endif |
| 24 | 20 |
| 25 namespace base { | 21 namespace base { |
| 26 | 22 |
| 27 // Enables low fragmentation heap (LFH) for every heaps of this process. This | 23 // Enables low fragmentation heap (LFH) for every heaps of this process. This |
| 28 // won't have any effect on heaps created after this function call. It will not | 24 // won't have any effect on heaps created after this function call. It will not |
| 29 // modify data allocated in the heaps before calling this function. So it is | 25 // modify data allocated in the heaps before calling this function. So it is |
| 30 // better to call this function early in initialization and again before | 26 // better to call this function early in initialization and again before |
| 31 // entering the main loop. | 27 // entering the main loop. |
| 32 // Note: Returns true on Windows 2000 without doing anything. | 28 // Note: Returns true on Windows 2000 without doing anything. |
| 33 BASE_EXPORT bool EnableLowFragmentationHeap(); | 29 BASE_EXPORT bool EnableLowFragmentationHeap(); |
| 34 | 30 |
| 35 // Enables 'terminate on heap corruption' flag. Helps protect against heap | 31 // Enables 'terminate on heap corruption' flag. Helps protect against heap |
| 36 // overflow. Has no effect if the OS doesn't provide the necessary facility. | 32 // overflow. Has no effect if the OS doesn't provide the necessary facility. |
| 37 BASE_EXPORT void EnableTerminationOnHeapCorruption(); | 33 BASE_EXPORT void EnableTerminationOnHeapCorruption(); |
| 38 | 34 |
| 39 // Turns on process termination if memory runs out. | 35 // Turns on process termination if memory runs out. |
| 40 BASE_EXPORT void EnableTerminationOnOutOfMemory(); | 36 BASE_EXPORT void EnableTerminationOnOutOfMemory(); |
| 41 | 37 |
| 42 // Terminates process. Should be called only for out of memory errors. | 38 // Terminates process. Should be called only for out of memory errors. |
| 43 // Crash reporting classifies such crashes as OOM. | 39 // Crash reporting classifies such crashes as OOM. |
| 44 BASE_EXPORT void TerminateBecauseOutOfMemory(size_t size); | 40 BASE_EXPORT void TerminateBecauseOutOfMemory(size_t size); |
| 45 | 41 |
| 46 #if defined(OS_WIN) | |
| 47 // Returns the module handle to which an address belongs. The reference count | |
| 48 // of the module is not incremented. | |
| 49 BASE_EXPORT HMODULE GetModuleFromAddress(void* address); | |
| 50 #endif | |
| 51 | |
| 52 #if defined(OS_LINUX) || defined(OS_ANDROID) | 42 #if defined(OS_LINUX) || defined(OS_ANDROID) |
| 53 BASE_EXPORT extern size_t g_oom_size; | 43 BASE_EXPORT extern size_t g_oom_size; |
| 54 | 44 |
| 55 // The maximum allowed value for the OOM score. | 45 // The maximum allowed value for the OOM score. |
| 56 const int kMaxOomScore = 1000; | 46 const int kMaxOomScore = 1000; |
| 57 | 47 |
| 58 // This adjusts /proc/<pid>/oom_score_adj so the Linux OOM killer will | 48 // This adjusts /proc/<pid>/oom_score_adj so the Linux OOM killer will |
| 59 // prefer to kill certain process types over others. The range for the | 49 // prefer to kill certain process types over others. The range for the |
| 60 // adjustment is [-1000, 1000], with [0, 1000] being user accessible. | 50 // adjustment is [-1000, 1000], with [0, 1000] being user accessible. |
| 61 // If the Linux system doesn't support the newer oom_score_adj range | 51 // If the Linux system doesn't support the newer oom_score_adj range |
| (...skipping 15 matching lines...) Expand all Loading... |
| 77 // set to NULL, otherwise it holds the memory address. | 67 // set to NULL, otherwise it holds the memory address. |
| 78 BASE_EXPORT WARN_UNUSED_RESULT bool UncheckedMalloc(size_t size, | 68 BASE_EXPORT WARN_UNUSED_RESULT bool UncheckedMalloc(size_t size, |
| 79 void** result); | 69 void** result); |
| 80 BASE_EXPORT WARN_UNUSED_RESULT bool UncheckedCalloc(size_t num_items, | 70 BASE_EXPORT WARN_UNUSED_RESULT bool UncheckedCalloc(size_t num_items, |
| 81 size_t size, | 71 size_t size, |
| 82 void** result); | 72 void** result); |
| 83 | 73 |
| 84 } // namespace base | 74 } // namespace base |
| 85 | 75 |
| 86 #endif // BASE_PROCESS_MEMORY_H_ | 76 #endif // BASE_PROCESS_MEMORY_H_ |
| OLD | NEW |