1 : // Copyright 2012 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 : // Utilities for dealing with block-graphs and blocks.
16 :
17 : #ifndef SYZYGY_BLOCK_GRAPH_BLOCK_UTIL_H_
18 : #define SYZYGY_BLOCK_GRAPH_BLOCK_UTIL_H_
19 :
20 : #include "syzygy/block_graph/basic_block.h"
21 : #include "syzygy/block_graph/block_graph.h"
22 :
23 m : namespace block_graph {
24 :
25 : // Determines whether @p block's attributes preclude basic-block
26 : // decomposition.
27 : // @param block the code block whose attributes are to be inspected.
28 : // @returns true if the block attributes are safe for decomposition to basic-
29 : // blocks, false otherwise.
30 : // @pre block has type CODE_BLOCK.
31 m : bool CodeBlockAttributesAreBasicBlockSafe(const BlockGraph::Block* block);
32 :
33 : // Determines whether @p bb's instructions and successors comprise a contiguous
34 : // source range, and return it if so.
35 : // @param bb the basic block to inspect.
36 : // @param source_range returns @p bb's source range on success.
37 : // @returns true iff @p bb's instructions and successors comprise a contiguous
38 : // source range.
39 : // @note @p bb's source range is deemed contiguous if at least one instruction
40 : // or successor has a source range, and if all the source ranges constitute
41 : // a single contiguous range, irrespective order. This means that this
42 : // function may succeed even if instructions in @p bb have been added,
43 : // reordered or mutated.
44 m : bool GetBasicBlockSourceRange(const BasicCodeBlock& bb,
45 m : BlockGraph::Block::SourceRange* source_range);
46 :
47 : // Returns true if the given references @p ref from @p referrer may not safely
48 : // be redirected. If both the referrer and the referenced blocks are irregular
49 : // in any way (i.e., inline assembly, not generated by cl.exe, etc) we cannot
50 : // safely assume that @p ref has call semantics, i.e., where a return address
51 : // is at the top of stack at entry. Ideally we would decide this on the basis
52 : // of a full stack analysis, but beggars can't be choosers; plus, for
53 : // hand-coded assembly that's the halting problem :).
54 : // For any instrumentation or manipulation that uses return address swizzling,
55 : // instrumenting an unsafe reference generally leads to crashes.
56 m : bool IsUnsafeReference(const BlockGraph::Block* referrer,
57 m : const BlockGraph::Reference& ref);
58 :
59 m : } // namespace block_graph
60 :
61 : #endif // SYZYGY_BLOCK_GRAPH_BLOCK_UTIL_H_
|