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

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

Issue 12223109: SECCOMP-BPF: Refactor the BPF sandbox API to use fewer "static" fields and methods. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Rebase Created 7 years, 9 months 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 | Annotate | Revision Log
« no previous file with comments | « sandbox/linux/seccomp-bpf/die.cc ('k') | sandbox/linux/seccomp-bpf/errorcode.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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_ERRORCODE_H__ 5 #ifndef SANDBOX_LINUX_SECCOMP_BPF_ERRORCODE_H__
6 #define SANDBOX_LINUX_SECCOMP_BPF_ERRORCODE_H__ 6 #define SANDBOX_LINUX_SECCOMP_BPF_ERRORCODE_H__
7 7
8 #include "sandbox/linux/seccomp-bpf/linux_seccomp.h"
8 #include "sandbox/linux/seccomp-bpf/trap.h" 9 #include "sandbox/linux/seccomp-bpf/trap.h"
9 10
10 namespace playground2 { 11 namespace playground2 {
11 12
12 struct arch_seccomp_data; 13 struct arch_seccomp_data;
13 14
14 // This class holds all the possible values that can be returned by a sandbox 15 // This class holds all the possible values that can be returned by a sandbox
15 // policy. 16 // policy.
16 // We can either wrap a symbolic ErrorCode (i.e. ERR_XXX enum values), an 17 // We can either wrap a symbolic ErrorCode (i.e. ERR_XXX enum values), an
17 // errno value (in the range 0..4095), a pointer to a TrapFnc callback 18 // errno value (in the range 0..4095), a pointer to a TrapFnc callback
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after
88 // The "ALL_BITS" variant performs this test: "arg & mask == mask" 89 // The "ALL_BITS" variant performs this test: "arg & mask == mask"
89 // This implies that a mask of zero always results in a passing test. 90 // This implies that a mask of zero always results in a passing test.
90 // The "ANY_BITS" variant performs this test: "arg & mask != 0" 91 // The "ANY_BITS" variant performs this test: "arg & mask != 0"
91 // This implies that a mask of zero always results in a failing test. 92 // This implies that a mask of zero always results in a failing test.
92 OP_HAS_ALL_BITS, OP_HAS_ANY_BITS, 93 OP_HAS_ALL_BITS, OP_HAS_ANY_BITS,
93 94
94 // Total number of operations. 95 // Total number of operations.
95 OP_NUM_OPS, 96 OP_NUM_OPS,
96 }; 97 };
97 98
99 enum ErrorType {
100 ET_INVALID, ET_SIMPLE, ET_TRAP, ET_COND,
101 };
102
98 // We allow the default constructor, as it makes the ErrorCode class 103 // We allow the default constructor, as it makes the ErrorCode class
99 // much easier to use. But if we ever encounter an invalid ErrorCode 104 // much easier to use. But if we ever encounter an invalid ErrorCode
100 // when compiling a BPF filter, we deliberately generate an invalid 105 // when compiling a BPF filter, we deliberately generate an invalid
101 // program that will get flagged both by our Verifier class and by 106 // program that will get flagged both by our Verifier class and by
102 // the Linux kernel. 107 // the Linux kernel.
103 ErrorCode() : 108 ErrorCode() :
104 error_type_(ET_INVALID), 109 error_type_(ET_INVALID),
105 err_(SECCOMP_RET_INVALID) { 110 err_(SECCOMP_RET_INVALID) {
106 } 111 }
107 explicit ErrorCode(int err); 112 explicit ErrorCode(int err);
108 113
109 // For all practical purposes, ErrorCodes are treated as if they were 114 // For all practical purposes, ErrorCodes are treated as if they were
110 // structs. The copy constructor and assignment operator are trivial and 115 // structs. The copy constructor and assignment operator are trivial and
111 // we do not need to explicitly specify them. 116 // we do not need to explicitly specify them.
112 // Most notably, it is in fact perfectly OK to directly copy the passed_ and 117 // Most notably, it is in fact perfectly OK to directly copy the passed_ and
113 // failed_ field. They only ever get set by our private constructor, and the 118 // failed_ field. They only ever get set by our private constructor, and the
114 // callers handle life-cycle management for these objects. 119 // callers handle life-cycle management for these objects.
115 120
116 // Destructor 121 // Destructor
117 ~ErrorCode() { } 122 ~ErrorCode() { }
118 123
119 bool Equals(const ErrorCode& err) const; 124 bool Equals(const ErrorCode& err) const;
120 bool LessThan(const ErrorCode& err) const; 125 bool LessThan(const ErrorCode& err) const;
121 126
122 uint32_t err() const { return err_; } 127 uint32_t err() const { return err_; }
128 ErrorType error_type() const { return error_type_; }
129
130 bool safe() const { return safe_; }
131
132 uint64_t value() const { return value_; }
133 int argno() const { return argno_; }
134 ArgType width() const { return width_; }
135 Operation op() const { return op_; }
136 const ErrorCode *passed() const { return passed_; }
137 const ErrorCode *failed() const { return failed_; }
123 138
124 struct LessThan { 139 struct LessThan {
125 bool operator()(const ErrorCode& a, const ErrorCode& b) const { 140 bool operator()(const ErrorCode& a, const ErrorCode& b) const {
126 return a.LessThan(b); 141 return a.LessThan(b);
127 } 142 }
128 }; 143 };
129 144
130 private: 145 private:
131 friend class CodeGen; 146 friend class CodeGen;
132 friend class Sandbox; 147 friend class Sandbox;
133 friend class Trap; 148 friend class Trap;
134 friend class Verifier;
135
136 enum ErrorType {
137 ET_INVALID, ET_SIMPLE, ET_TRAP, ET_COND,
138 };
139 149
140 // If we are wrapping a callback, we must assign a unique id. This id is 150 // If we are wrapping a callback, we must assign a unique id. This id is
141 // how the kernel tells us which one of our different SECCOMP_RET_TRAP 151 // how the kernel tells us which one of our different SECCOMP_RET_TRAP
142 // cases has been triggered. 152 // cases has been triggered.
143 ErrorCode(Trap::TrapFnc fnc, const void *aux, bool safe, uint16_t id); 153 ErrorCode(Trap::TrapFnc fnc, const void *aux, bool safe, uint16_t id);
144 154
145 // Some system calls require inspection of arguments. This constructor 155 // Some system calls require inspection of arguments. This constructor
146 // allows us to specify additional constraints. 156 // allows us to specify additional constraints.
147 ErrorCode(int argno, ArgType width, Operation op, uint64_t value, 157 ErrorCode(int argno, ArgType width, Operation op, uint64_t value,
148 const ErrorCode *passed, const ErrorCode *failed); 158 const ErrorCode *passed, const ErrorCode *failed);
(...skipping 22 matching lines...) Expand all
171 // 32bit field used for all possible types of ErrorCode values. This is 181 // 32bit field used for all possible types of ErrorCode values. This is
172 // the value that uniquely identifies any ErrorCode and it (typically) can 182 // the value that uniquely identifies any ErrorCode and it (typically) can
173 // be emitted directly into a BPF filter program. 183 // be emitted directly into a BPF filter program.
174 uint32_t err_; 184 uint32_t err_;
175 185
176 }; 186 };
177 187
178 } // namespace 188 } // namespace
179 189
180 #endif // SANDBOX_LINUX_SECCOMP_BPF_ERRORCODE_H__ 190 #endif // SANDBOX_LINUX_SECCOMP_BPF_ERRORCODE_H__
OLDNEW
« no previous file with comments | « sandbox/linux/seccomp-bpf/die.cc ('k') | sandbox/linux/seccomp-bpf/errorcode.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698