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

Unified Diff: sandbox/linux/bpf_dsl/policy_compiler.cc

Issue 659723002: SyscallIterator: support C++11 range-based for loops (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Change SyscallSet into a proper class 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
Index: sandbox/linux/bpf_dsl/policy_compiler.cc
diff --git a/sandbox/linux/bpf_dsl/policy_compiler.cc b/sandbox/linux/bpf_dsl/policy_compiler.cc
index ad100f957994227095aa3458fbd1b4a5b3f40a8f..0eb85ca6736bb3662dbf520b13d7723e7c2cc3d8 100644
--- a/sandbox/linux/bpf_dsl/policy_compiler.cc
+++ b/sandbox/linux/bpf_dsl/policy_compiler.cc
@@ -76,9 +76,8 @@ intptr_t BPFFailure(const struct arch_seccomp_data&, void* aux) {
}
bool HasUnsafeTraps(const SandboxBPFDSLPolicy* policy) {
- for (SyscallIterator iter(false); !iter.Done();) {
- uint32_t sysnum = iter.Next();
- if (SyscallIterator::IsValid(sysnum) &&
+ for (uint32_t sysnum : SyscallSet::All()) {
+ if (SyscallSet::IsValid(sysnum) &&
policy->EvaluateSyscall(sysnum)->HasUnsafeTraps()) {
return true;
}
@@ -89,8 +88,8 @@ bool HasUnsafeTraps(const SandboxBPFDSLPolicy* policy) {
} // namespace
struct PolicyCompiler::Range {
- Range(uint32_t f, uint32_t t, const ErrorCode& e) : from(f), to(t), err(e) {}
- uint32_t from, to;
+ Range(uint32_t f, const ErrorCode& e) : from(f), err(e) {}
+ uint32_t from;
ErrorCode err;
};
@@ -252,22 +251,22 @@ void PolicyCompiler::FindRanges(Ranges* ranges) {
// negative) all return the same ErrorCode.
const ErrorCode invalid_err = policy_->InvalidSyscall()->Compile(this);
uint32_t old_sysnum = 0;
- ErrorCode old_err = SyscallIterator::IsValid(old_sysnum)
+ ErrorCode old_err = SyscallSet::IsValid(old_sysnum)
? policy_->EvaluateSyscall(old_sysnum)->Compile(this)
: invalid_err;
- for (SyscallIterator iter(false); !iter.Done();) {
- uint32_t sysnum = iter.Next();
+ for (uint32_t sysnum : SyscallSet::All()) {
ErrorCode err =
- SyscallIterator::IsValid(sysnum)
+ SyscallSet::IsValid(sysnum)
? policy_->EvaluateSyscall(static_cast<int>(sysnum))->Compile(this)
: invalid_err;
- if (!err.Equals(old_err) || iter.Done()) {
- ranges->push_back(Range(old_sysnum, sysnum - 1, old_err));
+ if (!err.Equals(old_err)) {
+ ranges->push_back(Range(old_sysnum, old_err));
old_sysnum = sysnum;
old_err = err;
}
}
+ ranges->push_back(Range(old_sysnum, old_err));
}
Instruction* PolicyCompiler::AssembleJumpTable(Ranges::const_iterator start,
« no previous file with comments | « no previous file | sandbox/linux/seccomp-bpf/sandbox_bpf.cc » ('j') | sandbox/linux/seccomp-bpf/syscall_iterator.h » ('J')

Powered by Google App Engine
This is Rietveld 408576698