1 // Copyright 2016 The Chromium Authors 2 // Use of this source code is governed by a BSD-style license that can be 3 // found in the LICENSE file. 4 5 // Thin allocation wrappers for the windows heap. This file should be deleted 6 // once the win-specific allocation shim has been removed, and the generic shim 7 // has becaome the default. 8 9 #ifndef BASE_ALLOCATOR_PARTITION_ALLOCATOR_SRC_PARTITION_ALLOC_SHIM_WINHEAP_STUBS_WIN_H_ 10 #define BASE_ALLOCATOR_PARTITION_ALLOCATOR_SRC_PARTITION_ALLOC_SHIM_WINHEAP_STUBS_WIN_H_ 11 12 #include <stdint.h> 13 14 #include "partition_alloc/partition_alloc_buildflags.h" 15 16 #if BUILDFLAG(USE_ALLOCATOR_SHIM) 17 #include "partition_alloc/partition_alloc_base/component_export.h" 18 19 namespace allocator_shim { 20 21 // Set to true if the link-time magic has successfully hooked into the CRT's 22 // heap initialization. 23 extern bool g_is_win_shim_layer_initialized; 24 25 // Thin wrappers to implement the standard C allocation semantics on the 26 // CRT's Windows heap. 27 void* WinHeapMalloc(size_t size); 28 void WinHeapFree(void* ptr); 29 void* WinHeapRealloc(void* ptr, size_t size); 30 31 // Returns a lower-bound estimate for the full amount of memory consumed by the 32 // the allocation |ptr|. 33 size_t WinHeapGetSizeEstimate(void* ptr); 34 35 // Call the new handler, if one has been set. 36 // Returns true on successfully calling the handler, false otherwise. 37 bool WinCallNewHandler(size_t size); 38 39 // Wrappers to implement the interface for the _aligned_* functions on top of 40 // the CRT's Windows heap. Exported for tests. 41 PA_COMPONENT_EXPORT(ALLOCATOR_SHIM) 42 void* WinHeapAlignedMalloc(size_t size, size_t alignment); 43 PA_COMPONENT_EXPORT(ALLOCATOR_SHIM) 44 void* WinHeapAlignedRealloc(void* ptr, size_t size, size_t alignment); 45 PA_COMPONENT_EXPORT(ALLOCATOR_SHIM) void WinHeapAlignedFree(void* ptr); 46 47 } // namespace allocator_shim 48 49 #endif // BUILDFLAG(USE_ALLOCATOR_SHIM) 50 51 #endif // BASE_ALLOCATOR_PARTITION_ALLOCATOR_SRC_PARTITION_ALLOC_SHIM_WINHEAP_STUBS_WIN_H_ 52