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

Unified Diff: sandbox/linux/seccomp-bpf/syscall_iterator.h

Issue 659723002: SyscallIterator: support C++11 range-based for loops (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Sync and fix style 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « sandbox/linux/bpf_dsl/policy_compiler.cc ('k') | sandbox/linux/seccomp-bpf/syscall_iterator.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: sandbox/linux/seccomp-bpf/syscall_iterator.h
diff --git a/sandbox/linux/seccomp-bpf/syscall_iterator.h b/sandbox/linux/seccomp-bpf/syscall_iterator.h
index 3796be599553dbee0253466ce168412f0eff8121..f2d78bf6d7c453ed684437502bcd28266fa2d252 100644
--- a/sandbox/linux/seccomp-bpf/syscall_iterator.h
+++ b/sandbox/linux/seccomp-bpf/syscall_iterator.h
@@ -11,6 +11,7 @@
#include "sandbox/sandbox_export.h"
namespace sandbox {
+class SyscallIterator;
// Iterates over the entire system call range from 0..0xFFFFFFFFu. This
// iterator is aware of how system calls look like and will skip quickly
@@ -20,35 +21,58 @@ namespace sandbox {
// first invalid value after a valid range of syscalls. It iterates over
// individual values whenever it is in the normal range for system calls
// (typically MIN_SYSCALL..MAX_SYSCALL).
-// If |invalid_only| is true, this iterator will only return invalid
-// syscall numbers, but will still skip quickly over invalid ranges,
-// returning the first invalid value in the range and then skipping
-// to the last invalid value in the range.
//
// Example usage:
-// for (SyscallIterator iter(false); !iter.Done(); ) {
-// uint32_t sysnum = iter.Next();
+// for (uint32_t sysnum : SyscallSet::ALL) {
// // Do something with sysnum.
// }
-//
-// TODO(markus): Make this a classic C++ iterator.
+
+enum class SyscallSet {
+ // The "ALL" system call set contains both valid and invalid system
+ // call numbers.
+ ALL,
+
+ // The "INVALID_ONLY" system call set contains only valid system call
+ // numbers, but will still skip quickly over invalid ranges,
+ // returning the first invalid value in the range and then skipping
+ // to the last invalid value in the range.
+ INVALID_ONLY,
+
+ // TODO(mdempsky): Add ValidOnly.
+};
+
+// Begin returns an iterator pointing to the first element of the
+// specified system call set.
+SANDBOX_EXPORT SyscallIterator begin(SyscallSet set);
jln (very slow on Chromium) 2014/10/21 23:31:24 I find it a little strange to have a top-level beg
mdempsky 2014/10/22 00:15:33 We can, but it would add some more boiler plate, a
+
+// End returns an iterator pointing to the past-the-end element of the
+// specified system call set.
+SANDBOX_EXPORT SyscallIterator end(SyscallSet set);
+
+// SyscallIterator provides C++ forward iterator semantics for
+// traversing a system call set.
class SANDBOX_EXPORT SyscallIterator {
public:
- explicit SyscallIterator(bool invalid_only)
- : invalid_only_(invalid_only), done_(false), num_(0) {}
+ SyscallIterator(SyscallSet set, bool done);
+
+ uint32_t operator*() const;
+ SyscallIterator& operator++();
jln (very slow on Chromium) 2014/10/21 23:31:24 I don't think we need / use the return value. Let'
mdempsky 2014/10/22 00:15:33 Technically, the C++ spec's requirements on iterat
- bool Done() const { return done_; }
- uint32_t Next();
+ friend bool operator==(const SyscallIterator& lhs,
+ const SyscallIterator& rhs);
+
+ // TODO(mdempsky): Move elsewhere.
static bool IsValid(uint32_t num);
private:
- bool invalid_only_;
+ SyscallSet set_;
bool done_;
jln (very slow on Chromium) 2014/10/21 23:31:24 done_ feels weird. Could we just replace it with
mdempsky 2014/10/22 00:15:33 We can't simply get rid of "bool done_", because "
uint32_t num_;
-
- DISALLOW_IMPLICIT_CONSTRUCTORS(SyscallIterator);
};
+SANDBOX_EXPORT bool operator!=(const SyscallIterator& lhs,
+ const SyscallIterator& rhs);
+
} // namespace sandbox
#endif // SANDBOX_LINUX_SECCOMP_BPF_SYSCALL_ITERATOR_H__
« no previous file with comments | « sandbox/linux/bpf_dsl/policy_compiler.cc ('k') | sandbox/linux/seccomp-bpf/syscall_iterator.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698