OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 <stddef.h> | 5 #include <stddef.h> |
6 #include <stdlib.h> | 6 #include <stdlib.h> |
7 | 7 |
8 #include "base/process/memory.h" | 8 #include "base/process/memory.h" |
9 #include "build/build_config.h" | 9 #include "build/build_config.h" |
10 #include "third_party/skia/include/core/SkTypes.h" | 10 #include "third_party/skia/include/core/SkTypes.h" |
(...skipping 16 matching lines...) Expand all Loading... |
27 } | 27 } |
28 return p; | 28 return p; |
29 } | 29 } |
30 | 30 |
31 void sk_abort_no_print() { | 31 void sk_abort_no_print() { |
32 abort(); | 32 abort(); |
33 } | 33 } |
34 | 34 |
35 void sk_out_of_memory(void) { | 35 void sk_out_of_memory(void) { |
36 SkASSERT(!"sk_out_of_memory"); | 36 SkASSERT(!"sk_out_of_memory"); |
37 #if defined(OS_WIN) | 37 base::TerminateBecauseOutOfMemory(0); |
38 // Kill the process. This is important for security since most of code | 38 // Extra safety abort(). |
39 // does not check the result of memory allocation. | |
40 // https://msdn.microsoft.com/en-us/library/het71c37.aspx | |
41 ::RaiseException(base::win::kOomExceptionCode, EXCEPTION_NONCONTINUABLE, 0, | |
42 nullptr); | |
43 #endif | |
44 abort(); | 39 abort(); |
45 } | 40 } |
46 | 41 |
47 void* sk_realloc_throw(void* addr, size_t size) { | 42 void* sk_realloc_throw(void* addr, size_t size) { |
48 return throw_on_failure(size, realloc(addr, size)); | 43 return throw_on_failure(size, realloc(addr, size)); |
49 } | 44 } |
50 | 45 |
51 void sk_free(void* p) { | 46 void sk_free(void* p) { |
52 if (p) { | 47 if (p) { |
53 free(p); | 48 free(p); |
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
104 result = calloc(1, size); | 99 result = calloc(1, size); |
105 #else | 100 #else |
106 // It's the responsibility of the caller to check the return value. | 101 // It's the responsibility of the caller to check the return value. |
107 ignore_result(base::UncheckedCalloc(size, 1, &result)); | 102 ignore_result(base::UncheckedCalloc(size, 1, &result)); |
108 #endif | 103 #endif |
109 if (result) { | 104 if (result) { |
110 prevent_overcommit(0, size, result); | 105 prevent_overcommit(0, size, result); |
111 } | 106 } |
112 return result; | 107 return result; |
113 } | 108 } |
OLD | NEW |