blob: f397321eddd7679c2daca3049bc50567eb610b16 [file] [log] [blame]
Daniel Erat59c5f4b2015-08-24 12:50:25 -06001// 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 Chavez94ffa552016-05-25 15:29:35 -07008#include <memory>
9
Daniel Erat59c5f4b2015-08-24 12:50:25 -060010#include "base/macros.h"
Alex Vakulenko0d205d72016-01-15 13:02:14 -080011#include "sandbox/linux/bpf_dsl/codegen.h"
Daniel Erat59c5f4b2015-08-24 12:50:25 -060012#include "sandbox/sandbox_export.h"
13
14namespace sandbox {
Daniel Erat59c5f4b2015-08-24 12:50:25 -060015namespace bpf_dsl {
16class PolicyCompiler;
17
18namespace internal {
19
20// Internal interface implemented by BoolExpr implementations.
Luis Hector Chavez94ffa552016-05-25 15:29:35 -070021class BoolExprImpl {
Daniel Erat59c5f4b2015-08-24 12:50:25 -060022 public:
Alex Vakulenko0d205d72016-01-15 13:02:14 -080023 // 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 Erat59c5f4b2015-08-24 12:50:25 -060025 // boolean expression is true or false.
Alex Vakulenko0d205d72016-01-15 13:02:14 -080026 virtual CodeGen::Node Compile(PolicyCompiler* pc,
27 CodeGen::Node then_node,
28 CodeGen::Node else_node) const = 0;
Daniel Erat59c5f4b2015-08-24 12:50:25 -060029
30 protected:
31 BoolExprImpl() {}
32 virtual ~BoolExprImpl() {}
33
34 private:
Daniel Erat59c5f4b2015-08-24 12:50:25 -060035 DISALLOW_COPY_AND_ASSIGN(BoolExprImpl);
36};
37
38// Internal interface implemented by ResultExpr implementations.
Luis Hector Chavez94ffa552016-05-25 15:29:35 -070039class ResultExprImpl {
Daniel Erat59c5f4b2015-08-24 12:50:25 -060040 public:
Alex Vakulenko0d205d72016-01-15 13:02:14 -080041 // 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 Erat59c5f4b2015-08-24 12:50:25 -060044
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 Erat59c5f4b2015-08-24 12:50:25 -060060 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_