| 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_INSTRUCTION_H__ | 5 #ifndef SANDBOX_LINUX_SECCOMP_BPF_INSTRUCTION_H__ |
| 6 #define SANDBOX_LINUX_SECCOMP_BPF_INSTRUCTION_H__ | 6 #define SANDBOX_LINUX_SECCOMP_BPF_INSTRUCTION_H__ |
| 7 | 7 |
| 8 #include <stdint.h> | 8 #include <stdint.h> |
| 9 | 9 |
| 10 | |
| 11 namespace playground2 { | 10 namespace playground2 { |
| 12 | 11 |
| 13 // The fields in this structure have the same meaning as the corresponding | 12 // The fields in this structure have the same meaning as the corresponding |
| 14 // fields in "struct sock_filter". See <linux/filter.h> for a lot more | 13 // fields in "struct sock_filter". See <linux/filter.h> for a lot more |
| 15 // detail. | 14 // detail. |
| 16 // code -- Opcode of the instruction. This is typically a bitwise | 15 // code -- Opcode of the instruction. This is typically a bitwise |
| 17 // combination BPF_XXX values. | 16 // combination BPF_XXX values. |
| 18 // k -- Operand; BPF instructions take zero or one operands. Operands | 17 // k -- Operand; BPF instructions take zero or one operands. Operands |
| 19 // are 32bit-wide constants, if present. They can be immediate | 18 // are 32bit-wide constants, if present. They can be immediate |
| 20 // values (if BPF_K is present in "code_"), addresses (if BPF_ABS | 19 // values (if BPF_K is present in "code_"), addresses (if BPF_ABS |
| 21 // is present in "code_"), or relative jump offsets (if BPF_JMP | 20 // is present in "code_"), or relative jump offsets (if BPF_JMP |
| 22 // and BPF_JA are present in "code_"). | 21 // and BPF_JA are present in "code_"). |
| 23 // jt, jf -- all conditional jumps have a 8bit-wide jump offset that allows | 22 // jt, jf -- all conditional jumps have a 8bit-wide jump offset that allows |
| 24 // jumps of up to 256 instructions forward. Conditional jumps are | 23 // jumps of up to 256 instructions forward. Conditional jumps are |
| 25 // identified by BPF_JMP in "code_", but the lack of BPF_JA. | 24 // identified by BPF_JMP in "code_", but the lack of BPF_JA. |
| 26 // Conditional jumps have a "t"rue and "f"alse branch. | 25 // Conditional jumps have a "t"rue and "f"alse branch. |
| 27 struct Instruction { | 26 struct Instruction { |
| 28 // Constructor for an non-jumping instruction or for an unconditional | 27 // Constructor for an non-jumping instruction or for an unconditional |
| 29 // "always" jump. | 28 // "always" jump. |
| 30 Instruction(uint16_t c, uint32_t parm, Instruction *n) : | 29 Instruction(uint16_t c, uint32_t parm, Instruction* n) |
| 31 code(c), next(n), k(parm) { } | 30 : code(c), next(n), k(parm) {} |
| 32 | 31 |
| 33 // Constructor for a conditional jump instruction. | 32 // Constructor for a conditional jump instruction. |
| 34 Instruction(uint16_t c, uint32_t parm, Instruction *jt, Instruction *jf) : | 33 Instruction(uint16_t c, uint32_t parm, Instruction* jt, Instruction* jf) |
| 35 code(c), jt_ptr(jt), jf_ptr(jf), k(parm) { } | 34 : code(c), jt_ptr(jt), jf_ptr(jf), k(parm) {} |
| 36 | 35 |
| 37 uint16_t code; | 36 uint16_t code; |
| 38 union { | 37 union { |
| 39 // When code generation is complete, we will have computed relative | 38 // When code generation is complete, we will have computed relative |
| 40 // branch targets that are in the range 0..255. | 39 // branch targets that are in the range 0..255. |
| 41 struct { | 40 struct { |
| 42 uint8_t jt, jf; | 41 uint8_t jt, jf; |
| 43 }; | 42 }; |
| 44 | 43 |
| 45 // While assembling the BPF program, we use pointers for branch targets. | 44 // While assembling the BPF program, we use pointers for branch targets. |
| 46 // Once we have computed basic blocks, these pointers will be entered as | 45 // Once we have computed basic blocks, these pointers will be entered as |
| 47 // keys in a TargetsToBlocks map and should no longer be dereferenced | 46 // keys in a TargetsToBlocks map and should no longer be dereferenced |
| 48 // directly. | 47 // directly. |
| 49 struct { | 48 struct { |
| 50 Instruction *jt_ptr, *jf_ptr; | 49 Instruction* jt_ptr, *jf_ptr; |
| 51 }; | 50 }; |
| 52 | 51 |
| 53 // While assembling the BPF program, non-jumping instructions are linked | 52 // While assembling the BPF program, non-jumping instructions are linked |
| 54 // by the "next_" pointer. This field is no longer needed when we have | 53 // by the "next_" pointer. This field is no longer needed when we have |
| 55 // computed basic blocks. | 54 // computed basic blocks. |
| 56 Instruction *next; | 55 Instruction* next; |
| 57 }; | 56 }; |
| 58 uint32_t k; | 57 uint32_t k; |
| 59 }; | 58 }; |
| 60 | 59 |
| 61 } // namespace | 60 } // namespace |
| 62 | 61 |
| 63 #endif // SANDBOX_LINUX_SECCOMP_BPF_INSTRUCTION_H__ | 62 #endif // SANDBOX_LINUX_SECCOMP_BPF_INSTRUCTION_H__ |
| OLD | NEW |