| 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_IMPL_H_ | 5 #ifndef SANDBOX_LINUX_BPF_DSL_BPF_DSL_IMPL_H_ |
| 6 #define SANDBOX_LINUX_BPF_DSL_BPF_DSL_IMPL_H_ | 6 #define SANDBOX_LINUX_BPF_DSL_BPF_DSL_IMPL_H_ |
| 7 | 7 |
| 8 #include "base/macros.h" | 8 #include "base/macros.h" |
| 9 #include "base/memory/ref_counted.h" | 9 #include "base/memory/ref_counted.h" |
| 10 #include "sandbox/linux/bpf_dsl/codegen.h" |
| 10 #include "sandbox/sandbox_export.h" | 11 #include "sandbox/sandbox_export.h" |
| 11 | 12 |
| 12 namespace sandbox { | 13 namespace sandbox { |
| 13 namespace bpf_dsl { | 14 namespace bpf_dsl { |
| 14 class ErrorCode; | 15 class ErrorCode; |
| 15 class PolicyCompiler; | 16 class PolicyCompiler; |
| 16 | 17 |
| 17 namespace internal { | 18 namespace internal { |
| 18 | 19 |
| 19 // Internal interface implemented by BoolExpr implementations. | 20 // Internal interface implemented by BoolExpr implementations. |
| 20 class BoolExprImpl : public base::RefCounted<BoolExprImpl> { | 21 class BoolExprImpl : public base::RefCounted<BoolExprImpl> { |
| 21 public: | 22 public: |
| 22 // Compile uses |pc| to construct an ErrorCode that conditionally continues | 23 // Compile uses |pc| to emit a CodeGen::Node that conditionally continues |
| 23 // to either |true_ec| or |false_ec|, depending on whether the represented | 24 // to either |then_node| or |false_node|, depending on whether the represented |
| 24 // boolean expression is true or false. | 25 // boolean expression is true or false. |
| 25 virtual ErrorCode Compile(PolicyCompiler* pc, | 26 virtual CodeGen::Node Compile(PolicyCompiler* pc, |
| 26 ErrorCode true_ec, | 27 CodeGen::Node then_node, |
| 27 ErrorCode false_ec) const = 0; | 28 CodeGen::Node else_node) const = 0; |
| 28 | 29 |
| 29 protected: | 30 protected: |
| 30 BoolExprImpl() {} | 31 BoolExprImpl() {} |
| 31 virtual ~BoolExprImpl() {} | 32 virtual ~BoolExprImpl() {} |
| 32 | 33 |
| 33 private: | 34 private: |
| 34 friend class base::RefCounted<BoolExprImpl>; | 35 friend class base::RefCounted<BoolExprImpl>; |
| 35 DISALLOW_COPY_AND_ASSIGN(BoolExprImpl); | 36 DISALLOW_COPY_AND_ASSIGN(BoolExprImpl); |
| 36 }; | 37 }; |
| 37 | 38 |
| 38 // Internal interface implemented by ResultExpr implementations. | 39 // Internal interface implemented by ResultExpr implementations. |
| 39 class ResultExprImpl : public base::RefCounted<ResultExprImpl> { | 40 class ResultExprImpl : public base::RefCounted<ResultExprImpl> { |
| 40 public: | 41 public: |
| 41 // Compile uses |pc| to construct an ErrorCode analogous to the represented | 42 // Compile uses |pc| to emit a CodeGen::Node that executes the |
| 42 // result expression. | 43 // represented result expression. |
| 43 virtual ErrorCode Compile(PolicyCompiler* pc) const = 0; | 44 virtual CodeGen::Node Compile(PolicyCompiler* pc) const = 0; |
| 44 | 45 |
| 45 // HasUnsafeTraps returns whether the result expression is or recursively | 46 // HasUnsafeTraps returns whether the result expression is or recursively |
| 46 // contains an unsafe trap expression. | 47 // contains an unsafe trap expression. |
| 47 virtual bool HasUnsafeTraps() const; | 48 virtual bool HasUnsafeTraps() const; |
| 48 | 49 |
| 49 // IsAllow returns whether the result expression is an "allow" result. | 50 // IsAllow returns whether the result expression is an "allow" result. |
| 50 virtual bool IsAllow() const; | 51 virtual bool IsAllow() const; |
| 51 | 52 |
| 52 // IsAllow returns whether the result expression is a "deny" result. | 53 // IsAllow returns whether the result expression is a "deny" result. |
| 53 virtual bool IsDeny() const; | 54 virtual bool IsDeny() const; |
| 54 | 55 |
| 55 protected: | 56 protected: |
| 56 ResultExprImpl() {} | 57 ResultExprImpl() {} |
| 57 virtual ~ResultExprImpl() {} | 58 virtual ~ResultExprImpl() {} |
| 58 | 59 |
| 59 private: | 60 private: |
| 60 friend class base::RefCounted<ResultExprImpl>; | 61 friend class base::RefCounted<ResultExprImpl>; |
| 61 DISALLOW_COPY_AND_ASSIGN(ResultExprImpl); | 62 DISALLOW_COPY_AND_ASSIGN(ResultExprImpl); |
| 62 }; | 63 }; |
| 63 | 64 |
| 64 } // namespace internal | 65 } // namespace internal |
| 65 } // namespace bpf_dsl | 66 } // namespace bpf_dsl |
| 66 } // namespace sandbox | 67 } // namespace sandbox |
| 67 | 68 |
| 68 #endif // SANDBOX_LINUX_BPF_DSL_BPF_DSL_IMPL_H_ | 69 #endif // SANDBOX_LINUX_BPF_DSL_BPF_DSL_IMPL_H_ |
| OLD | NEW |