1 : // Copyright 2014 Google Inc. All Rights Reserved.
2 : //
3 : // Licensed under the Apache License, Version 2.0 (the "License");
4 : // you may not use this file except in compliance with the License.
5 : // You may obtain a copy of the License at
6 : //
7 : // http://www.apache.org/licenses/LICENSE-2.0
8 : //
9 : // Unless required by applicable law or agreed to in writing, software
10 : // distributed under the License is distributed on an "AS IS" BASIS,
11 : // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 : // See the License for the specific language governing permissions and
13 : // limitations under the License.
14 : //
15 : // Implements an all-static class that act as a proxy between the Windows heap
16 : // interceptors and the Asan heaps.
17 : #ifndef SYZYGY_AGENT_ASAN_WINDOWS_HEAP_ADAPTER_H_
18 : #define SYZYGY_AGENT_ASAN_WINDOWS_HEAP_ADAPTER_H_
19 :
20 : #include <windows.h>
21 :
22 : #include "base\logging.h"
23 :
24 m : namespace agent {
25 m : namespace asan {
26 :
27 m : class HeapManagerInterface;
28 :
29 : // A WindowsHeapAdapter is responsible for translating the calls to the Windows
30 : // heap functions to their counterparts in a heap manager.
31 : //
32 : // This is an all static class which, once initialized with a
33 : // HeapManagerInterface, simply redirects the calls to this manager.
34 m : class WindowsHeapAdapter {
35 m : public:
36 : // Setup the WindowsHeapAdapter that this adapter delegates to.
37 : // @param heap_manager The heap manager that his adapter should use.
38 m : static void SetUp(HeapManagerInterface* heap_manager);
39 :
40 : // Tear down this adapter.
41 m : static void TearDown();
42 :
43 : // @name Windows Heap API.
44 : // @{
45 m : static HANDLE HeapCreate(DWORD options,
46 m : SIZE_T initial_size,
47 m : SIZE_T maximum_size);
48 m : static BOOL HeapDestroy(HANDLE heap);
49 m : static LPVOID HeapAlloc(HANDLE heap, DWORD flags, SIZE_T bytes);
50 m : static LPVOID WINAPI HeapReAlloc(HANDLE heap,
51 m : DWORD flags,
52 m : LPVOID mem,
53 m : SIZE_T bytes);
54 m : static BOOL HeapFree(HANDLE heap, DWORD flags, LPVOID mem);
55 m : static SIZE_T HeapSize(HANDLE heap, DWORD flags, LPCVOID mem);
56 m : static BOOL HeapValidate(HANDLE heap, DWORD flags, LPCVOID mem);
57 m : static SIZE_T HeapCompact(HANDLE heap, DWORD flags);
58 m : static BOOL HeapLock(HANDLE heap);
59 m : static BOOL HeapUnlock(HANDLE heap);
60 m : static BOOL HeapWalk(HANDLE heap, LPPROCESS_HEAP_ENTRY entry);
61 m : static BOOL HeapSetInformation(HANDLE heap,
62 m : HEAP_INFORMATION_CLASS info_class,
63 m : PVOID info,
64 m : SIZE_T info_length);
65 m : static BOOL HeapQueryInformation(HANDLE heap,
66 m : HEAP_INFORMATION_CLASS info_class,
67 m : PVOID info,
68 m : SIZE_T info_length,
69 m : PSIZE_T return_length);
70 : // @}
71 :
72 m : private:
73 : // The heap manager that we use internally.
74 m : static HeapManagerInterface* heap_manager_;
75 :
76 m : DISALLOW_COPY_AND_ASSIGN(WindowsHeapAdapter);
77 m : };
78 :
79 m : } // namespace asan
80 m : } // namespace agent
81 :
82 : #endif // SYZYGY_AGENT_ASAN_WINDOWS_HEAP_ADAPTER_H_
|