Index: base/allocator/allocator_shim.cc |
diff --git a/base/allocator/allocator_shim.cc b/base/allocator/allocator_shim.cc |
index fd6d741c04d3e195c00305477fbf9a26553e38dc..a16c106ec893589c00e8c7587575cc32b0ccc712 100644 |
--- a/base/allocator/allocator_shim.cc |
+++ b/base/allocator/allocator_shim.cc |
@@ -65,6 +65,7 @@ void* je_realloc(void* p, size_t s); |
void je_free(void* s); |
size_t je_msize(void* p); |
bool je_malloc_init_hard(); |
+void* je_memalign(size_t a, size_t s); |
} |
extern "C" { |
@@ -299,6 +300,53 @@ extern "C" void _heap_term() {} |
// the rest of the CRT is still usable. |
extern "C" void* _crtheap = reinterpret_cast<void*>(1); |
+// Provide support for aligned memory through Windows only _aligned_malloc(). |
+void* _aligned_malloc(size_t size, size_t alignment) { |
+ void* ptr; |
+ for (;;) { |
+#ifdef ENABLE_DYNAMIC_ALLOCATOR_SWITCHING |
+ switch (allocator) { |
+ case JEMALLOC: |
+ ptr = je_memalign(alignment, size); |
+ break; |
+ case WINHEAP: |
+ case WINLFH: |
+ ptr = win_heap_memalign(alignment, size); |
+ break; |
+ case TCMALLOC: |
+ default: |
+ ptr = tc_memalign(alignment, size); |
+ break; |
+ } |
+#else |
+ // TCMalloc case. |
+ ptr = tc_memalign(alignment, size); |
+#endif |
+ if (ptr) |
+ return ptr; |
+ |
+ if (!new_mode || !call_new_handler(true)) |
+ break; |
+ } |
+ return ptr; |
+} |
+ |
+void _aligned_free(void* p) { |
+#ifdef ENABLE_DYNAMIC_ALLOCATOR_SWITCHING |
+ switch (allocator) { |
+ case JEMALLOC: |
+ je_free(p); |
+ return; |
+ case WINHEAP: |
+ case WINLFH: |
+ win_heap_memalign_free(p); |
+ return; |
+ } |
+#endif |
+ // TCMalloc case. |
+ do_free(p); |
+} |
+ |
#endif // WIN32 |
#include "generic_allocators.cc" |