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

Side by Side Diff: sandbox/linux/seccomp-bpf/syscall_iterator_unittest.cc

Issue 11096012: Add a platform-specific syscall number iterator. (Closed) Base URL: http://git.chromium.org/chromium/src.git@master
Patch Set: 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 unified diff | Download patch
« no previous file with comments | « sandbox/linux/seccomp-bpf/syscall_iterator.cc ('k') | sandbox/linux/seccomp-bpf/verifier.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 #include "sandbox/linux/seccomp-bpf/sandbox_bpf.h"
6 #include "sandbox/linux/seccomp-bpf/syscall_iterator.h"
7 #include "sandbox/linux/tests/unit_tests.h"
8
9 using namespace playground2;
10
11 namespace {
12
13 SANDBOX_TEST(SyscallIterator, Monotonous) {
14 for (int i = 0; i < 2; ++i) {
15 SyscallIterator iter(!i);
16 uint32_t next = iter.Next();
17 if (i || MIN_SYSCALL != 0) {
18 SANDBOX_ASSERT(next == 0);
19 }
20 for (uint32_t last = next; !iter.Done(); last = next) {
21 next = iter.Next();
22 SANDBOX_ASSERT(last < next);
23 }
24 SANDBOX_ASSERT(next == 0xFFFFFFFFu);
25 }
26 }
27
28 SANDBOX_TEST(SyscallIterator, SyscallRange) {
29 SyscallIterator iter(false);
30 uint32_t next = iter.Next();
31 while (next < std::max(MIN_SYSCALL, 1u)-1) {
32 next = iter.Next();
33 }
34 SANDBOX_ASSERT(next == std::max(MIN_SYSCALL, 1u)-1);
35 for (uint32_t last = next; next < MAX_PUBLIC_SYSCALL+1; last = next) {
36 SANDBOX_ASSERT((next = iter.Next()) == last+1);
37 }
38 SANDBOX_ASSERT(next == MAX_PUBLIC_SYSCALL+1);
39 }
40
41 #if defined(__i386__) || defined(__x86_64__)
42 SANDBOX_TEST(SyscallIterator, X32) {
43 SyscallIterator iter(false);
44 uint32_t next = iter.Next();
45 while (next < std::max(MIN_SYSCALL^0x40000000u, 1u)-1) {
46 next = iter.Next();
47 }
48 SANDBOX_ASSERT(next == std::max(MIN_SYSCALL^0x40000000u, 1u)-1);
49 for (uint32_t last = next; next < (MAX_SYSCALL^0x40000000u)+1; last = next) {
50 SANDBOX_ASSERT((next = iter.Next()) == last+1);
51 }
52 SANDBOX_ASSERT(next == (MAX_SYSCALL^0x40000000u)+1);
53 }
54 #endif
55
56 #if defined(__arm__)
57 SANDBOX_TEST(SyscallIterator, ARMPrivate) {
58 SyscallIterator iter(false);
59 uint32_t next = iter.Next();
60 while (next < MIN_PRIVATE_SYSCALL-1) {
61 next = iter.Next();
62 }
63 SANDBOX_ASSERT(next == MIN_PRIVATE_SYSCALL-1);
64 for (uint32_t last = next; next < MAX_PRIVATE_SYSCALL+1; last = next) {
65 SANDBOX_ASSERT((next = iter.Next()) == last+1);
66 }
67 SANDBOX_ASSERT(next == MAX_PRIVATE_SYSCALL+1);
68 }
69
70 SANDBOX_TEST(SyscallIterator, ARMHidden) {
71 SyscallIterator iter(false);
72 uint32_t next = iter.Next();
73 while (next < __ARM_NR_cmpxchg-1) {
74 next = iter.Next();
75 }
76 SANDBOX_ASSERT(next == __ARM_NR_cmpxchg-1);
77 for (uint32_t last = next; next < MAX_SYSCALL+1; last = next) {
78 SANDBOX_ASSERT((next = iter.Next()) == last+1);
79 }
80 SANDBOX_ASSERT(next == MAX_SYSCALL+1);
81 }
82 #endif
83
84 SANDBOX_TEST(SyscallIterator, Invalid) {
85 for (int i = 0; i < 2; ++i) {
86 SyscallIterator iter(!i);
87 uint32_t next = iter.Next();
88 if (i || MIN_SYSCALL != 0) {
89 SANDBOX_ASSERT(next == 0);
90 }
91 if (MIN_SYSCALL > 1) {
92 while (next < MIN_SYSCALL-1) {
93 next = iter.Next();
94 }
95 SANDBOX_ASSERT(next == MIN_SYSCALL-1);
96 }
97 while (next < MAX_SYSCALL+1) {
98 next = iter.Next();
99 }
100 SANDBOX_ASSERT(next == MAX_SYSCALL+1);
101 while (next < 0x7FFFFFFFu) {
102 next = iter.Next();
103 }
104 SANDBOX_ASSERT(next == 0x7FFFFFFFu);
105 next = iter.Next();
106 SANDBOX_ASSERT(next == 0x80000000u);
107 SANDBOX_ASSERT(!iter.Done());
108 next = iter.Next();
109 SANDBOX_ASSERT( iter.Done());
110 SANDBOX_ASSERT(next == 0xFFFFFFFFu);
111 }
112 }
113
114 SANDBOX_TEST(SyscallIterator, InvalidOnly) {
115 for (SyscallIterator iter(true); !iter.Done(); ) {
116 uint32_t next = iter.Next();
117 SANDBOX_ASSERT(next < MIN_SYSCALL || next > MAX_PUBLIC_SYSCALL);
118 #if defined(__arm__)
119 SANDBOX_ASSERT(next < MIN_PRIVATE_SYSCALL || next > MAX_PRIVATE_SYSCALL);
120 SANDBOX_ASSERT(next < __ARM_NR_cmpxchg || next > MAX_SYSCALL);
121 #endif
122 }
123
124 }
125
126 } // namespace
OLDNEW
« no previous file with comments | « sandbox/linux/seccomp-bpf/syscall_iterator.cc ('k') | sandbox/linux/seccomp-bpf/verifier.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698