OLD | NEW |
---|---|
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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/bpf_dsl/dump_bpf.h" | 5 #include "sandbox/linux/bpf_dsl/dump_bpf.h" |
6 | 6 |
7 #include <stdio.h> | 7 #include <stdio.h> |
8 | 8 |
9 #include "sandbox/linux/bpf_dsl/codegen.h" | 9 #include "sandbox/linux/bpf_dsl/codegen.h" |
10 #include "sandbox/linux/bpf_dsl/trap_registry.h" | 10 #include "sandbox/linux/bpf_dsl/trap_registry.h" |
11 #include "sandbox/linux/system_headers/linux_filter.h" | |
11 #include "sandbox/linux/system_headers/linux_seccomp.h" | 12 #include "sandbox/linux/system_headers/linux_seccomp.h" |
12 | 13 |
13 namespace sandbox { | 14 namespace sandbox { |
14 namespace bpf_dsl { | 15 namespace bpf_dsl { |
15 | 16 |
16 void DumpBPF::PrintProgram(const CodeGen::Program& program) { | 17 void DumpBPF::PrintProgram(const CodeGen::Program& program) { |
17 for (CodeGen::Program::const_iterator iter = program.begin(); | 18 for (CodeGen::Program::const_iterator iter = program.begin(); |
18 iter != program.end(); | 19 iter != program.end(); |
19 ++iter) { | 20 ++iter) { |
20 int ip = (int)(iter - program.begin()); | 21 int ip = (int)(iter - program.begin()); |
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
72 fprintf(stderr, "errno = %d\n", iter->k & SECCOMP_RET_DATA); | 73 fprintf(stderr, "errno = %d\n", iter->k & SECCOMP_RET_DATA); |
73 } else if ((iter->k & SECCOMP_RET_ACTION) == SECCOMP_RET_TRACE) { | 74 } else if ((iter->k & SECCOMP_RET_ACTION) == SECCOMP_RET_TRACE) { |
74 fprintf(stderr, "Trace #%d\n", iter->k & SECCOMP_RET_DATA); | 75 fprintf(stderr, "Trace #%d\n", iter->k & SECCOMP_RET_DATA); |
75 } else if (iter->k == SECCOMP_RET_ALLOW) { | 76 } else if (iter->k == SECCOMP_RET_ALLOW) { |
76 fprintf(stderr, "Allowed\n"); | 77 fprintf(stderr, "Allowed\n"); |
77 } else { | 78 } else { |
78 fprintf(stderr, "???\n"); | 79 fprintf(stderr, "???\n"); |
79 } | 80 } |
80 break; | 81 break; |
81 case BPF_ALU: | 82 case BPF_ALU: |
82 fprintf(stderr, BPF_OP(iter->code) == BPF_NEG | 83 if (BPF_OP(iter->code) == BPF_NEG) { |
hidehiko
2015/04/01 12:10:38
FYI: This causes an error with "-Werror,-Wformat-e
mdempsky
2015/04/01 22:06:10
Yeah, the rewrite is much better, thanks. (This i
| |
83 ? "A := -A\n" : "A := A %s 0x%x\n", | 84 fprintf(stderr, "A := -A\n"); |
84 BPF_OP(iter->code) == BPF_ADD ? "+" : | 85 } else { |
85 BPF_OP(iter->code) == BPF_SUB ? "-" : | 86 fprintf(stderr, "A := A %s 0x%x\n", |
86 BPF_OP(iter->code) == BPF_MUL ? "*" : | 87 BPF_OP(iter->code) == BPF_ADD ? "+" : |
87 BPF_OP(iter->code) == BPF_DIV ? "/" : | 88 BPF_OP(iter->code) == BPF_SUB ? "-" : |
88 BPF_OP(iter->code) == BPF_MOD ? "%" : | 89 BPF_OP(iter->code) == BPF_MUL ? "*" : |
89 BPF_OP(iter->code) == BPF_OR ? "|" : | 90 BPF_OP(iter->code) == BPF_DIV ? "/" : |
90 BPF_OP(iter->code) == BPF_XOR ? "^" : | 91 BPF_OP(iter->code) == BPF_MOD ? "%" : |
91 BPF_OP(iter->code) == BPF_AND ? "&" : | 92 BPF_OP(iter->code) == BPF_OR ? "|" : |
92 BPF_OP(iter->code) == BPF_LSH ? "<<" : | 93 BPF_OP(iter->code) == BPF_XOR ? "^" : |
93 BPF_OP(iter->code) == BPF_RSH ? ">>" : "???", | 94 BPF_OP(iter->code) == BPF_AND ? "&" : |
94 (int)iter->k); | 95 BPF_OP(iter->code) == BPF_LSH ? "<<" : |
96 BPF_OP(iter->code) == BPF_RSH ? ">>" : "???", | |
97 (int)iter->k); | |
98 } | |
95 break; | 99 break; |
96 default: | 100 default: |
97 fprintf(stderr, "???\n"); | 101 fprintf(stderr, "???\n"); |
98 break; | 102 break; |
99 } | 103 } |
100 } | 104 } |
101 return; | 105 return; |
102 } | 106 } |
103 | 107 |
104 } // namespace bpf_dsl | 108 } // namespace bpf_dsl |
105 } // namespace sandbox | 109 } // namespace sandbox |
OLD | NEW |