| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 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 | 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_SECCOMP_BPF_BPF_TESTER_COMPATIBILITY_DELEGATE_H_ | 5 #ifndef SANDBOX_LINUX_SECCOMP_BPF_BPF_TESTER_COMPATIBILITY_DELEGATE_H_ |
| 6 #define SANDBOX_LINUX_SECCOMP_BPF_BPF_TESTER_COMPATIBILITY_DELEGATE_H_ | 6 #define SANDBOX_LINUX_SECCOMP_BPF_BPF_TESTER_COMPATIBILITY_DELEGATE_H_ |
| 7 | 7 |
| 8 #include "base/memory/scoped_ptr.h" | 8 #include "base/memory/scoped_ptr.h" |
| 9 #include "sandbox/linux/seccomp-bpf/sandbox_bpf_test_runner.h" | 9 #include "sandbox/linux/seccomp-bpf/sandbox_bpf_test_runner.h" |
| 10 | 10 |
| 11 namespace sandbox { | 11 namespace sandbox { |
| 12 | 12 |
| 13 // This templated class allows building a BPFTesterDelegate from a | 13 // This templated class allows building a BPFTesterDelegate from a |
| 14 // deprecated-style BPF policy (that is a SyscallEvaluator function pointer, | 14 // deprecated-style BPF policy (that is a SyscallEvaluator function pointer, |
| 15 // instead of a SandboxBPFPolicy class), specified in |policy_function| and a | 15 // instead of a SandboxBPFPolicy class), specified in |policy_function| and a |
| 16 // function pointer to a test in |test_function|. | 16 // function pointer to a test in |test_function|. |
| 17 // This allows both the policy and the test function to take a pointer to an | 17 // This allows both the policy and the test function to take a pointer to an |
| 18 // object of type "Aux" as a parameter. This is used to implement the BPF_TEST | 18 // object of type "Aux" as a parameter. This is used to implement the BPF_TEST |
| 19 // macro and should generally not be used directly. | 19 // macro and should generally not be used directly. |
| 20 template <class Policy, class Aux> | 20 template <class Policy, class Aux> |
| 21 class BPFTesterCompatibilityDelegate : public BPFTesterDelegate { | 21 class BPFTesterCompatibilityDelegate : public BPFTesterDelegate { |
| 22 public: | 22 public: |
| 23 typedef void (*TestFunction)(Aux*); | 23 typedef void (*TestFunction)(Aux*); |
| 24 | 24 |
| 25 explicit BPFTesterCompatibilityDelegate(TestFunction test_function) | 25 explicit BPFTesterCompatibilityDelegate(TestFunction test_function) |
| 26 : aux_(), test_function_(test_function) {} | 26 : aux_(), test_function_(test_function) {} |
| 27 | 27 |
| 28 virtual ~BPFTesterCompatibilityDelegate() {} | 28 ~BPFTesterCompatibilityDelegate() override {} |
| 29 | 29 |
| 30 virtual scoped_ptr<bpf_dsl::Policy> GetSandboxBPFPolicy() override { | 30 scoped_ptr<bpf_dsl::Policy> GetSandboxBPFPolicy() override { |
| 31 // The current method is guaranteed to only run in the child process | 31 // The current method is guaranteed to only run in the child process |
| 32 // running the test. In this process, the current object is guaranteed | 32 // running the test. In this process, the current object is guaranteed |
| 33 // to live forever. So it's ok to pass aux_pointer_for_policy_ to | 33 // to live forever. So it's ok to pass aux_pointer_for_policy_ to |
| 34 // the policy, which could in turn pass it to the kernel via Trap(). | 34 // the policy, which could in turn pass it to the kernel via Trap(). |
| 35 return scoped_ptr<bpf_dsl::Policy>(new Policy(&aux_)); | 35 return scoped_ptr<bpf_dsl::Policy>(new Policy(&aux_)); |
| 36 } | 36 } |
| 37 | 37 |
| 38 virtual void RunTestFunction() override { | 38 void RunTestFunction() override { |
| 39 // Run the actual test. | 39 // Run the actual test. |
| 40 // The current object is guaranteed to live forever in the child process | 40 // The current object is guaranteed to live forever in the child process |
| 41 // where this will run. | 41 // where this will run. |
| 42 test_function_(&aux_); | 42 test_function_(&aux_); |
| 43 } | 43 } |
| 44 | 44 |
| 45 private: | 45 private: |
| 46 Aux aux_; | 46 Aux aux_; |
| 47 TestFunction test_function_; | 47 TestFunction test_function_; |
| 48 | 48 |
| 49 DISALLOW_COPY_AND_ASSIGN(BPFTesterCompatibilityDelegate); | 49 DISALLOW_COPY_AND_ASSIGN(BPFTesterCompatibilityDelegate); |
| 50 }; | 50 }; |
| 51 | 51 |
| 52 } // namespace sandbox | 52 } // namespace sandbox |
| 53 | 53 |
| 54 #endif // SANDBOX_LINUX_SECCOMP_BPF_BPF_TESTER_COMPATIBILITY_DELEGATE_H_ | 54 #endif // SANDBOX_LINUX_SECCOMP_BPF_BPF_TESTER_COMPATIBILITY_DELEGATE_H_ |
| OLD | NEW |