Daniel Erat | 59c5f4b | 2015-08-24 12:50:25 -0600 | [diff] [blame] | 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 |
| 3 | // found in the LICENSE file. |
| 4 | |
| 5 | #ifndef SANDBOX_LINUX_BPF_DSL_BPF_DSL_IMPL_H_ |
| 6 | #define SANDBOX_LINUX_BPF_DSL_BPF_DSL_IMPL_H_ |
| 7 | |
Luis Hector Chavez | 94ffa55 | 2016-05-25 15:29:35 -0700 | [diff] [blame] | 8 | #include <memory> |
| 9 | |
Daniel Erat | 59c5f4b | 2015-08-24 12:50:25 -0600 | [diff] [blame] | 10 | #include "base/macros.h" |
Alex Vakulenko | 0d205d7 | 2016-01-15 13:02:14 -0800 | [diff] [blame] | 11 | #include "sandbox/linux/bpf_dsl/codegen.h" |
Daniel Erat | 59c5f4b | 2015-08-24 12:50:25 -0600 | [diff] [blame] | 12 | #include "sandbox/sandbox_export.h" |
| 13 | |
| 14 | namespace sandbox { |
Daniel Erat | 59c5f4b | 2015-08-24 12:50:25 -0600 | [diff] [blame] | 15 | namespace bpf_dsl { |
| 16 | class PolicyCompiler; |
| 17 | |
| 18 | namespace internal { |
| 19 | |
| 20 | // Internal interface implemented by BoolExpr implementations. |
Luis Hector Chavez | 94ffa55 | 2016-05-25 15:29:35 -0700 | [diff] [blame] | 21 | class BoolExprImpl { |
Daniel Erat | 59c5f4b | 2015-08-24 12:50:25 -0600 | [diff] [blame] | 22 | public: |
Alex Vakulenko | 0d205d7 | 2016-01-15 13:02:14 -0800 | [diff] [blame] | 23 | // Compile uses |pc| to emit a CodeGen::Node that conditionally continues |
| 24 | // to either |then_node| or |false_node|, depending on whether the represented |
Daniel Erat | 59c5f4b | 2015-08-24 12:50:25 -0600 | [diff] [blame] | 25 | // boolean expression is true or false. |
Alex Vakulenko | 0d205d7 | 2016-01-15 13:02:14 -0800 | [diff] [blame] | 26 | virtual CodeGen::Node Compile(PolicyCompiler* pc, |
| 27 | CodeGen::Node then_node, |
| 28 | CodeGen::Node else_node) const = 0; |
Daniel Erat | 59c5f4b | 2015-08-24 12:50:25 -0600 | [diff] [blame] | 29 | |
| 30 | protected: |
| 31 | BoolExprImpl() {} |
| 32 | virtual ~BoolExprImpl() {} |
| 33 | |
| 34 | private: |
Daniel Erat | 59c5f4b | 2015-08-24 12:50:25 -0600 | [diff] [blame] | 35 | DISALLOW_COPY_AND_ASSIGN(BoolExprImpl); |
| 36 | }; |
| 37 | |
| 38 | // Internal interface implemented by ResultExpr implementations. |
Luis Hector Chavez | 94ffa55 | 2016-05-25 15:29:35 -0700 | [diff] [blame] | 39 | class ResultExprImpl { |
Daniel Erat | 59c5f4b | 2015-08-24 12:50:25 -0600 | [diff] [blame] | 40 | public: |
Alex Vakulenko | 0d205d7 | 2016-01-15 13:02:14 -0800 | [diff] [blame] | 41 | // Compile uses |pc| to emit a CodeGen::Node that executes the |
| 42 | // represented result expression. |
| 43 | virtual CodeGen::Node Compile(PolicyCompiler* pc) const = 0; |
Daniel Erat | 59c5f4b | 2015-08-24 12:50:25 -0600 | [diff] [blame] | 44 | |
| 45 | // HasUnsafeTraps returns whether the result expression is or recursively |
| 46 | // contains an unsafe trap expression. |
| 47 | virtual bool HasUnsafeTraps() const; |
| 48 | |
| 49 | // IsAllow returns whether the result expression is an "allow" result. |
| 50 | virtual bool IsAllow() const; |
| 51 | |
| 52 | // IsAllow returns whether the result expression is a "deny" result. |
| 53 | virtual bool IsDeny() const; |
| 54 | |
| 55 | protected: |
| 56 | ResultExprImpl() {} |
| 57 | virtual ~ResultExprImpl() {} |
| 58 | |
| 59 | private: |
Daniel Erat | 59c5f4b | 2015-08-24 12:50:25 -0600 | [diff] [blame] | 60 | DISALLOW_COPY_AND_ASSIGN(ResultExprImpl); |
| 61 | }; |
| 62 | |
| 63 | } // namespace internal |
| 64 | } // namespace bpf_dsl |
| 65 | } // namespace sandbox |
| 66 | |
| 67 | #endif // SANDBOX_LINUX_BPF_DSL_BPF_DSL_IMPL_H_ |