Chromium Code Reviews| OLD | NEW |
|---|---|
| (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/sandbox_bpf.h" | |
| 6 | |
| 7 | |
| 8 namespace playground2 { | |
| 9 | |
| 10 ErrorCode::ErrorCode(int err) { | |
| 11 switch (err) { | |
| 12 case ERR_ALLOWED: | |
| 13 err_ = SECCOMP_RET_ALLOW; | |
| 14 error_type_ = ET_SIMPLE; | |
| 15 break; | |
| 16 case ERR_MIN_ERRNO ... ERR_MAX_ERRNO: | |
| 17 err_ = SECCOMP_RET_ERRNO + err; | |
| 18 error_type_ = ET_SIMPLE; | |
| 19 break; | |
| 20 default: | |
| 21 SANDBOX_DIE("Invalid use of ErrorCode object"); | |
| 22 } | |
| 23 } | |
| 24 | |
| 25 ErrorCode::ErrorCode(ErrorCode::TrapFnc fnc, const void *aux, uint16_t id) | |
|
jln (very slow on Chromium)
2012/08/31 01:16:00
nit: void* aux
| |
| 26 : error_type_(ET_TRAP), | |
| 27 fnc_(fnc), | |
| 28 aux_(const_cast<void *>(aux)), | |
| 29 err_(SECCOMP_RET_TRAP + id) { | |
| 30 } | |
| 31 | |
| 32 ErrorCode::ErrorCode(int argno, ArgType width, Operation op, uint64_t value, | |
| 33 const ErrorCode *passed, const ErrorCode *failed) | |
|
jln (very slow on Chromium)
2012/08/31 01:16:00
nit: type* ptr
| |
| 34 : error_type_(ET_COND), | |
| 35 value_(value), | |
| 36 argno_(argno), | |
| 37 width_(width), | |
| 38 op_(op), | |
| 39 passed_(passed), | |
| 40 failed_(failed), | |
| 41 err_(SECCOMP_RET_INVALID) { | |
| 42 if (op < 0 || op >= OP_NUM_OPS) { | |
| 43 SANDBOX_DIE("Invalid opcode in BPF sandbox rules"); | |
| 44 } | |
| 45 } | |
| 46 | |
| 47 bool ErrorCode::Equals(const ErrorCode& err) const { | |
| 48 if (error_type_ == ET_INVALID || err.error_type_ == ET_INVALID) { | |
| 49 SANDBOX_DIE("Dereferencing invalid ErrorCode"); | |
| 50 } | |
| 51 if (error_type_ != err.error_type_) { | |
| 52 return false; | |
| 53 } | |
| 54 if (error_type_ == ET_SIMPLE || error_type_ == ET_TRAP) { | |
| 55 return err_ == err.err_; | |
| 56 } else if (error_type_ == ET_COND) { | |
| 57 return value_ == err.value_ && | |
| 58 argno_ == err.argno_ && | |
| 59 width_ == err.width_ && | |
| 60 op_ == err.op_ && | |
| 61 passed_->Equals(*err.passed_) && | |
| 62 failed_->Equals(*err.failed_); | |
| 63 } else { | |
| 64 SANDBOX_DIE("Corrupted ErrorCode"); | |
| 65 } | |
| 66 } | |
| 67 | |
| 68 bool ErrorCode::LessThan(const ErrorCode& err) const { | |
| 69 // Implementing a "LessThan()" operator allows us to use ErrorCode objects | |
| 70 // as keys in STL containers; most notably, it also allows us to put them | |
| 71 // into std::set<>. Actual ordering is not important as long as it is | |
| 72 // deterministic. | |
| 73 if (error_type_ == ET_INVALID || err.error_type_ == ET_INVALID) { | |
| 74 SANDBOX_DIE("Dereferencing invalid ErrorCode"); | |
| 75 } | |
| 76 if (error_type_ != err.error_type_) { | |
| 77 return error_type_ < err.error_type_; | |
| 78 } else { | |
| 79 if (error_type_ == ET_SIMPLE || error_type_ == ET_TRAP) { | |
| 80 return err_ < err.err_; | |
| 81 } else if (error_type_ == ET_COND) { | |
| 82 if (value_ != err.value_) { | |
| 83 return value_ < err.value_; | |
| 84 } else if (argno_ != err.argno_) { | |
| 85 return argno_ < err.argno_; | |
| 86 } else if (width_ != err.width_) { | |
| 87 return width_ < err.width_; | |
| 88 } else if (op_ != err.op_) { | |
| 89 return op_ < err.op_; | |
| 90 } else if (!passed_->Equals(*err.passed_)) { | |
| 91 return passed_->LessThan(*err.passed_); | |
| 92 } else if (!failed_->Equals(*err.failed_)) { | |
| 93 return failed_->LessThan(*err.failed_); | |
| 94 } else { | |
| 95 return false; | |
| 96 } | |
| 97 } else { | |
| 98 SANDBOX_DIE("Corrupted ErrorCode"); | |
| 99 } | |
| 100 } | |
| 101 } | |
| 102 | |
| 103 } // namespace | |
| OLD | NEW |