1 : // Copyright 2015 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 : #include "syzygy/bard/backdrops/heap_backdrop.h"
16 :
17 : #include "base/logging.h"
18 :
19 : namespace bard {
20 : namespace backdrops {
21 :
22 E : HeapBackdrop::HeapBackdrop() {
23 E : }
24 :
25 E : LPVOID HeapBackdrop::HeapAlloc(HANDLE heap, DWORD flags, SIZE_T bytes) {
26 E : DCHECK(!heap_alloc_.is_null());
27 E : return heap_alloc_.Run(heap, flags, bytes);
28 E : }
29 :
30 : HANDLE HeapBackdrop::HeapCreate(DWORD options,
31 : SIZE_T initial_size,
32 E : SIZE_T maximum_size) {
33 E : DCHECK(!heap_create_.is_null());
34 E : return heap_create_.Run(options, initial_size, maximum_size);
35 E : }
36 :
37 E : BOOL HeapBackdrop::HeapDestroy(HANDLE heap) {
38 E : DCHECK(!heap_destroy_.is_null());
39 E : return heap_destroy_.Run(heap);
40 E : }
41 :
42 E : BOOL HeapBackdrop::HeapFree(HANDLE heap, DWORD flags, LPVOID mem) {
43 E : DCHECK(!heap_free_.is_null());
44 E : return heap_free_.Run(heap, flags, mem);
45 E : }
46 :
47 : LPVOID HeapBackdrop::HeapReAlloc(HANDLE heap,
48 : DWORD flags,
49 : LPVOID mem,
50 E : SIZE_T bytes) {
51 E : DCHECK(!heap_realloc_.is_null());
52 E : return heap_realloc_.Run(heap, flags, mem, bytes);
53 E : }
54 :
55 : BOOL HeapBackdrop::HeapSetInformation(HANDLE heap,
56 : HEAP_INFORMATION_CLASS info_class,
57 : PVOID info,
58 E : SIZE_T info_length) {
59 E : DCHECK(!heap_set_information_.is_null());
60 E : return heap_set_information_.Run(heap, info_class, info, info_length);
61 E : }
62 :
63 E : SIZE_T HeapBackdrop::HeapSize(HANDLE heap, DWORD flags, LPCVOID mem) {
64 E : DCHECK(!heap_size_.is_null());
65 E : return heap_size_.Run(heap, flags, mem);
66 E : }
67 :
68 E : void HeapBackdrop::UpdateStats(EventType type, uint64_t time) {
69 E : base::AutoLock auto_lock(lock_);
70 :
71 E : auto stats = total_stats_.insert(std::make_pair(type, struct Stats())).first;
72 E : stats->second.calls++;
73 E : stats->second.time += time;
74 E : }
75 :
76 : } // namespace backdrops
77 : } // namespace bard
|