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.h> | 7 #include <new.h> |
8 #include <psapi.h> | 8 #include <psapi.h> |
9 #include <stddef.h> | 9 #include <stddef.h> |
10 | 10 |
(...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
88 void EnableTerminationOnHeapCorruption() { | 88 void EnableTerminationOnHeapCorruption() { |
89 // Ignore the result code. Supported on XP SP3 and Vista. | 89 // Ignore the result code. Supported on XP SP3 and Vista. |
90 HeapSetInformation(NULL, HeapEnableTerminationOnCorruption, NULL, 0); | 90 HeapSetInformation(NULL, HeapEnableTerminationOnCorruption, NULL, 0); |
91 } | 91 } |
92 | 92 |
93 void EnableTerminationOnOutOfMemory() { | 93 void EnableTerminationOnOutOfMemory() { |
94 _set_new_handler(&OnNoMemory); | 94 _set_new_handler(&OnNoMemory); |
95 _set_new_mode(1); | 95 _set_new_mode(1); |
96 } | 96 } |
97 | 97 |
98 HMODULE GetModuleFromAddress(void* address) { | 98 HMODULE GetModuleFromAddress(const void* address) { |
99 HMODULE instance = NULL; | 99 HMODULE instance = NULL; |
100 if (!::GetModuleHandleExA(GET_MODULE_HANDLE_EX_FLAG_FROM_ADDRESS | | 100 if (!::GetModuleHandleExA(GET_MODULE_HANDLE_EX_FLAG_FROM_ADDRESS | |
101 GET_MODULE_HANDLE_EX_FLAG_UNCHANGED_REFCOUNT, | 101 GET_MODULE_HANDLE_EX_FLAG_UNCHANGED_REFCOUNT, |
102 static_cast<char*>(address), | 102 static_cast<char*>(const_cast<void*>(address)), |
103 &instance)) { | 103 &instance)) { |
104 NOTREACHED(); | 104 NOTREACHED(); |
105 } | 105 } |
106 return instance; | 106 return instance; |
107 } | 107 } |
108 | 108 |
109 // Implemented using a weak symbol. | 109 // Implemented using a weak symbol. |
110 bool UncheckedMalloc(size_t size, void** result) { | 110 bool UncheckedMalloc(size_t size, void** result) { |
111 *result = malloc_unchecked(size); | 111 *result = malloc_unchecked(size); |
112 return *result != NULL; | 112 return *result != NULL; |
113 } | 113 } |
114 | 114 |
115 } // namespace base | 115 } // namespace base |
OLD | NEW |