Chromium Code Reviews| Index: base/allocator/win_allocator.cc |
| diff --git a/base/allocator/win_allocator.cc b/base/allocator/win_allocator.cc |
| index 8ae653a690ed033b5e708e7021f98998082f0ca1..50b83e9a4dfd277bf42aa3a7989f7f343ba2048e 100644 |
| --- a/base/allocator/win_allocator.cc |
| +++ b/base/allocator/win_allocator.cc |
| @@ -47,4 +47,21 @@ size_t win_heap_msize(void* ptr) { |
| return HeapSize(win_heap, 0, ptr); |
| } |
| +void* win_heap_memalign(size_t alignment, size_t size) { |
| + // Reserve enough space to ensure we can align and set aligned_ptr[-1] to the |
|
jar (doing other things)
2012/07/30 23:04:22
I think you may want to be cautious about args her
DaleCurtis
2012/07/31 00:44:22
Can you elaborate on the trouble we could face? Fr
jar (doing other things)
2012/07/31 03:18:51
I didn't see where the args were being validated.
DaleCurtis
2012/07/31 03:39:48
Gotcha, I thought there might be some weird HeapAl
|
| + // original allocation for use with win_heap_memalign_free() later. |
| + void* ptr = win_heap_malloc(size + (alignment - 1) + sizeof(void*)); |
| + |
| + char* aligned_ptr = static_cast<char*>(ptr) + sizeof(void*); |
| + aligned_ptr += |
| + alignment - reinterpret_cast<uintptr_t>(aligned_ptr) & (alignment - 1); |
| + |
| + reinterpret_cast<void**>(aligned_ptr)[-1] = ptr; |
| + return aligned_ptr; |
| +} |
| + |
| +void win_heap_memalign_free(void* ptr) { |
| + win_heap_free(static_cast<void**>(ptr)[-1]); |
| +} |
| + |
| } // extern "C" |