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