Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(121)

Side by Side Diff: sandbox/linux/seccomp-bpf/instruction.h

Issue 754433003: Update from https://crrev.com/305340 (Closed) Base URL: git@github.com:domokit/mojo.git@master
Patch Set: Created 6 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « sandbox/linux/seccomp-bpf/codegen_unittest.cc ('k') | sandbox/linux/seccomp-bpf/sandbox_bpf.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
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
3 // found in the LICENSE file.
4
5 #ifndef SANDBOX_LINUX_SECCOMP_BPF_INSTRUCTION_H__
6 #define SANDBOX_LINUX_SECCOMP_BPF_INSTRUCTION_H__
7
8 #include <stdint.h>
9
10 #include <cstddef>
11
12 namespace sandbox {
13
14 // The fields in this structure have the same meaning as the corresponding
15 // fields in "struct sock_filter". See <linux/filter.h> for a lot more
16 // detail.
17 // code -- Opcode of the instruction. This is typically a bitwise
18 // combination BPF_XXX values.
19 // k -- Operand; BPF instructions take zero or one operands. Operands
20 // are 32bit-wide constants, if present. They can be immediate
21 // values (if BPF_K is present in "code_"), addresses (if BPF_ABS
22 // is present in "code_"), or relative jump offsets (if BPF_JMP
23 // and BPF_JA are present in "code_").
24 // jt, jf -- all conditional jumps have a 8bit-wide jump offset that allows
25 // jumps of up to 256 instructions forward. Conditional jumps are
26 // identified by BPF_JMP in "code_", but the lack of BPF_JA.
27 // Conditional jumps have a "t"rue and "f"alse branch.
28 struct Instruction {
29 // Constructor for an non-jumping instruction or for an unconditional
30 // "always" jump.
31 Instruction(uint16_t c, uint32_t parm, Instruction* n)
32 : code(c), jt(0), jf(0), jt_ptr(NULL), jf_ptr(NULL), next(n), k(parm) {}
33
34 // Constructor for a conditional jump instruction.
35 Instruction(uint16_t c, uint32_t parm, Instruction* jt, Instruction* jf)
36 : code(c), jt(0), jf(0), jt_ptr(jt), jf_ptr(jf), next(NULL), k(parm) {}
37
38 uint16_t code;
39
40 // When code generation is complete, we will have computed relative
41 // branch targets that are in the range 0..255.
42 uint8_t jt, jf;
43
44 // While assembling the BPF program, we use pointers for branch targets.
45 // Once we have computed basic blocks, these pointers will be entered as
46 // keys in a TargetsToBlocks map and should no longer be dereferenced
47 // directly.
48 Instruction* jt_ptr, *jf_ptr;
49
50 // While assembling the BPF program, non-jumping instructions are linked
51 // by the "next_" pointer. This field is no longer needed when we have
52 // computed basic blocks.
53 Instruction* next;
54
55 uint32_t k;
56 };
57
58 } // namespace sandbox
59
60 #endif // SANDBOX_LINUX_SECCOMP_BPF_INSTRUCTION_H__
OLDNEW
« no previous file with comments | « sandbox/linux/seccomp-bpf/codegen_unittest.cc ('k') | sandbox/linux/seccomp-bpf/sandbox_bpf.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698