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

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

Powered by Google App Engine
This is Rietveld 408576698