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 CtMalloc heap.
16 :
17 : #ifndef SYZYGY_AGENT_ASAN_HEAPS_CTMALLOC_HEAP_H_
18 : #define SYZYGY_AGENT_ASAN_HEAPS_CTMALLOC_HEAP_H_
19 :
20 : #include "base/logging.h"
21 : #include "base/memory/scoped_ptr.h"
22 : #include "syzygy/agent/asan/heap.h"
23 : #include "syzygy/agent/asan/memory_notifier.h"
24 : #include "syzygy/common/recursive_lock.h"
25 : #include "wtf/config.h"
26 : #include "wtf/PartitionAlloc.h"
27 :
28 m : namespace agent {
29 m : namespace asan {
30 m : namespace heaps {
31 :
32 m : class CtMallocHeap : public HeapInterface {
33 m : public:
34 : // Constructor. Creates a heap that is owned uniquely by this object.
35 : // @param memory_notifier The notifier that will be used to inform the
36 : // runtime of this heaps internal memory use.
37 m : explicit CtMallocHeap(MemoryNotifierInterface* memory_notifier);
38 :
39 : // Destructor.
40 m : virtual ~CtMallocHeap();
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 underlying heap. Under lock_.
57 m : PartitionAllocatorGeneric allocator_;
58 :
59 : // The interface that will be notified of internal memory use. Has its own
60 : // locking.
61 m : MemoryNotifierInterface* memory_notifier_;
62 :
63 : // The lock that gates access to this heap.
64 m : ::common::RecursiveLock lock_;
65 :
66 m : private:
67 m : DISALLOW_COPY_AND_ASSIGN(CtMallocHeap);
68 m : };
69 :
70 m : } // namespace heaps
71 m : } // namespace asan
72 m : } // namespace agent
73 :
74 : #endif // SYZYGY_AGENT_ASAN_HEAPS_CTMALLOC_HEAP_H_
|