1 : // Copyright 2012 Google Inc.
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/pe/block_util.h"
16 :
17 : namespace block_graph {
18 :
19 : bool CodeBlockAttributesAreBasicBlockSafe(
20 E : const block_graph::BlockGraph::Block* block) {
21 E : DCHECK(block != NULL);
22 E : DCHECK_EQ(BlockGraph::CODE_BLOCK, block->type());
23 :
24 : // If the block was built by our toolchain it's inherently safe. This
25 : // attribute is used to whitelist a block.
26 E : if (block->attributes() & BlockGraph::BUILT_BY_SYZYGY)
27 E : return true;
28 :
29 : // Any of the following attributes make it unsafe to basic-block
30 : // decompose the code block.
31 : static const BlockGraph::BlockAttributes kInvalidAttributes =
32 : BlockGraph::GAP_BLOCK |
33 : BlockGraph::PADDING_BLOCK |
34 : BlockGraph::HAS_INLINE_ASSEMBLY |
35 : BlockGraph::BUILT_BY_UNSUPPORTED_COMPILER |
36 : BlockGraph::ERRORED_DISASSEMBLY |
37 : BlockGraph::HAS_EXCEPTION_HANDLING |
38 : BlockGraph::DISASSEMBLED_PAST_END;
39 E : if ((block->attributes() & kInvalidAttributes) != 0)
40 E : return false;
41 :
42 E : return true;
43 E : }
44 :
45 : } // namespace block_graph
|