| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 #ifndef SANDBOX_LINUX_BPF_DSL_BPF_DSL_H_ | 5 #ifndef SANDBOX_LINUX_BPF_DSL_BPF_DSL_H_ |
| 6 #define SANDBOX_LINUX_BPF_DSL_BPF_DSL_H_ | 6 #define SANDBOX_LINUX_BPF_DSL_BPF_DSL_H_ |
| 7 | 7 |
| 8 #include <stdint.h> | 8 #include <stdint.h> |
| 9 | 9 |
| 10 #include <utility> | 10 #include <utility> |
| (...skipping 264 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 275 const __typeof__(value) bpf_dsl_cases_values[] = {value, __VA_ARGS__}; \ | 275 const __typeof__(value) bpf_dsl_cases_values[] = {value, __VA_ARGS__}; \ |
| 276 std::vector<__typeof__(value)>( \ | 276 std::vector<__typeof__(value)>( \ |
| 277 bpf_dsl_cases_values, \ | 277 bpf_dsl_cases_values, \ |
| 278 bpf_dsl_cases_values + arraysize(bpf_dsl_cases_values)); \ | 278 bpf_dsl_cases_values + arraysize(bpf_dsl_cases_values)); \ |
| 279 }) | 279 }) |
| 280 | 280 |
| 281 // ===================================================================== | 281 // ===================================================================== |
| 282 // Official API ends here. | 282 // Official API ends here. |
| 283 // ===================================================================== | 283 // ===================================================================== |
| 284 | 284 |
| 285 // Definitions below are necessary here only for C++03 compatibility. | |
| 286 // Once C++11 is available, they should be moved into bpf_dsl.cc via extern | |
| 287 // templates. | |
| 288 namespace internal { | 285 namespace internal { |
| 289 | 286 |
| 290 // Make argument-dependent lookup work. This is necessary because although | 287 // Make argument-dependent lookup work. This is necessary because although |
| 291 // BoolExpr is defined in bpf_dsl, since it's merely a typedef for | 288 // BoolExpr is defined in bpf_dsl, since it's merely a typedef for |
| 292 // scoped_refptr<const internal::BoolExplImpl>, argument-dependent lookup only | 289 // scoped_refptr<const internal::BoolExplImpl>, argument-dependent lookup only |
| 293 // searches the "internal" nested namespace. | 290 // searches the "internal" nested namespace. |
| 294 using bpf_dsl::operator!; | 291 using bpf_dsl::operator!; |
| 295 using bpf_dsl::operator||; | 292 using bpf_dsl::operator||; |
| 296 using bpf_dsl::operator&&; | 293 using bpf_dsl::operator&&; |
| 297 | 294 |
| 298 // Returns a boolean expression that represents whether system call | 295 // Returns a boolean expression that represents whether system call |
| 299 // argument |num| of size |size| is equal to |val|, when masked | 296 // argument |num| of size |size| is equal to |val|, when masked |
| 300 // according to |mask|. Users should use the Arg template class below | 297 // according to |mask|. Users should use the Arg template class below |
| 301 // instead of using this API directly. | 298 // instead of using this API directly. |
| 302 SANDBOX_EXPORT BoolExpr | 299 SANDBOX_EXPORT BoolExpr |
| 303 ArgEq(int num, size_t size, uint64_t mask, uint64_t val); | 300 ArgEq(int num, size_t size, uint64_t mask, uint64_t val); |
| 304 | 301 |
| 305 // Returns the default mask for a system call argument of the specified size. | 302 // Returns the default mask for a system call argument of the specified size. |
| 306 SANDBOX_EXPORT uint64_t DefaultMask(size_t size); | 303 SANDBOX_EXPORT uint64_t DefaultMask(size_t size); |
| 307 | 304 |
| 308 // Internal interface implemented by BoolExpr implementations. | |
| 309 class SANDBOX_EXPORT BoolExprImpl : public base::RefCounted<BoolExprImpl> { | |
| 310 public: | |
| 311 BoolExprImpl() {} | |
| 312 virtual ErrorCode Compile(SandboxBPF* sb, | |
| 313 ErrorCode true_ec, | |
| 314 ErrorCode false_ec) const = 0; | |
| 315 | |
| 316 protected: | |
| 317 virtual ~BoolExprImpl() {} | |
| 318 | |
| 319 private: | |
| 320 friend class base::RefCounted<BoolExprImpl>; | |
| 321 DISALLOW_COPY_AND_ASSIGN(BoolExprImpl); | |
| 322 }; | |
| 323 | |
| 324 // Internal interface implemented by ResultExpr implementations. | |
| 325 class SANDBOX_EXPORT ResultExprImpl : public base::RefCounted<ResultExprImpl> { | |
| 326 public: | |
| 327 ResultExprImpl() {} | |
| 328 virtual ErrorCode Compile(SandboxBPF* sb) const = 0; | |
| 329 virtual bool HasUnsafeTraps() const; | |
| 330 | |
| 331 protected: | |
| 332 virtual ~ResultExprImpl() {} | |
| 333 | |
| 334 private: | |
| 335 friend class base::RefCounted<ResultExprImpl>; | |
| 336 DISALLOW_COPY_AND_ASSIGN(ResultExprImpl); | |
| 337 }; | |
| 338 | |
| 339 } // namespace internal | 305 } // namespace internal |
| 340 | 306 |
| 341 template <typename T> | 307 template <typename T> |
| 342 Arg<T>::Arg(int num) | 308 Arg<T>::Arg(int num) |
| 343 : num_(num), mask_(internal::DefaultMask(sizeof(T))) { | 309 : num_(num), mask_(internal::DefaultMask(sizeof(T))) { |
| 344 } | 310 } |
| 345 | 311 |
| 346 // Definition requires ArgEq to have been declared. Moved out-of-line | 312 // Definition requires ArgEq to have been declared. Moved out-of-line |
| 347 // to minimize how much internal clutter users have to ignore while | 313 // to minimize how much internal clutter users have to ignore while |
| 348 // reading the header documentation. | 314 // reading the header documentation. |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 381 } | 347 } |
| 382 | 348 |
| 383 template <typename T> | 349 template <typename T> |
| 384 ResultExpr Caser<T>::Default(ResultExpr result) const { | 350 ResultExpr Caser<T>::Default(ResultExpr result) const { |
| 385 return elser_.Else(result); | 351 return elser_.Else(result); |
| 386 } | 352 } |
| 387 | 353 |
| 388 } // namespace bpf_dsl | 354 } // namespace bpf_dsl |
| 389 } // namespace sandbox | 355 } // namespace sandbox |
| 390 | 356 |
| 357 extern template class SANDBOX_EXPORT |
| 358 scoped_refptr<const sandbox::bpf_dsl::internal::BoolExprImpl>; |
| 359 extern template class SANDBOX_EXPORT |
| 360 scoped_refptr<const sandbox::bpf_dsl::internal::ResultExprImpl>; |
| 361 |
| 391 #endif // SANDBOX_LINUX_BPF_DSL_BPF_DSL_H_ | 362 #endif // SANDBOX_LINUX_BPF_DSL_BPF_DSL_H_ |
| OLD | NEW |