OLD | NEW |
1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 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/allocator/allocator_shim.h" | 5 #include "base/allocator/allocator_shim.h" |
6 | 6 |
7 #include "base/allocator/winheap_stubs_win.h" | 7 #include "base/allocator/winheap_stubs_win.h" |
8 #include "base/logging.h" | 8 #include "base/logging.h" |
9 | 9 |
10 namespace { | 10 namespace { |
11 | 11 |
12 using base::allocator::AllocatorDispatch; | 12 using base::allocator::AllocatorDispatch; |
13 | 13 |
14 void* DefaultWinHeapMallocImpl(const AllocatorDispatch*, size_t size) { | 14 void* DefaultWinHeapMallocImpl(const AllocatorDispatch*, |
| 15 size_t size, |
| 16 void* context) { |
15 return base::allocator::WinHeapMalloc(size); | 17 return base::allocator::WinHeapMalloc(size); |
16 } | 18 } |
17 | 19 |
18 void* DefaultWinHeapCallocImpl(const AllocatorDispatch* self, | 20 void* DefaultWinHeapCallocImpl(const AllocatorDispatch* self, |
19 size_t n, | 21 size_t n, |
20 size_t elem_size) { | 22 size_t elem_size, |
| 23 void* context) { |
21 // Overflow check. | 24 // Overflow check. |
22 const size_t size = n * elem_size; | 25 const size_t size = n * elem_size; |
23 if (elem_size != 0 && size / elem_size != n) | 26 if (elem_size != 0 && size / elem_size != n) |
24 return nullptr; | 27 return nullptr; |
25 | 28 |
26 void* result = DefaultWinHeapMallocImpl(self, size); | 29 void* result = DefaultWinHeapMallocImpl(self, size, context); |
27 if (result) { | 30 if (result) { |
28 memset(result, 0, size); | 31 memset(result, 0, size); |
29 } | 32 } |
30 return result; | 33 return result; |
31 } | 34 } |
32 | 35 |
33 void* DefaultWinHeapMemalignImpl(const AllocatorDispatch* self, | 36 void* DefaultWinHeapMemalignImpl(const AllocatorDispatch* self, |
34 size_t alignment, | 37 size_t alignment, |
35 size_t size) { | 38 size_t size, |
| 39 void* context) { |
36 CHECK(false) << "The windows heap does not support memalign."; | 40 CHECK(false) << "The windows heap does not support memalign."; |
37 return nullptr; | 41 return nullptr; |
38 } | 42 } |
39 | 43 |
40 void* DefaultWinHeapReallocImpl(const AllocatorDispatch* self, | 44 void* DefaultWinHeapReallocImpl(const AllocatorDispatch* self, |
41 void* address, | 45 void* address, |
42 size_t size) { | 46 size_t size, |
| 47 void* context) { |
43 return base::allocator::WinHeapRealloc(address, size); | 48 return base::allocator::WinHeapRealloc(address, size); |
44 } | 49 } |
45 | 50 |
46 void DefaultWinHeapFreeImpl(const AllocatorDispatch*, void* address) { | 51 void DefaultWinHeapFreeImpl(const AllocatorDispatch*, |
| 52 void* address, |
| 53 void* context) { |
47 base::allocator::WinHeapFree(address); | 54 base::allocator::WinHeapFree(address); |
48 } | 55 } |
49 | 56 |
50 size_t DefaultWinHeapGetSizeEstimateImpl(const AllocatorDispatch*, | 57 size_t DefaultWinHeapGetSizeEstimateImpl(const AllocatorDispatch*, |
51 void* address) { | 58 void* address, |
| 59 void* context) { |
52 return base::allocator::WinHeapGetSizeEstimate(address); | 60 return base::allocator::WinHeapGetSizeEstimate(address); |
53 } | 61 } |
54 | 62 |
55 } // namespace | 63 } // namespace |
56 | 64 |
57 const AllocatorDispatch AllocatorDispatch::default_dispatch = { | 65 const AllocatorDispatch AllocatorDispatch::default_dispatch = { |
58 &DefaultWinHeapMallocImpl, | 66 &DefaultWinHeapMallocImpl, |
59 &DefaultWinHeapCallocImpl, | 67 &DefaultWinHeapCallocImpl, |
60 &DefaultWinHeapMemalignImpl, | 68 &DefaultWinHeapMemalignImpl, |
61 &DefaultWinHeapReallocImpl, | 69 &DefaultWinHeapReallocImpl, |
62 &DefaultWinHeapFreeImpl, | 70 &DefaultWinHeapFreeImpl, |
63 &DefaultWinHeapGetSizeEstimateImpl, | 71 &DefaultWinHeapGetSizeEstimateImpl, |
64 nullptr, /* batch_malloc_function */ | 72 nullptr, /* batch_malloc_function */ |
65 nullptr, /* batch_free_function */ | 73 nullptr, /* batch_free_function */ |
66 nullptr, /* free_definite_size_function */ | 74 nullptr, /* free_definite_size_function */ |
67 nullptr, /* next */ | 75 nullptr, /* next */ |
68 }; | 76 }; |
OLD | NEW |