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 PARTITION_ALLOC_SHIM_WINHEAP_STUBS_WIN_H_
10 #define PARTITION_ALLOC_SHIM_WINHEAP_STUBS_WIN_H_
11 
12 #include <cstdint>
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 PA_COMPONENT_EXPORT(ALLOCATOR_SHIM)
24 extern bool g_is_win_shim_layer_initialized;
25 
26 // Thin wrappers to implement the standard C allocation semantics on the
27 // CRT's Windows heap.
28 void* WinHeapMalloc(size_t size);
29 void WinHeapFree(void* ptr);
30 void* WinHeapRealloc(void* ptr, size_t size);
31 
32 // Returns a lower-bound estimate for the full amount of memory consumed by the
33 // the allocation |ptr|.
34 size_t WinHeapGetSizeEstimate(void* ptr);
35 
36 // Call the new handler, if one has been set.
37 // Returns true on successfully calling the handler, false otherwise.
38 bool WinCallNewHandler(size_t size);
39 
40 // Wrappers to implement the interface for the _aligned_* functions on top of
41 // the CRT's Windows heap. Exported for tests.
42 PA_COMPONENT_EXPORT(ALLOCATOR_SHIM)
43 void* WinHeapAlignedMalloc(size_t size, size_t alignment);
44 PA_COMPONENT_EXPORT(ALLOCATOR_SHIM)
45 void* WinHeapAlignedRealloc(void* ptr, size_t size, size_t alignment);
46 PA_COMPONENT_EXPORT(ALLOCATOR_SHIM) void WinHeapAlignedFree(void* ptr);
47 
48 }  // namespace allocator_shim
49 
50 #endif  // BUILDFLAG(USE_ALLOCATOR_SHIM)
51 
52 #endif  // PARTITION_ALLOC_SHIM_WINHEAP_STUBS_WIN_H_
53