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 : // An implementation of HeapInterface that wraps the Windows heap API.
16 :
17 : #ifndef SYZYGY_AGENT_ASAN_HEAPS_WIN_HEAP_H_
18 : #define SYZYGY_AGENT_ASAN_HEAPS_WIN_HEAP_H_
19 :
20 : #include <windows.h>
21 :
22 : #include "base/logging.h"
23 : #include "syzygy/agent/asan/heap.h"
24 : #include "syzygy/common/recursive_lock.h"
25 :
26 m : namespace agent {
27 m : namespace asan {
28 m : namespace heaps {
29 :
30 m : class WinHeap : public HeapInterface {
31 m : public:
32 : // Constructor. Creates a heap that is owned uniquely by this object.
33 m : WinHeap();
34 :
35 : // Constructor that wraps an existing heap. Ownership of the heap remains
36 : // external to this object.
37 m : explicit WinHeap(HANDLE heap);
38 :
39 : // Destructor.
40 m : virtual ~WinHeap();
41 :
42 : // @name HeapInterface functions.
43 : // @{
44 m : virtual HeapType GetHeapType() const;
45 m : virtual uint32 GetHeapFeatures() const;
46 m : virtual void* Allocate(size_t bytes);
47 m : virtual bool Free(void* alloc);
48 m : virtual bool IsAllocated(const void* alloc);
49 m : virtual size_t GetAllocationSize(const void* alloc);
50 m : virtual void Lock();
51 m : virtual void Unlock();
52 m : virtual bool TryLock();
53 : // @}
54 :
55 m : protected:
56 : // The heap that is wrapped by this object.
57 m : HANDLE heap_;
58 :
59 : // If true then this object owns the wrapped heap.
60 m : bool own_heap_;
61 :
62 : // The lock that gates access to this heap. This is a little redundant as
63 : // the underlying heap has its own lock, but it allows 'try' locking
64 : // semantics by our manager and heap checker.
65 m : ::common::RecursiveLock lock_;
66 :
67 : // True if the heap lock itself is held. Under lock_.
68 m : bool heap_lock_held_;
69 :
70 m : private:
71 m : DISALLOW_COPY_AND_ASSIGN(WinHeap);
72 m : };
73 :
74 m : } // namespace heaps
75 m : } // namespace asan
76 m : } // namespace agent
77 :
78 : #endif // SYZYGY_AGENT_ASAN_HEAPS_WIN_HEAP_H_
|