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

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

Issue 66723007: Make sandbox/linux/seccomp-bpf/ follow the style guide. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: (empty) rebase Created 7 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 | Annotate | Revision Log
« no previous file with comments | « sandbox/linux/seccomp-bpf/errorcode.h ('k') | sandbox/linux/seccomp-bpf/instruction.h » ('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 #include "sandbox/linux/seccomp-bpf/die.h" 5 #include "sandbox/linux/seccomp-bpf/die.h"
6 #include "sandbox/linux/seccomp-bpf/errorcode.h" 6 #include "sandbox/linux/seccomp-bpf/errorcode.h"
7 7
8
9 namespace playground2 { 8 namespace playground2 {
10 9
11 ErrorCode::ErrorCode(int err) { 10 ErrorCode::ErrorCode(int err) {
12 switch (err) { 11 switch (err) {
13 case ERR_ALLOWED: 12 case ERR_ALLOWED:
14 err_ = SECCOMP_RET_ALLOW; 13 err_ = SECCOMP_RET_ALLOW;
15 error_type_ = ET_SIMPLE; 14 error_type_ = ET_SIMPLE;
16 break; 15 break;
17 case ERR_MIN_ERRNO ... ERR_MAX_ERRNO: 16 case ERR_MIN_ERRNO... ERR_MAX_ERRNO:
18 err_ = SECCOMP_RET_ERRNO + err; 17 err_ = SECCOMP_RET_ERRNO + err;
19 error_type_ = ET_SIMPLE; 18 error_type_ = ET_SIMPLE;
20 break; 19 break;
21 default: 20 default:
22 SANDBOX_DIE("Invalid use of ErrorCode object"); 21 SANDBOX_DIE("Invalid use of ErrorCode object");
23 } 22 }
24 } 23 }
25 24
26 ErrorCode::ErrorCode(Trap::TrapFnc fnc, const void *aux, bool safe, 25 ErrorCode::ErrorCode(Trap::TrapFnc fnc, const void* aux, bool safe, uint16_t id)
27 uint16_t id)
28 : error_type_(ET_TRAP), 26 : error_type_(ET_TRAP),
29 fnc_(fnc), 27 fnc_(fnc),
30 aux_(const_cast<void *>(aux)), 28 aux_(const_cast<void*>(aux)),
31 safe_(safe), 29 safe_(safe),
32 err_(SECCOMP_RET_TRAP + id) { 30 err_(SECCOMP_RET_TRAP + id) {}
33 }
34 31
35 ErrorCode::ErrorCode(int argno, ArgType width, Operation op, uint64_t value, 32 ErrorCode::ErrorCode(int argno,
36 const ErrorCode *passed, const ErrorCode *failed) 33 ArgType width,
34 Operation op,
35 uint64_t value,
36 const ErrorCode* passed,
37 const ErrorCode* failed)
37 : error_type_(ET_COND), 38 : error_type_(ET_COND),
38 value_(value), 39 value_(value),
39 argno_(argno), 40 argno_(argno),
40 width_(width), 41 width_(width),
41 op_(op), 42 op_(op),
42 passed_(passed), 43 passed_(passed),
43 failed_(failed), 44 failed_(failed),
44 err_(SECCOMP_RET_INVALID) { 45 err_(SECCOMP_RET_INVALID) {
45 if (op < 0 || op >= OP_NUM_OPS) { 46 if (op < 0 || op >= OP_NUM_OPS) {
46 SANDBOX_DIE("Invalid opcode in BPF sandbox rules"); 47 SANDBOX_DIE("Invalid opcode in BPF sandbox rules");
47 } 48 }
48 } 49 }
49 50
50 bool ErrorCode::Equals(const ErrorCode& err) const { 51 bool ErrorCode::Equals(const ErrorCode& err) const {
51 if (error_type_ == ET_INVALID || err.error_type_ == ET_INVALID) { 52 if (error_type_ == ET_INVALID || err.error_type_ == ET_INVALID) {
52 SANDBOX_DIE("Dereferencing invalid ErrorCode"); 53 SANDBOX_DIE("Dereferencing invalid ErrorCode");
53 } 54 }
54 if (error_type_ != err.error_type_) { 55 if (error_type_ != err.error_type_) {
55 return false; 56 return false;
56 } 57 }
57 if (error_type_ == ET_SIMPLE || error_type_ == ET_TRAP) { 58 if (error_type_ == ET_SIMPLE || error_type_ == ET_TRAP) {
58 return err_ == err.err_; 59 return err_ == err.err_;
59 } else if (error_type_ == ET_COND) { 60 } else if (error_type_ == ET_COND) {
60 return value_ == err.value_ && 61 return value_ == err.value_ && argno_ == err.argno_ &&
61 argno_ == err.argno_ && 62 width_ == err.width_ && op_ == err.op_ &&
62 width_ == err.width_ && 63 passed_->Equals(*err.passed_) && failed_->Equals(*err.failed_);
63 op_ == err.op_ &&
64 passed_->Equals(*err.passed_) &&
65 failed_->Equals(*err.failed_);
66 } else { 64 } else {
67 SANDBOX_DIE("Corrupted ErrorCode"); 65 SANDBOX_DIE("Corrupted ErrorCode");
68 } 66 }
69 } 67 }
70 68
71 bool ErrorCode::LessThan(const ErrorCode& err) const { 69 bool ErrorCode::LessThan(const ErrorCode& err) const {
72 // Implementing a "LessThan()" operator allows us to use ErrorCode objects 70 // Implementing a "LessThan()" operator allows us to use ErrorCode objects
73 // as keys in STL containers; most notably, it also allows us to put them 71 // as keys in STL containers; most notably, it also allows us to put them
74 // into std::set<>. Actual ordering is not important as long as it is 72 // into std::set<>. Actual ordering is not important as long as it is
75 // deterministic. 73 // deterministic.
(...skipping 21 matching lines...) Expand all
97 } else { 95 } else {
98 return false; 96 return false;
99 } 97 }
100 } else { 98 } else {
101 SANDBOX_DIE("Corrupted ErrorCode"); 99 SANDBOX_DIE("Corrupted ErrorCode");
102 } 100 }
103 } 101 }
104 } 102 }
105 103
106 } // namespace 104 } // namespace
OLDNEW
« no previous file with comments | « sandbox/linux/seccomp-bpf/errorcode.h ('k') | sandbox/linux/seccomp-bpf/instruction.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698