Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 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 | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #include "base/allocator/allocator_shim.h" | |
| 6 | |
| 7 #include "base/allocator/winheap_stubs_win.h" | |
| 8 #include "base/logging.h" | |
| 9 | |
| 10 namespace { | |
| 11 | |
| 12 using base::allocator::AllocatorDispatch; | |
| 13 | |
| 14 void* DefaultWinHeapMallocImpl(const AllocatorDispatch*, size_t size) { | |
| 15 return base::allocator::WinHeapMalloc(size); | |
| 16 } | |
| 17 | |
| 18 void* DefaultWinHeapCallocImpl(const AllocatorDispatch* self, | |
| 19 size_t n, | |
| 20 size_t elem_size) { | |
| 21 // Overflow check. | |
| 22 const size_t size = n * elem_size; | |
| 23 if (elem_size != 0 && size / elem_size != n) | |
| 24 return nullptr; | |
| 25 | |
| 26 void* result = DefaultWinHeapMallocImpl(self, size); | |
| 27 if (result) { | |
| 28 memset(result, 0, size); | |
| 29 } | |
| 30 return result; | |
| 31 } | |
| 32 | |
| 33 void* DefaultWinHeapMemalignImpl(const AllocatorDispatch* self, | |
| 34 size_t alignment, | |
| 35 size_t size) { | |
| 36 CHECK(false) << "The windows heap does not support memalign."; | |
|
Will Harris
2016/07/15 15:49:54
won't this check hit a lot?
Primiano Tucci (use gerrit)
2016/07/15 17:58:09
my understand is that memalign is a posix inventio
Sigurður Ásgeirsson
2016/07/18 19:27:06
The Win heap doesn't (AFAIK) support aligned alloc
Sigurður Ásgeirsson
2016/07/18 19:27:06
Nopes, nothing on Windows should call memalign, an
| |
| 37 return nullptr; | |
| 38 } | |
| 39 | |
| 40 void* DefaultWinHeapReallocImpl(const AllocatorDispatch* self, | |
| 41 void* address, | |
| 42 size_t size) { | |
| 43 return base::allocator::WinHeapRealloc(address, size); | |
| 44 } | |
| 45 | |
| 46 void DefaultWinHeapFreeImpl(const AllocatorDispatch*, void* address) { | |
| 47 base::allocator::WinHeapFree(address); | |
| 48 } | |
| 49 | |
| 50 } // namespace | |
| 51 | |
| 52 const AllocatorDispatch AllocatorDispatch::default_dispatch = { | |
| 53 &DefaultWinHeapMallocImpl, &DefaultWinHeapCallocImpl, | |
| 54 &DefaultWinHeapMemalignImpl, &DefaultWinHeapReallocImpl, | |
| 55 &DefaultWinHeapFreeImpl, nullptr, /* next */ | |
| 56 }; | |
| OLD | NEW |