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 : // Utility functions for working with Asan Blocks.
16 :
17 : #ifndef SYZYGY_AGENT_ASAN_BLOCK_UTILS_H_
18 : #define SYZYGY_AGENT_ASAN_BLOCK_UTILS_H_
19 :
20 : #include "base/logging.h"
21 : #include "syzygy/agent/asan/block.h"
22 : #include "syzygy/agent/asan/shadow.h"
23 :
24 : namespace agent {
25 : namespace asan {
26 :
27 : // A functor that retrieves the total size of an Asan allocation.
28 : struct GetTotalBlockSizeFunctor {
29 E : size_t operator()(const CompactBlockInfo& info) {
30 E : DCHECK_NE(static_cast<BlockHeader*>(nullptr), info.header);
31 E : return info.block_size;
32 E : }
33 : };
34 :
35 : // A functor for calculating a hash value associated with a block. This is used
36 : // by the sharded quarantine.
37 : struct GetBlockHashFunctor {
38 E : size_t operator()(const CompactBlockInfo& info) {
39 E : DCHECK_NE(static_cast<BlockHeader*>(nullptr), info.header);
40 : const BlockTrailer* trailer = reinterpret_cast<const BlockTrailer*>(
41 E : reinterpret_cast<const uint8*>(info.header) + info.block_size) - 1;
42 E : return trailer->alloc_ticks + reinterpret_cast<size_t>(info.header);
43 E : }
44 : };
45 :
46 : // Checks if a block is corrupt. This checks the block's metadata and its
47 : // checksum.
48 : // @param block_info The information about this block.
49 : // @returns true if the block is corrupt, false otherwise.
50 : // @note The pages containing the entire block must be readable.
51 : bool IsBlockCorrupt(const BlockInfo& block_info);
52 :
53 : } // namespace asan
54 : } // namespace agent
55 :
56 : #endif // SYZYGY_AGENT_ASAN_BLOCK_UTILS_H_
|