Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(309)

Side by Side Diff: sandbox/linux/seccomp-bpf/bpf_tester_compatibility_delegate.h

Issue 1849323003: Convert //sandbox to use std::unique_ptr (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: fixup nonsfi_sandbox_unittest.cc Created 4 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 <memory>
9
8 #include "base/macros.h" 10 #include "base/macros.h"
9 #include "base/memory/scoped_ptr.h"
10 #include "sandbox/linux/seccomp-bpf/sandbox_bpf_test_runner.h" 11 #include "sandbox/linux/seccomp-bpf/sandbox_bpf_test_runner.h"
11 12
12 namespace sandbox { 13 namespace sandbox {
13 14
14 // This templated class allows building a BPFTesterDelegate from a 15 // This templated class allows building a BPFTesterDelegate from a
15 // deprecated-style BPF policy (that is a SyscallEvaluator function pointer, 16 // deprecated-style BPF policy (that is a SyscallEvaluator function pointer,
16 // instead of a SandboxBPFPolicy class), specified in |policy_function| and a 17 // instead of a SandboxBPFPolicy class), specified in |policy_function| and a
17 // function pointer to a test in |test_function|. 18 // function pointer to a test in |test_function|.
18 // This allows both the policy and the test function to take a pointer to an 19 // This allows both the policy and the test function to take a pointer to an
19 // object of type "Aux" as a parameter. This is used to implement the BPF_TEST 20 // object of type "Aux" as a parameter. This is used to implement the BPF_TEST
20 // macro and should generally not be used directly. 21 // macro and should generally not be used directly.
21 template <class Policy, class Aux> 22 template <class Policy, class Aux>
22 class BPFTesterCompatibilityDelegate : public BPFTesterDelegate { 23 class BPFTesterCompatibilityDelegate : public BPFTesterDelegate {
23 public: 24 public:
24 typedef void (*TestFunction)(Aux*); 25 typedef void (*TestFunction)(Aux*);
25 26
26 explicit BPFTesterCompatibilityDelegate(TestFunction test_function) 27 explicit BPFTesterCompatibilityDelegate(TestFunction test_function)
27 : aux_(), test_function_(test_function) {} 28 : aux_(), test_function_(test_function) {}
28 29
29 ~BPFTesterCompatibilityDelegate() override {} 30 ~BPFTesterCompatibilityDelegate() override {}
30 31
31 scoped_ptr<bpf_dsl::Policy> GetSandboxBPFPolicy() override { 32 std::unique_ptr<bpf_dsl::Policy> GetSandboxBPFPolicy() override {
32 // The current method is guaranteed to only run in the child process 33 // The current method is guaranteed to only run in the child process
33 // running the test. In this process, the current object is guaranteed 34 // running the test. In this process, the current object is guaranteed
34 // to live forever. So it's ok to pass aux_pointer_for_policy_ to 35 // to live forever. So it's ok to pass aux_pointer_for_policy_ to
35 // the policy, which could in turn pass it to the kernel via Trap(). 36 // the policy, which could in turn pass it to the kernel via Trap().
36 return scoped_ptr<bpf_dsl::Policy>(new Policy(&aux_)); 37 return std::unique_ptr<bpf_dsl::Policy>(new Policy(&aux_));
37 } 38 }
38 39
39 void RunTestFunction() override { 40 void RunTestFunction() override {
40 // Run the actual test. 41 // Run the actual test.
41 // The current object is guaranteed to live forever in the child process 42 // The current object is guaranteed to live forever in the child process
42 // where this will run. 43 // where this will run.
43 test_function_(&aux_); 44 test_function_(&aux_);
44 } 45 }
45 46
46 private: 47 private:
47 Aux aux_; 48 Aux aux_;
48 TestFunction test_function_; 49 TestFunction test_function_;
49 50
50 DISALLOW_COPY_AND_ASSIGN(BPFTesterCompatibilityDelegate); 51 DISALLOW_COPY_AND_ASSIGN(BPFTesterCompatibilityDelegate);
51 }; 52 };
52 53
53 } // namespace sandbox 54 } // namespace sandbox
54 55
55 #endif // SANDBOX_LINUX_SECCOMP_BPF_BPF_TESTER_COMPATIBILITY_DELEGATE_H_ 56 #endif // SANDBOX_LINUX_SECCOMP_BPF_BPF_TESTER_COMPATIBILITY_DELEGATE_H_
OLDNEW
« no previous file with comments | « sandbox/linux/integration_tests/seccomp_broker_process_unittest.cc ('k') | sandbox/linux/seccomp-bpf/bpf_tests.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698