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 : // Declares HeapChecker, a class that checks a heap for corruption.
16 :
17 : #ifndef SYZYGY_AGENT_ASAN_HEAP_CHECKER_H_
18 : #define SYZYGY_AGENT_ASAN_HEAP_CHECKER_H_
19 :
20 : #include <vector>
21 :
22 : #include "base/logging.h"
23 : #include "syzygy/agent/asan/error_info.h"
24 : #include "syzygy/agent/common/stack_capture.h"
25 :
26 m : namespace agent {
27 m : namespace asan {
28 :
29 : // Forward declarations.
30 m : class AsanRuntime;
31 m : class Shadow;
32 :
33 : // A class to analyze the heap and to check if it's corrupt.
34 m : class HeapChecker {
35 m : public:
36 m : typedef std::vector<AsanCorruptBlockRange> CorruptRangesVector;
37 :
38 : // Constructor.
39 : // @param shadow The shadow memory to query.
40 m : explicit HeapChecker(Shadow* shadow);
41 :
42 : // Checks if the heap is corrupt and returns the information about the
43 : // corrupt ranges. This permanently removes all page protections as it
44 : // walks through memory.
45 : // @param corrupt_ranges Will receive the information about the corrupt
46 : // ranges.
47 : // @returns true if the heap is corrupt, false otherwise.
48 m : bool IsHeapCorrupt(CorruptRangesVector* corrupt_ranges);
49 :
50 : // TODO(sebmarchand): Add a testing seam that controls the range of memory
51 : // that is walked by HeapChecker to keep unittest times to something
52 : // reasonable.
53 :
54 m : private:
55 : // Get the information about the corrupt ranges in a heap slab.
56 : // @param lower_bound The lower bound for this slab.
57 : // @param length The length of this slab.
58 : // @param corrupt_ranges Will receive the information about the corrupt ranges
59 : // in this slab.
60 m : void GetCorruptRangesInSlab(const uint8_t* lower_bound,
61 m : size_t length,
62 m : CorruptRangesVector* corrupt_ranges);
63 :
64 : // The shadow memory that will be analyzed.
65 m : Shadow* shadow_;
66 :
67 m : DISALLOW_COPY_AND_ASSIGN(HeapChecker);
68 m : };
69 :
70 m : } // namespace asan
71 m : } // namespace agent
72 :
73 : #endif // SYZYGY_AGENT_ASAN_HEAP_CHECKER_H_
|