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 : namespace agent {
27 : namespace asan {
28 :
29 : // Forward declaration.
30 : class AsanRuntime;
31 :
32 : // A class to analyze the heap and to check if it's corrupt.
33 : class HeapChecker {
34 : public:
35 : typedef std::vector<AsanCorruptBlockRange> CorruptRangesVector;
36 :
37 : // Constructor.
38 E : HeapChecker() { }
39 :
40 : // Checks if the heap is corrupt and returns the information about the
41 : // corrupt ranges. This permanently removes all page protections as it
42 : // walks through memory.
43 : // @param corrupt_ranges Will receive the information about the corrupt
44 : // ranges.
45 : // @returns true if the heap is corrupt, false otherwise.
46 : bool IsHeapCorrupt(CorruptRangesVector* corrupt_ranges);
47 :
48 : // TODO(sebmarchand): Add a testing seam that controls the range of memory
49 : // that is walked by HeapChecker to keep unittest times to something
50 : // reasonable.
51 :
52 : private:
53 : // Get the information about the corrupt ranges in a heap slab.
54 : // @param lower_bound The lower bound for this slab.
55 : // @param length The length of this slab.
56 : // @param corrupt_ranges Will receive the information about the corrupt ranges
57 : // in this slab.
58 : void GetCorruptRangesInSlab(const uint8* lower_bound,
59 : size_t length,
60 : CorruptRangesVector* corrupt_ranges);
61 : };
62 :
63 : } // namespace asan
64 : } // namespace agent
65 :
66 : #endif // SYZYGY_AGENT_ASAN_HEAP_CHECKER_H_
|