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

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

Issue 11096012: Add a platform-specific syscall number iterator. (Closed) Base URL: http://git.chromium.org/chromium/src.git@master
Patch Set: Assume MIN_SYSCALL == 0, remove X32 support, address comments. Created 8 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
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
new file mode 100644
index 0000000000000000000000000000000000000000..717d6b57ea24b8580f48be2b279266d50c465bf1
--- /dev/null
+++ b/sandbox/linux/seccomp-bpf/syscall_iterator.h
@@ -0,0 +1,56 @@
+// Copyright (c) 2012 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#ifndef SANDBOX_LINUX_SECCOMP_BPF_SYSCALL_ITERATOR_H__
+#define SANDBOX_LINUX_SECCOMP_BPF_SYSCALL_ITERATOR_H__
+
+#include <stdint.h>
+
+#include <base/logging.h>
+
+namespace playground2 {
+
+// Iterates over the entire system call range from 0..0xFFFFFFFFu. This
+// iterator is aware of how system calls look like and will skip quickly
+// over ranges that can't contain system calls. It iterates more slowly
+// whenever it reaches a range that is potentially problematic. And 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, the iterator will only return invalid
+// syscall numbers, but will still skip quickly over invalid ranges.
+//
+// Example usage:
+// for (SyscallIterator iter(false); !iter.Done(); ) {
+// uint32_t sysnum = iter.Next();
+// // Do something with sysnum.
+// }
+//
+// TODO(markus): Make this a classic C++ iterator.
+class SyscallIterator {
+ public:
+ explicit SyscallIterator(bool invalid_only)
+ : invalid_only_(invalid_only),
jln (very slow on Chromium) 2012/10/13 02:44:22 Style: You misread my previous comment. Colon shou
Jorge Lucangeli Obes 2012/10/13 04:45:42 I'm not sure what's wrong in this case. The colon
+ done_(false),
+ num_(MIN_SYSCALL) {
+ CHECK_EQ(MIN_SYSCALL, 0u);
jln (very slow on Chromium) 2012/10/13 02:44:22 This needs to be localized where you are actually
Jorge Lucangeli Obes 2012/10/13 04:45:42 Done.
+ }
+
+ bool Done() const { return done_; }
+ uint32_t Next();
+ static bool IsValid(uint32_t num);
+
+ private:
+ static bool IsArmPrivate(uint32_t num);
+
+ bool invalid_only_;
+ bool done_;
+ uint32_t num_;
+
+ DISALLOW_COPY_AND_ASSIGN(SyscallIterator);
+};
+
+} // namespace
jln (very slow on Chromium) 2012/10/13 02:44:22 Style: namespace playground2
Jorge Lucangeli Obes 2012/10/13 04:45:42 Done.
+
+#endif // SANDBOX_LINUX_SECCOMP_BPF_SYSCALL_ITERATOR_H__
+

Powered by Google App Engine
This is Rietveld 408576698