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" |
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
54 // This adjusts /proc/<pid>/oom_score_adj so the Linux OOM killer will | 54 // This adjusts /proc/<pid>/oom_score_adj so the Linux OOM killer will |
55 // prefer to kill certain process types over others. The range for the | 55 // prefer to kill certain process types over others. The range for the |
56 // adjustment is [-1000, 1000], with [0, 1000] being user accessible. | 56 // adjustment is [-1000, 1000], with [0, 1000] being user accessible. |
57 // If the Linux system doesn't support the newer oom_score_adj range | 57 // If the Linux system doesn't support the newer oom_score_adj range |
58 // of [0, 1000], then we revert to using the older oom_adj, and | 58 // of [0, 1000], then we revert to using the older oom_adj, and |
59 // translate the given value into [0, 15]. Some aliasing of values | 59 // translate the given value into [0, 15]. Some aliasing of values |
60 // may occur in that case, of course. | 60 // may occur in that case, of course. |
61 BASE_EXPORT bool AdjustOOMScore(ProcessId process, int score); | 61 BASE_EXPORT bool AdjustOOMScore(ProcessId process, int score); |
62 #endif | 62 #endif |
63 | 63 |
| 64 // Special allocator functions for callers that want to check for OOM. |
| 65 // These will not abort if the allocation fails even if |
| 66 // EnableTerminationOnOutOfMemory has been called. |
| 67 // This can be useful for huge and/or unpredictable size memory allocations. |
| 68 // Please only use this if you really handle the case when the allocation |
| 69 // fails. Doing otherwise would risk security. |
| 70 // Return value tells whether the allocation succeeded. If it fails |result| is |
| 71 // set to NULL, otherwise it holds the memory address. |
| 72 BASE_EXPORT WARN_UNUSED_RESULT bool UncheckedMalloc(size_t size, |
| 73 void** result); |
| 74 BASE_EXPORT WARN_UNUSED_RESULT bool UncheckedCalloc(size_t num_items, |
| 75 size_t size, |
| 76 void** result); |
| 77 |
| 78 // TODO(b.kelemen): make Skia use the new interface and remove these. |
64 #if defined(OS_MACOSX) | 79 #if defined(OS_MACOSX) |
65 // Very large images or svg canvases can cause huge mallocs. Skia | |
66 // does tricks on tcmalloc-based systems to allow malloc to fail with | |
67 // a NULL rather than hit the oom crasher. This replicates that for | |
68 // OSX. | |
69 // | |
70 // IF YOU USE THIS WITHOUT CONSULTING YOUR FRIENDLY OSX DEVELOPER, | |
71 // YOUR CODE IS LIKELY TO BE REVERTED. THANK YOU. | |
72 BASE_EXPORT void* UncheckedMalloc(size_t size); | 80 BASE_EXPORT void* UncheckedMalloc(size_t size); |
73 BASE_EXPORT void* UncheckedCalloc(size_t num_items, size_t size); | 81 BASE_EXPORT void* UncheckedCalloc(size_t num_items, size_t size); |
74 #endif // defined(OS_MACOSX) | 82 #endif |
75 | 83 |
76 } // namespace base | 84 } // namespace base |
77 | 85 |
78 #endif // BASE_PROCESS_MEMORY_H_ | 86 #endif // BASE_PROCESS_MEMORY_H_ |
OLD | NEW |