| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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_POLICY_COMPILER_H_ | 5 #ifndef SANDBOX_LINUX_BPF_DSL_POLICY_COMPILER_H_ |
| 6 #define SANDBOX_LINUX_BPF_DSL_POLICY_COMPILER_H_ | 6 #define SANDBOX_LINUX_BPF_DSL_POLICY_COMPILER_H_ |
| 7 | 7 |
| 8 #include <stdint.h> | 8 #include <stdint.h> |
| 9 | 9 |
| 10 #include <map> | 10 #include <map> |
| 11 #include <set> | 11 #include <set> |
| 12 #include <vector> | 12 #include <vector> |
| 13 | 13 |
| 14 #include "base/macros.h" | 14 #include "base/macros.h" |
| 15 #include "base/memory/scoped_ptr.h" | 15 #include "base/memory/scoped_ptr.h" |
| 16 #include "sandbox/linux/seccomp-bpf/codegen.h" | 16 #include "sandbox/linux/seccomp-bpf/codegen.h" |
| 17 #include "sandbox/linux/seccomp-bpf/errorcode.h" | 17 #include "sandbox/linux/seccomp-bpf/errorcode.h" |
| 18 #include "sandbox/sandbox_export.h" | 18 #include "sandbox/sandbox_export.h" |
| 19 | 19 |
| 20 namespace sandbox { | 20 namespace sandbox { |
| 21 struct Instruction; | 21 struct Instruction; |
| 22 | 22 |
| 23 namespace bpf_dsl { | 23 namespace bpf_dsl { |
| 24 class SandboxBPFDSLPolicy; | 24 class Policy; |
| 25 | 25 |
| 26 // PolicyCompiler implements the bpf_dsl compiler, allowing users to | 26 // PolicyCompiler implements the bpf_dsl compiler, allowing users to |
| 27 // transform bpf_dsl policies into BPF programs to be executed by the | 27 // transform bpf_dsl policies into BPF programs to be executed by the |
| 28 // Linux kernel. | 28 // Linux kernel. |
| 29 class SANDBOX_EXPORT PolicyCompiler { | 29 class SANDBOX_EXPORT PolicyCompiler { |
| 30 public: | 30 public: |
| 31 PolicyCompiler(const SandboxBPFDSLPolicy* policy, TrapRegistry* registry); | 31 PolicyCompiler(const Policy* policy, TrapRegistry* registry); |
| 32 ~PolicyCompiler(); | 32 ~PolicyCompiler(); |
| 33 | 33 |
| 34 // Compile registers any trap handlers needed by the policy and | 34 // Compile registers any trap handlers needed by the policy and |
| 35 // compiles the policy to a BPF program, which it returns. | 35 // compiles the policy to a BPF program, which it returns. |
| 36 scoped_ptr<CodeGen::Program> Compile(); | 36 scoped_ptr<CodeGen::Program> Compile(); |
| 37 | 37 |
| 38 // Error returns an ErrorCode to indicate the system call should fail with | 38 // Error returns an ErrorCode to indicate the system call should fail with |
| 39 // the specified error number. | 39 // the specified error number. |
| 40 ErrorCode Error(int err); | 40 ErrorCode Error(int err); |
| 41 | 41 |
| (...skipping 109 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 151 // Returns a BPF program that evaluates half of a conditional expression; | 151 // Returns a BPF program that evaluates half of a conditional expression; |
| 152 // it should only ever be called from CondExpression(). | 152 // it should only ever be called from CondExpression(). |
| 153 Instruction* CondExpressionHalf(const ErrorCode& cond, | 153 Instruction* CondExpressionHalf(const ErrorCode& cond, |
| 154 ArgHalf half, | 154 ArgHalf half, |
| 155 Instruction* passed, | 155 Instruction* passed, |
| 156 Instruction* failed); | 156 Instruction* failed); |
| 157 | 157 |
| 158 // MakeTrap is the common implementation for Trap and UnsafeTrap. | 158 // MakeTrap is the common implementation for Trap and UnsafeTrap. |
| 159 ErrorCode MakeTrap(TrapRegistry::TrapFnc fnc, const void* aux, bool safe); | 159 ErrorCode MakeTrap(TrapRegistry::TrapFnc fnc, const void* aux, bool safe); |
| 160 | 160 |
| 161 const SandboxBPFDSLPolicy* policy_; | 161 const Policy* policy_; |
| 162 TrapRegistry* registry_; | 162 TrapRegistry* registry_; |
| 163 | 163 |
| 164 Conds conds_; | 164 Conds conds_; |
| 165 CodeGen gen_; | 165 CodeGen gen_; |
| 166 bool has_unsafe_traps_; | 166 bool has_unsafe_traps_; |
| 167 | 167 |
| 168 DISALLOW_COPY_AND_ASSIGN(PolicyCompiler); | 168 DISALLOW_COPY_AND_ASSIGN(PolicyCompiler); |
| 169 }; | 169 }; |
| 170 | 170 |
| 171 } // namespace bpf_dsl | 171 } // namespace bpf_dsl |
| 172 } // namespace sandbox | 172 } // namespace sandbox |
| 173 | 173 |
| 174 #endif // SANDBOX_LINUX_BPF_DSL_POLICY_COMPILER_H_ | 174 #endif // SANDBOX_LINUX_BPF_DSL_POLICY_COMPILER_H_ |
| OLD | NEW |