• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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_SECCOMP_BPF_SANDBOX_BPF_COMPATIBILITY_POLICY_H_
6 #define SANDBOX_LINUX_SECCOMP_BPF_SANDBOX_BPF_COMPATIBILITY_POLICY_H_
7 
8 #include "base/basictypes.h"
9 #include "base/logging.h"
10 #include "base/macros.h"
11 #include "sandbox/linux/seccomp-bpf/sandbox_bpf.h"
12 #include "sandbox/linux/seccomp-bpf/sandbox_bpf_policy.h"
13 
14 namespace sandbox {
15 
16 // This class allows compatibility with the old, deprecated
17 // policies that were designed for SetSandboxPolicyDeprecated().
18 template <class AuxType>
19 class CompatibilityPolicy : public SandboxBPFPolicy {
20  public:
21   typedef ErrorCode (*SyscallEvaluator)(SandboxBPF* sandbox_compiler,
22                                         int system_call_number,
23                                         AuxType* aux);
CompatibilityPolicy(SyscallEvaluator syscall_evaluator,AuxType * aux)24   CompatibilityPolicy(SyscallEvaluator syscall_evaluator, AuxType* aux)
25       : syscall_evaluator_(syscall_evaluator), aux_(aux) {}
26 
~CompatibilityPolicy()27   virtual ~CompatibilityPolicy() {}
28 
EvaluateSyscall(SandboxBPF * sandbox_compiler,int system_call_number)29   virtual ErrorCode EvaluateSyscall(SandboxBPF* sandbox_compiler,
30                                     int system_call_number) const OVERRIDE {
31     DCHECK(SandboxBPF::IsValidSyscallNumber(system_call_number));
32     return syscall_evaluator_(sandbox_compiler, system_call_number, aux_);
33   }
34 
35  private:
36   SyscallEvaluator syscall_evaluator_;
37   AuxType* aux_;
38   DISALLOW_COPY_AND_ASSIGN(CompatibilityPolicy);
39 };
40 
41 }  // namespace sandbox
42 
43 #endif  // SANDBOX_LINUX_SECCOMP_BPF_SANDBOX_BPF_COMPATIBILITY_POLICY_H_
44