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

Side by Side Diff: sandbox/linux/bpf_dsl/errorcode.cc

Issue 1292753009: sandbox/linux: move ErrorCode into bpf_dsl (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@bpf_dsl-deps
Patch Set: Rebase and cleanup test code Created 5 years, 4 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
« no previous file with comments | « sandbox/linux/bpf_dsl/errorcode.h ('k') | sandbox/linux/bpf_dsl/errorcode_unittest.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 #include "sandbox/linux/seccomp-bpf/errorcode.h" 5 #include "sandbox/linux/bpf_dsl/errorcode.h"
6 6
7 #include "sandbox/linux/seccomp-bpf/die.h" 7 #include "base/logging.h"
8 #include "sandbox/linux/system_headers/linux_seccomp.h" 8 #include "sandbox/linux/system_headers/linux_seccomp.h"
9 9
10 namespace sandbox { 10 namespace sandbox {
11 namespace bpf_dsl {
11 12
12 ErrorCode::ErrorCode() : error_type_(ET_INVALID), err_(SECCOMP_RET_INVALID) { 13 ErrorCode::ErrorCode() : error_type_(ET_INVALID), err_(SECCOMP_RET_INVALID) {}
13 }
14 14
15 ErrorCode::ErrorCode(int err) { 15 ErrorCode::ErrorCode(int err) {
16 switch (err) { 16 switch (err) {
17 case ERR_ALLOWED: 17 case ERR_ALLOWED:
18 err_ = SECCOMP_RET_ALLOW; 18 err_ = SECCOMP_RET_ALLOW;
19 error_type_ = ET_SIMPLE; 19 error_type_ = ET_SIMPLE;
20 break; 20 break;
21 case ERR_KILL: 21 case ERR_KILL:
22 err_ = SECCOMP_RET_KILL; 22 err_ = SECCOMP_RET_KILL;
23 error_type_ = ET_SIMPLE; 23 error_type_ = ET_SIMPLE;
24 break; 24 break;
25 case ERR_MIN_ERRNO... ERR_MAX_ERRNO: 25 case ERR_MIN_ERRNO... ERR_MAX_ERRNO:
26 err_ = SECCOMP_RET_ERRNO + err; 26 err_ = SECCOMP_RET_ERRNO + err;
27 error_type_ = ET_SIMPLE; 27 error_type_ = ET_SIMPLE;
28 break; 28 break;
29 default: 29 default:
30 if ((err & ~SECCOMP_RET_DATA) == ERR_TRACE) { 30 if ((err & ~SECCOMP_RET_DATA) == ERR_TRACE) {
31 err_ = SECCOMP_RET_TRACE + (err & SECCOMP_RET_DATA); 31 err_ = SECCOMP_RET_TRACE + (err & SECCOMP_RET_DATA);
32 error_type_ = ET_SIMPLE; 32 error_type_ = ET_SIMPLE;
33 break; 33 break;
34 } 34 }
35 SANDBOX_DIE("Invalid use of ErrorCode object"); 35 LOG(FATAL) << "Invalid use of ErrorCode object";
36 } 36 }
37 } 37 }
38 38
39 ErrorCode::ErrorCode(uint16_t trap_id, 39 ErrorCode::ErrorCode(uint16_t trap_id,
40 Trap::TrapFnc fnc, 40 TrapRegistry::TrapFnc fnc,
41 const void* aux, 41 const void* aux,
42 bool safe) 42 bool safe)
43 : error_type_(ET_TRAP), 43 : error_type_(ET_TRAP),
44 fnc_(fnc), 44 fnc_(fnc),
45 aux_(const_cast<void*>(aux)), 45 aux_(const_cast<void*>(aux)),
46 safe_(safe), 46 safe_(safe),
47 err_(SECCOMP_RET_TRAP + trap_id) { 47 err_(SECCOMP_RET_TRAP + trap_id) {}
48 }
49 48
50 ErrorCode::ErrorCode(int argno, 49 ErrorCode::ErrorCode(int argno,
51 ArgType width, 50 ArgType width,
52 uint64_t mask, 51 uint64_t mask,
53 uint64_t value, 52 uint64_t value,
54 const ErrorCode* passed, 53 const ErrorCode* passed,
55 const ErrorCode* failed) 54 const ErrorCode* failed)
56 : error_type_(ET_COND), 55 : error_type_(ET_COND),
57 mask_(mask), 56 mask_(mask),
58 value_(value), 57 value_(value),
59 argno_(argno), 58 argno_(argno),
60 width_(width), 59 width_(width),
61 passed_(passed), 60 passed_(passed),
62 failed_(failed), 61 failed_(failed),
63 err_(SECCOMP_RET_INVALID) { 62 err_(SECCOMP_RET_INVALID) {}
64 }
65 63
66 bool ErrorCode::Equals(const ErrorCode& err) const { 64 bool ErrorCode::Equals(const ErrorCode& err) const {
67 if (error_type_ == ET_INVALID || err.error_type_ == ET_INVALID) { 65 if (error_type_ == ET_INVALID || err.error_type_ == ET_INVALID) {
68 SANDBOX_DIE("Dereferencing invalid ErrorCode"); 66 LOG(FATAL) << "Dereferencing invalid ErrorCode";
69 } 67 }
70 if (error_type_ != err.error_type_) { 68 if (error_type_ != err.error_type_) {
71 return false; 69 return false;
72 } 70 }
73 if (error_type_ == ET_SIMPLE || error_type_ == ET_TRAP) { 71 if (error_type_ == ET_SIMPLE || error_type_ == ET_TRAP) {
74 return err_ == err.err_; 72 return err_ == err.err_;
75 } else if (error_type_ == ET_COND) { 73 } else if (error_type_ == ET_COND) {
76 return mask_ == err.mask_ && value_ == err.value_ && argno_ == err.argno_ && 74 return mask_ == err.mask_ && value_ == err.value_ && argno_ == err.argno_ &&
77 width_ == err.width_ && passed_->Equals(*err.passed_) && 75 width_ == err.width_ && passed_->Equals(*err.passed_) &&
78 failed_->Equals(*err.failed_); 76 failed_->Equals(*err.failed_);
79 } else { 77 } else {
80 SANDBOX_DIE("Corrupted ErrorCode"); 78 LOG(FATAL) << "Corrupted ErrorCode";
79 return false;
81 } 80 }
82 } 81 }
83 82
84 bool ErrorCode::LessThan(const ErrorCode& err) const { 83 bool ErrorCode::LessThan(const ErrorCode& err) const {
85 // Implementing a "LessThan()" operator allows us to use ErrorCode objects 84 // Implementing a "LessThan()" operator allows us to use ErrorCode objects
86 // as keys in STL containers; most notably, it also allows us to put them 85 // as keys in STL containers; most notably, it also allows us to put them
87 // into std::set<>. Actual ordering is not important as long as it is 86 // into std::set<>. Actual ordering is not important as long as it is
88 // deterministic. 87 // deterministic.
89 if (error_type_ == ET_INVALID || err.error_type_ == ET_INVALID) { 88 if (error_type_ == ET_INVALID || err.error_type_ == ET_INVALID) {
90 SANDBOX_DIE("Dereferencing invalid ErrorCode"); 89 LOG(FATAL) << "Dereferencing invalid ErrorCode";
91 } 90 }
92 if (error_type_ != err.error_type_) { 91 if (error_type_ != err.error_type_) {
93 return error_type_ < err.error_type_; 92 return error_type_ < err.error_type_;
94 } else { 93 } else {
95 if (error_type_ == ET_SIMPLE || error_type_ == ET_TRAP) { 94 if (error_type_ == ET_SIMPLE || error_type_ == ET_TRAP) {
96 return err_ < err.err_; 95 return err_ < err.err_;
97 } else if (error_type_ == ET_COND) { 96 } else if (error_type_ == ET_COND) {
98 if (mask_ != err.mask_) { 97 if (mask_ != err.mask_) {
99 return mask_ < err.mask_; 98 return mask_ < err.mask_;
100 } else if (value_ != err.value_) { 99 } else if (value_ != err.value_) {
101 return value_ < err.value_; 100 return value_ < err.value_;
102 } else if (argno_ != err.argno_) { 101 } else if (argno_ != err.argno_) {
103 return argno_ < err.argno_; 102 return argno_ < err.argno_;
104 } else if (width_ != err.width_) { 103 } else if (width_ != err.width_) {
105 return width_ < err.width_; 104 return width_ < err.width_;
106 } else if (!passed_->Equals(*err.passed_)) { 105 } else if (!passed_->Equals(*err.passed_)) {
107 return passed_->LessThan(*err.passed_); 106 return passed_->LessThan(*err.passed_);
108 } else if (!failed_->Equals(*err.failed_)) { 107 } else if (!failed_->Equals(*err.failed_)) {
109 return failed_->LessThan(*err.failed_); 108 return failed_->LessThan(*err.failed_);
110 } else { 109 } else {
111 return false; 110 return false;
112 } 111 }
113 } else { 112 } else {
114 SANDBOX_DIE("Corrupted ErrorCode"); 113 LOG(FATAL) << "Corrupted ErrorCode";
114 return false;
115 } 115 }
116 } 116 }
117 } 117 }
118 118
119 } // namespace bpf_dsl
119 } // namespace sandbox 120 } // namespace sandbox
OLDNEW
« no previous file with comments | « sandbox/linux/bpf_dsl/errorcode.h ('k') | sandbox/linux/bpf_dsl/errorcode_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698