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 <stdint.h> | 8 #include <stdint.h> |
9 | 9 |
10 #include <map> | 10 #include <map> |
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
56 // | 56 // |
57 class SANDBOX_EXPORT CodeGen { | 57 class SANDBOX_EXPORT CodeGen { |
58 public: | 58 public: |
59 // A vector of BPF instructions that need to be installed as a filter | 59 // A vector of BPF instructions that need to be installed as a filter |
60 // program in the kernel. | 60 // program in the kernel. |
61 typedef std::vector<struct sock_filter> Program; | 61 typedef std::vector<struct sock_filter> Program; |
62 | 62 |
63 CodeGen(); | 63 CodeGen(); |
64 ~CodeGen(); | 64 ~CodeGen(); |
65 | 65 |
66 // This is a helper method that can be used for debugging purposes. It is | |
67 // not normally called. | |
68 static void PrintProgram(const Program& program); | |
69 | |
70 // Create a new instruction. Instructions form a DAG. The instruction objects | 66 // Create a new instruction. Instructions form a DAG. The instruction objects |
71 // are owned by the CodeGen object. They do not need to be explicitly | 67 // are owned by the CodeGen object. They do not need to be explicitly |
72 // deleted. | 68 // deleted. |
73 // For details on the possible parameters refer to <linux/filter.h> | 69 // For details on the possible parameters refer to <linux/filter.h> |
74 Instruction* MakeInstruction(uint16_t code, | 70 Instruction* MakeInstruction(uint16_t code, |
75 uint32_t k, | 71 uint32_t k, |
76 Instruction* next = nullptr); | 72 Instruction* next = nullptr); |
77 Instruction* MakeInstruction(uint16_t code, | 73 Instruction* MakeInstruction(uint16_t code, |
78 uint32_t k, | 74 uint32_t k, |
79 Instruction* jt, | 75 Instruction* jt, |
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
142 BasicBlocks basic_blocks_; | 138 BasicBlocks basic_blocks_; |
143 | 139 |
144 // Compile() must only ever be called once as it makes destructive changes | 140 // Compile() must only ever be called once as it makes destructive changes |
145 // to the DAG. | 141 // to the DAG. |
146 bool compiled_; | 142 bool compiled_; |
147 }; | 143 }; |
148 | 144 |
149 } // namespace sandbox | 145 } // namespace sandbox |
150 | 146 |
151 #endif // SANDBOX_LINUX_SECCOMP_BPF_CODEGEN_H__ | 147 #endif // SANDBOX_LINUX_SECCOMP_BPF_CODEGEN_H__ |
OLD | NEW |