Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #ifndef SANDBOX_LINUX_SECCOMP_BPF_CODEGEN_H__ | 5 #ifndef SANDBOX_LINUX_SECCOMP_BPF_CODEGEN_H__ |
| 6 #define SANDBOX_LINUX_SECCOMP_BPF_CODEGEN_H__ | 6 #define SANDBOX_LINUX_SECCOMP_BPF_CODEGEN_H__ |
| 7 | 7 |
| 8 #include <map> | 8 #include <map> |
| 9 #include <set> | 9 #include <set> |
| 10 #include <vector> | 10 #include <vector> |
| (...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 70 Instruction *next = NULL); | 70 Instruction *next = NULL); |
| 71 Instruction *MakeInstruction(uint16_t code, const ErrorCode& err); | 71 Instruction *MakeInstruction(uint16_t code, const ErrorCode& err); |
| 72 Instruction *MakeInstruction(uint16_t code, uint32_t k, | 72 Instruction *MakeInstruction(uint16_t code, uint32_t k, |
| 73 Instruction *jt, Instruction *jf); | 73 Instruction *jt, Instruction *jf); |
| 74 | 74 |
| 75 // Join two (sequences of) instructions. This is useful, if the "next" | 75 // Join two (sequences of) instructions. This is useful, if the "next" |
| 76 // parameter had not originally been given in the call to MakeInstruction(), | 76 // parameter had not originally been given in the call to MakeInstruction(), |
| 77 // or if a (conditional) jump still has an unsatisfied target. | 77 // or if a (conditional) jump still has an unsatisfied target. |
| 78 void JoinInstructions(Instruction *head, Instruction *tail); | 78 void JoinInstructions(Instruction *head, Instruction *tail); |
| 79 | 79 |
| 80 // Traverse the graph of instructions and visit each instruction once. | |
| 81 // Traversal order is implementation-defined. It is acceptable to make | |
| 82 // changes to the graph from within the callback function. These changes | |
| 83 // do not affect traversal. | |
| 84 void Traverse(Instruction *, void (*fnc)(Instruction *, void *), void *); | |
|
jln (very slow on Chromium)
2012/11/15 01:51:52
Please, name and document the parameter, this is i
| |
| 85 | |
| 80 // Compiles the graph of instructions into a BPF program that can be passed | 86 // Compiles the graph of instructions into a BPF program that can be passed |
| 81 // to the kernel. Please note that this function modifies the graph in place | 87 // to the kernel. Please note that this function modifies the graph in place |
| 82 // and must therefore only be called once per graph. | 88 // and must therefore only be called once per graph. |
| 83 void Compile(Instruction *instructions, Sandbox::Program *program); | 89 void Compile(Instruction *instructions, Sandbox::Program *program); |
| 84 | 90 |
| 85 private: | 91 private: |
| 86 friend class CodeGenUnittestHelper; | 92 friend class CodeGenUnittestHelper; |
| 87 | 93 |
| 94 // Helper function for Traverse() | |
|
jln (very slow on Chromium)
2012/11/15 01:51:52
Nit: "." at the end.
| |
| 95 void TraverseRecursively(std::set<Instruction *> *, Instruction *); | |
|
jln (very slow on Chromium)
2012/11/15 01:51:52
Same here
| |
| 96 | |
| 88 // Find all the instructions that are the target of BPF_JMPs. | 97 // Find all the instructions that are the target of BPF_JMPs. |
| 89 void FindBranchTargets(const Instruction& instructions, | 98 void FindBranchTargets(const Instruction& instructions, |
| 90 BranchTargets *branch_targets); | 99 BranchTargets *branch_targets); |
| 91 | 100 |
| 92 // Combine instructions between "head" and "tail" into a new basic block. | 101 // Combine instructions between "head" and "tail" into a new basic block. |
| 93 // Basic blocks are defined as sequences of instructions whose only branch | 102 // Basic blocks are defined as sequences of instructions whose only branch |
| 94 // target is the very first instruction; furthermore, any BPF_JMP or BPF_RET | 103 // target is the very first instruction; furthermore, any BPF_JMP or BPF_RET |
| 95 // instruction must be at the very end of the basic block. | 104 // instruction must be at the very end of the basic block. |
| 96 BasicBlock *MakeBasicBlock(Instruction *head, Instruction *tail); | 105 BasicBlock *MakeBasicBlock(Instruction *head, Instruction *tail); |
| 97 | 106 |
| (...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 138 BasicBlocks basic_blocks_; | 147 BasicBlocks basic_blocks_; |
| 139 | 148 |
| 140 // Compile() must only ever be called once as it makes destructive changes | 149 // Compile() must only ever be called once as it makes destructive changes |
| 141 // to the DAG. | 150 // to the DAG. |
| 142 bool compiled_; | 151 bool compiled_; |
| 143 }; | 152 }; |
| 144 | 153 |
| 145 } // namespace | 154 } // namespace |
| 146 | 155 |
| 147 #endif // SANDBOX_LINUX_SECCOMP_BPF_CODEGEN_H__ | 156 #endif // SANDBOX_LINUX_SECCOMP_BPF_CODEGEN_H__ |
| OLD | NEW |