| 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 <stddef.h> | 8 #include <stddef.h> |
| 9 | 9 |
| 10 #include "base/base_export.h" | 10 #include "base/base_export.h" |
| (...skipping 30 matching lines...) Expand all Loading... |
| 41 // This adjusts /proc/<pid>/oom_score_adj so the Linux OOM killer will | 41 // This adjusts /proc/<pid>/oom_score_adj so the Linux OOM killer will |
| 42 // prefer to kill certain process types over others. The range for the | 42 // prefer to kill certain process types over others. The range for the |
| 43 // adjustment is [-1000, 1000], with [0, 1000] being user accessible. | 43 // adjustment is [-1000, 1000], with [0, 1000] being user accessible. |
| 44 // If the Linux system doesn't support the newer oom_score_adj range | 44 // If the Linux system doesn't support the newer oom_score_adj range |
| 45 // of [0, 1000], then we revert to using the older oom_adj, and | 45 // of [0, 1000], then we revert to using the older oom_adj, and |
| 46 // translate the given value into [0, 15]. Some aliasing of values | 46 // translate the given value into [0, 15]. Some aliasing of values |
| 47 // may occur in that case, of course. | 47 // may occur in that case, of course. |
| 48 BASE_EXPORT bool AdjustOOMScore(ProcessId process, int score); | 48 BASE_EXPORT bool AdjustOOMScore(ProcessId process, int score); |
| 49 #endif | 49 #endif |
| 50 | 50 |
| 51 #if defined(OS_WIN) | |
| 52 namespace win { | |
| 53 | |
| 54 // Custom exception code chosen to indicate an out of memory error. | |
| 55 // See https://msdn.microsoft.com/en-us/library/het71c37.aspx. | |
| 56 // "To make sure that you do not define a code that conflicts with an existing | |
| 57 // exception code" ... "The resulting error code should therefore have the | |
| 58 // highest four bits set to hexadecimal E." | |
| 59 // 0xe0000008 was chosen arbitrarily, as 0x00000008 is ERROR_NOT_ENOUGH_MEMORY. | |
| 60 const DWORD kOomExceptionCode = 0xe0000008; | |
| 61 | |
| 62 } // namespace win | |
| 63 #endif | |
| 64 | |
| 65 // Special allocator functions for callers that want to check for OOM. | 51 // Special allocator functions for callers that want to check for OOM. |
| 66 // These will not abort if the allocation fails even if | 52 // These will not abort if the allocation fails even if |
| 67 // EnableTerminationOnOutOfMemory has been called. | 53 // EnableTerminationOnOutOfMemory has been called. |
| 68 // This can be useful for huge and/or unpredictable size memory allocations. | 54 // This can be useful for huge and/or unpredictable size memory allocations. |
| 69 // Please only use this if you really handle the case when the allocation | 55 // Please only use this if you really handle the case when the allocation |
| 70 // fails. Doing otherwise would risk security. | 56 // fails. Doing otherwise would risk security. |
| 71 // These functions may still crash on OOM when running under memory tools, | 57 // These functions may still crash on OOM when running under memory tools, |
| 72 // specifically ASan and other sanitizers. | 58 // specifically ASan and other sanitizers. |
| 73 // Return value tells whether the allocation succeeded. If it fails |result| is | 59 // Return value tells whether the allocation succeeded. If it fails |result| is |
| 74 // set to NULL, otherwise it holds the memory address. | 60 // set to NULL, otherwise it holds the memory address. |
| 75 BASE_EXPORT WARN_UNUSED_RESULT bool UncheckedMalloc(size_t size, | 61 BASE_EXPORT WARN_UNUSED_RESULT bool UncheckedMalloc(size_t size, |
| 76 void** result); | 62 void** result); |
| 77 BASE_EXPORT WARN_UNUSED_RESULT bool UncheckedCalloc(size_t num_items, | 63 BASE_EXPORT WARN_UNUSED_RESULT bool UncheckedCalloc(size_t num_items, |
| 78 size_t size, | 64 size_t size, |
| 79 void** result); | 65 void** result); |
| 80 | 66 |
| 81 } // namespace base | 67 } // namespace base |
| 82 | 68 |
| 83 #endif // BASE_PROCESS_MEMORY_H_ | 69 #endif // BASE_PROCESS_MEMORY_H_ |
| OLD | NEW |