OLD | NEW |
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/bpf_dsl/codegen.h" | 5 #include "sandbox/linux/bpf_dsl/codegen.h" |
6 | 6 |
7 #include <limits> | 7 #include <limits> |
8 #include <utility> | 8 #include <utility> |
9 | 9 |
10 #include "base/logging.h" | 10 #include "base/logging.h" |
(...skipping 113 matching lines...) Loading... |
124 CHECK_LE(jf, kBranchRange); | 124 CHECK_LE(jf, kBranchRange); |
125 } else { | 125 } else { |
126 CHECK_EQ(0U, jt); | 126 CHECK_EQ(0U, jt); |
127 CHECK_EQ(0U, jf); | 127 CHECK_EQ(0U, jf); |
128 } | 128 } |
129 | 129 |
130 CHECK_LT(program_.size(), static_cast<size_t>(BPF_MAXINSNS)); | 130 CHECK_LT(program_.size(), static_cast<size_t>(BPF_MAXINSNS)); |
131 CHECK_EQ(program_.size(), equivalent_.size()); | 131 CHECK_EQ(program_.size(), equivalent_.size()); |
132 | 132 |
133 Node res = program_.size(); | 133 Node res = program_.size(); |
134 program_.push_back(sock_filter{code, jt, jf, k}); | 134 program_.push_back(sock_filter{ |
| 135 code, static_cast<uint8_t>(jt), static_cast<uint8_t>(jf), k}); |
135 equivalent_.push_back(res); | 136 equivalent_.push_back(res); |
136 return res; | 137 return res; |
137 } | 138 } |
138 | 139 |
139 size_t CodeGen::Offset(Node target) const { | 140 size_t CodeGen::Offset(Node target) const { |
140 CHECK_LT(target, program_.size()) << "Bogus offset target node"; | 141 CHECK_LT(target, program_.size()) << "Bogus offset target node"; |
141 return (program_.size() - 1) - target; | 142 return (program_.size() - 1) - target; |
142 } | 143 } |
143 | 144 |
144 // TODO(mdempsky): Move into a general base::Tuple helper library. | 145 // TODO(mdempsky): Move into a general base::Tuple helper library. |
145 bool CodeGen::MemoKeyLess::operator()(const MemoKey& lhs, | 146 bool CodeGen::MemoKeyLess::operator()(const MemoKey& lhs, |
146 const MemoKey& rhs) const { | 147 const MemoKey& rhs) const { |
147 if (get<0>(lhs) != get<0>(rhs)) | 148 if (get<0>(lhs) != get<0>(rhs)) |
148 return get<0>(lhs) < get<0>(rhs); | 149 return get<0>(lhs) < get<0>(rhs); |
149 if (get<1>(lhs) != get<1>(rhs)) | 150 if (get<1>(lhs) != get<1>(rhs)) |
150 return get<1>(lhs) < get<1>(rhs); | 151 return get<1>(lhs) < get<1>(rhs); |
151 if (get<2>(lhs) != get<2>(rhs)) | 152 if (get<2>(lhs) != get<2>(rhs)) |
152 return get<2>(lhs) < get<2>(rhs); | 153 return get<2>(lhs) < get<2>(rhs); |
153 if (get<3>(lhs) != get<3>(rhs)) | 154 if (get<3>(lhs) != get<3>(rhs)) |
154 return get<3>(lhs) < get<3>(rhs); | 155 return get<3>(lhs) < get<3>(rhs); |
155 return false; | 156 return false; |
156 } | 157 } |
157 | 158 |
158 } // namespace sandbox | 159 } // namespace sandbox |
OLD | NEW |