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

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

Issue 670183003: Update from chromium 62675d9fb31fb8cedc40f68e78e8445a74f362e7 (Closed) Base URL: git@github.com:domokit/mojo.git@master
Patch Set: Created 6 years, 2 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
« no previous file with comments | « sandbox/linux/seccomp-bpf/syscall.cc ('k') | sandbox/linux/seccomp-bpf/syscall_iterator.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
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
3 // found in the LICENSE file.
4
5 #ifndef SANDBOX_LINUX_SECCOMP_BPF_SYSCALL_ITERATOR_H__
6 #define SANDBOX_LINUX_SECCOMP_BPF_SYSCALL_ITERATOR_H__
7
8 #include <stdint.h>
9
10 #include "base/macros.h"
11 #include "sandbox/sandbox_export.h"
12
13 namespace sandbox {
14
15 // TODO(mdempsky): Rename this header to syscall_set.h.
16
17 // Iterates over the entire system call range from 0..0xFFFFFFFFu. This
18 // iterator is aware of how system calls look like and will skip quickly
19 // over ranges that can't contain system calls. It iterates more slowly
20 // whenever it reaches a range that is potentially problematic, returning
21 // the last invalid value before a valid range of system calls, and the
22 // first invalid value after a valid range of syscalls. It iterates over
23 // individual values whenever it is in the normal range for system calls
24 // (typically MIN_SYSCALL..MAX_SYSCALL).
25 //
26 // Example usage:
27 // for (uint32_t sysnum : SyscallSet::All()) {
28 // // Do something with sysnum.
29 // }
30 class SANDBOX_EXPORT SyscallSet {
31 public:
32 class Iterator;
33
34 SyscallSet(const SyscallSet& ss) : set_(ss.set_) {}
35 ~SyscallSet() {}
36
37 Iterator begin() const;
38 Iterator end() const;
39
40 // All returns a SyscallSet that contains both valid and invalid
41 // system call numbers.
42 static SyscallSet All() { return SyscallSet(Set::ALL); }
43
44 // InvalidOnly returns a SyscallSet that contains only invalid
45 // system call numbers, but still omits numbers in the middle of a
46 // range of invalid system call numbers.
47 static SyscallSet InvalidOnly() { return SyscallSet(Set::INVALID_ONLY); }
48
49 // IsValid returns whether |num| specifies a valid system call
50 // number.
51 static bool IsValid(uint32_t num);
52
53 private:
54 enum class Set { ALL, INVALID_ONLY };
55
56 explicit SyscallSet(Set set) : set_(set) {}
57
58 Set set_;
59
60 friend bool operator==(const SyscallSet&, const SyscallSet&);
61 DISALLOW_ASSIGN(SyscallSet);
62 };
63
64 SANDBOX_EXPORT bool operator==(const SyscallSet& lhs, const SyscallSet& rhs);
65
66 // Iterator provides C++ input iterator semantics for traversing a
67 // SyscallSet.
68 class SyscallSet::Iterator {
69 public:
70 Iterator(const Iterator& it)
71 : set_(it.set_), done_(it.done_), num_(it.num_) {}
72 ~Iterator() {}
73
74 uint32_t operator*() const;
75 Iterator& operator++();
76
77 private:
78 Iterator(Set set, bool done);
79
80 Set set_;
81 bool done_;
82 uint32_t num_;
83
84 friend SyscallSet;
85 friend bool operator==(const Iterator&, const Iterator&);
86 DISALLOW_ASSIGN(Iterator);
87 };
88
89 SANDBOX_EXPORT bool operator==(const SyscallSet::Iterator& lhs,
90 const SyscallSet::Iterator& rhs);
91 SANDBOX_EXPORT bool operator!=(const SyscallSet::Iterator& lhs,
92 const SyscallSet::Iterator& rhs);
93
94 } // namespace sandbox
95
96 #endif // SANDBOX_LINUX_SECCOMP_BPF_SYSCALL_ITERATOR_H__
OLDNEW
« no previous file with comments | « sandbox/linux/seccomp-bpf/syscall.cc ('k') | sandbox/linux/seccomp-bpf/syscall_iterator.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698