Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(2136)

Unified Diff: base/allocator/win_allocator.cc

Issue 10828054: Modify allocator_shim to support _aligned_alloc(), _aligned_free(). (Closed) Base URL: http://git.chromium.org/chromium/src.git@master
Patch Set: Land jemalloc.c change separately. Created 8 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « base/allocator/allocator_unittests.cc ('k') | third_party/jemalloc/README.chromium » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: base/allocator/win_allocator.cc
diff --git a/base/allocator/win_allocator.cc b/base/allocator/win_allocator.cc
index 8ae653a690ed033b5e708e7021f98998082f0ca1..5367509ba4f3abc855ead1b428231581ca16506d 100644
--- a/base/allocator/win_allocator.cc
+++ b/base/allocator/win_allocator.cc
@@ -47,4 +47,26 @@ 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
+ // original allocation for use with win_heap_memalign_free() later.
+ size_t allocation_size = size + (alignment - 1) + sizeof(void*);
+
+ // Check for overflow. Alignment and size are checked in allocator_shim.
+ DCHECK_LT(size, allocation_size);
+ DCHECK_LT(alignment, allocation_size);
+
+ void* ptr = win_heap_malloc(allocation_size);
+ 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"
« no previous file with comments | « base/allocator/allocator_unittests.cc ('k') | third_party/jemalloc/README.chromium » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698