| 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 <limits.h> | 5 #include <limits.h> |
| 6 #include <malloc.h> | 6 #include <malloc.h> |
| 7 #include <new.h> | 7 #include <new.h> |
| 8 #include <windows.h> | 8 #include <windows.h> |
| 9 #include <stddef.h> | 9 #include <stddef.h> |
| 10 | 10 |
| 11 // This shim make it possible to perform additional checks on allocations | 11 // This shim make it possible to perform additional checks on allocations |
| 12 // before passing them to the Heap functions. | 12 // before passing them to the Heap functions. |
| 13 | 13 |
| 14 // Heap functions are stripped from libcmt.lib using the prep_libc.py | 14 // Heap functions are stripped from libcmt.lib using the prep_libc.py |
| 15 // for each object file stripped, we re-implement them here to allow us to | 15 // for each object file stripped, we re-implement them here to allow us to |
| 16 // perform additional checks: | 16 // perform additional checks: |
| 17 // 1. Enforcing the maximum size that can be allocated to 2Gb. | 17 // 1. Enforcing the maximum size that can be allocated to 2Gb. |
| 18 // 2. Calling new_handler if malloc fails. | 18 // 2. Calling new_handler if malloc fails. |
| 19 | 19 |
| 20 extern "C" { | 20 extern "C" { |
| 21 // We set this to 1 because part of the CRT uses a check of _crtheap != 0 | 21 // We set this to 1 because part of the CRT uses a check of _crtheap != 0 |
| 22 // to test whether the CRT has been initialized. Once we've ripped out | 22 // to test whether the CRT has been initialized. Once we've ripped out |
| 23 // the allocators from libcmt, we need to provide this definition so that | 23 // the allocators from libcmt, we need to provide this definition so that |
| 24 // the rest of the CRT is still usable. | 24 // the rest of the CRT is still usable. |
| 25 // heapinit.c | 25 // heapinit.c |
| 26 void* _crtheap = reinterpret_cast<void*>(1); | 26 void* _crtheap = reinterpret_cast<void*>(1); |
| 27 } | 27 } |
| 28 | 28 |
| 29 namespace base { |
| 30 namespace allocator { |
| 31 bool g_is_win_shim_layer_initialized = false; |
| 32 } // namespace allocator |
| 33 } // namespace base |
| 34 |
| 29 namespace { | 35 namespace { |
| 30 | 36 |
| 31 const size_t kWindowsPageSize = 4096; | 37 const size_t kWindowsPageSize = 4096; |
| 32 const size_t kMaxWindowsAllocation = INT_MAX - kWindowsPageSize; | 38 const size_t kMaxWindowsAllocation = INT_MAX - kWindowsPageSize; |
| 33 int new_mode = 0; | 39 int new_mode = 0; |
| 34 | 40 |
| 35 // VS2013 crt uses the process heap as its heap, so we do the same here. | 41 // VS2013 crt uses the process heap as its heap, so we do the same here. |
| 36 // See heapinit.c in VS CRT sources. | 42 // See heapinit.c in VS CRT sources. |
| 37 bool win_heap_init() { | 43 bool win_heap_init() { |
| 38 // Set the _crtheap global here. THis allows us to offload most of the | 44 // Set the _crtheap global here. THis allows us to offload most of the |
| (...skipping 165 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 204 return new_ptr; | 210 return new_ptr; |
| 205 } | 211 } |
| 206 | 212 |
| 207 // heapinit.c | 213 // heapinit.c |
| 208 intptr_t _get_heap_handle() { | 214 intptr_t _get_heap_handle() { |
| 209 return reinterpret_cast<intptr_t>(_crtheap); | 215 return reinterpret_cast<intptr_t>(_crtheap); |
| 210 } | 216 } |
| 211 | 217 |
| 212 // heapinit.c | 218 // heapinit.c |
| 213 int _heap_init() { | 219 int _heap_init() { |
| 220 base::allocator::g_is_win_shim_layer_initialized = true; |
| 214 return win_heap_init() ? 1 : 0; | 221 return win_heap_init() ? 1 : 0; |
| 215 } | 222 } |
| 216 | 223 |
| 217 // heapinit.c | 224 // heapinit.c |
| 218 void _heap_term() { | 225 void _heap_term() { |
| 219 win_heap_term(); | 226 win_heap_term(); |
| 220 } | 227 } |
| 221 | 228 |
| 222 // calloc.c | 229 // calloc.c |
| 223 void* calloc(size_t n, size_t elem_size) { | 230 void* calloc(size_t n, size_t elem_size) { |
| (...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 313 void _free_dbg(void* ptr, int) { | 320 void _free_dbg(void* ptr, int) { |
| 314 free(ptr); | 321 free(ptr); |
| 315 } | 322 } |
| 316 | 323 |
| 317 void* _calloc_dbg(size_t n, size_t size, int, const char*, int) { | 324 void* _calloc_dbg(size_t n, size_t size, int, const char*, int) { |
| 318 return calloc(n, size); | 325 return calloc(n, size); |
| 319 } | 326 } |
| 320 #endif // NDEBUG | 327 #endif // NDEBUG |
| 321 | 328 |
| 322 } // extern C | 329 } // extern C |
| OLD | NEW |