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