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 <vector> | 9 #include <vector> |
10 | 10 |
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
65 // deleted. | 65 // deleted. |
66 // For details on the possible parameters refer to <linux/filter.h> | 66 // For details on the possible parameters refer to <linux/filter.h> |
67 Instruction* MakeInstruction(uint16_t code, | 67 Instruction* MakeInstruction(uint16_t code, |
68 uint32_t k, | 68 uint32_t k, |
69 Instruction* next = NULL); | 69 Instruction* next = NULL); |
70 Instruction* MakeInstruction(uint16_t code, | 70 Instruction* MakeInstruction(uint16_t code, |
71 uint32_t k, | 71 uint32_t k, |
72 Instruction* jt, | 72 Instruction* jt, |
73 Instruction* jf); | 73 Instruction* jf); |
74 | 74 |
75 // Traverse the graph of instructions and visit each instruction once. | |
76 // Traversal order is implementation-defined. It is acceptable to make | |
77 // changes to the graph from within the callback function. These changes | |
78 // do not affect traversal. | |
79 // The "fnc" function gets called with both the instruction and the opaque | |
80 // "aux" pointer. | |
81 void Traverse(Instruction*, void (*fnc)(Instruction*, void* aux), void* aux); | |
82 | |
83 // Compiles the graph of instructions into a BPF program that can be passed | 75 // Compiles the graph of instructions into a BPF program that can be passed |
84 // to the kernel. Please note that this function modifies the graph in place | 76 // to the kernel. Please note that this function modifies the graph in place |
85 // and must therefore only be called once per graph. | 77 // and must therefore only be called once per graph. |
86 void Compile(Instruction* instructions, SandboxBPF::Program* program); | 78 void Compile(Instruction* instructions, SandboxBPF::Program* program); |
87 | 79 |
88 private: | 80 private: |
89 friend class CodeGenUnittestHelper; | 81 friend class CodeGenUnittestHelper; |
90 | 82 |
91 // Find all the instructions that are the target of BPF_JMPs. | 83 // Find all the instructions that are the target of BPF_JMPs. |
92 void FindBranchTargets(const Instruction& instructions, | 84 void FindBranchTargets(const Instruction& instructions, |
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
143 BasicBlocks basic_blocks_; | 135 BasicBlocks basic_blocks_; |
144 | 136 |
145 // Compile() must only ever be called once as it makes destructive changes | 137 // Compile() must only ever be called once as it makes destructive changes |
146 // to the DAG. | 138 // to the DAG. |
147 bool compiled_; | 139 bool compiled_; |
148 }; | 140 }; |
149 | 141 |
150 } // namespace sandbox | 142 } // namespace sandbox |
151 | 143 |
152 #endif // SANDBOX_LINUX_SECCOMP_BPF_CODEGEN_H__ | 144 #endif // SANDBOX_LINUX_SECCOMP_BPF_CODEGEN_H__ |
OLD | NEW |