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<uint8*>(nullptr), info.block);
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<uint8*>(nullptr), info.block);
40 : const BlockTrailer* trailer = reinterpret_cast<const BlockTrailer*>(
41 E : info.block + info.block_size) - 1;
42 E : return trailer->alloc_ticks + reinterpret_cast<size_t>(info.block);
43 E : }
44 : };
45 :
46 : // Checks if a block is corrupt. This checks the block's metadata and its
47 : // checksum.
48 : // @param block_header A pointer to the block header of the block.
49 : // @param block_info Will be filled in with pointers to the various portions
50 : // of the block if this function succeeds. May be NULL.
51 : // @returns true if the block is corrupt, false otherwise.
52 : // @note The pages containing the block redzones must be readable.
53 : bool IsBlockCorrupt(const uint8* block_header, BlockInfo* block_info);
54 :
55 : } // namespace asan
56 : } // namespace agent
57 :
58 : #endif // SYZYGY_AGENT_ASAN_BLOCK_UTILS_H_
|