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 #include "sandbox/linux/seccomp-bpf/codegen.h" | 5 #include "sandbox/linux/seccomp-bpf/codegen.h" |
6 | 6 |
7 #include <stdio.h> | 7 #include <stdio.h> |
8 | 8 |
9 #include <set> | 9 #include <set> |
10 | 10 |
(...skipping 154 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
165 instructions_.push_back(insn); | 165 instructions_.push_back(insn); |
166 return insn; | 166 return insn; |
167 } else { | 167 } else { |
168 // Non-jumping instructions do not use any of the branch targets. | 168 // Non-jumping instructions do not use any of the branch targets. |
169 Instruction* insn = new Instruction(code, k, next); | 169 Instruction* insn = new Instruction(code, k, next); |
170 instructions_.push_back(insn); | 170 instructions_.push_back(insn); |
171 return insn; | 171 return insn; |
172 } | 172 } |
173 } | 173 } |
174 | 174 |
175 Instruction* CodeGen::MakeInstruction(uint16_t code, const ErrorCode& err) { | |
176 if (BPF_CLASS(code) != BPF_RET) { | |
177 SANDBOX_DIE("ErrorCodes can only be used in return expressions"); | |
178 } | |
179 if (err.error_type_ != ErrorCode::ET_SIMPLE && | |
180 err.error_type_ != ErrorCode::ET_TRAP) { | |
181 SANDBOX_DIE("ErrorCode is not suitable for returning from a BPF program"); | |
182 } | |
183 return MakeInstruction(code, err.err_); | |
184 } | |
185 | |
186 Instruction* CodeGen::MakeInstruction(uint16_t code, | 175 Instruction* CodeGen::MakeInstruction(uint16_t code, |
187 uint32_t k, | 176 uint32_t k, |
188 Instruction* jt, | 177 Instruction* jt, |
189 Instruction* jf) { | 178 Instruction* jf) { |
190 // We can handle all conditional jumps. They are followed by both a | 179 // We can handle all conditional jumps. They are followed by both a |
191 // "true" and a "false" branch. | 180 // "true" and a "false" branch. |
192 if (BPF_CLASS(code) != BPF_JMP || BPF_OP(code) == BPF_JA) { | 181 if (BPF_CLASS(code) != BPF_JMP || BPF_OP(code) == BPF_JA) { |
193 SANDBOX_DIE("Expected a BPF_JMP instruction"); | 182 SANDBOX_DIE("Expected a BPF_JMP instruction"); |
194 } | 183 } |
195 if (!jt && !jf) { | 184 if (!jt && !jf) { |
(...skipping 572 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
768 CutGraphIntoBasicBlocks(instructions, branch_targets, &all_blocks); | 757 CutGraphIntoBasicBlocks(instructions, branch_targets, &all_blocks); |
769 MergeTails(&all_blocks); | 758 MergeTails(&all_blocks); |
770 BasicBlocks basic_blocks; | 759 BasicBlocks basic_blocks; |
771 TopoSortBasicBlocks(first_block, all_blocks, &basic_blocks); | 760 TopoSortBasicBlocks(first_block, all_blocks, &basic_blocks); |
772 ComputeRelativeJumps(&basic_blocks, all_blocks); | 761 ComputeRelativeJumps(&basic_blocks, all_blocks); |
773 ConcatenateBasicBlocks(basic_blocks, program); | 762 ConcatenateBasicBlocks(basic_blocks, program); |
774 return; | 763 return; |
775 } | 764 } |
776 | 765 |
777 } // namespace sandbox | 766 } // namespace sandbox |
OLD | NEW |