OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "sandbox/linux/seccomp-bpf/syscall_iterator.h" | 5 #include "sandbox/linux/seccomp-bpf/syscall_iterator.h" |
6 | 6 |
7 #include "base/basictypes.h" | 7 #include "base/basictypes.h" |
8 #include "sandbox/linux/seccomp-bpf/linux_seccomp.h" | 8 #include "sandbox/linux/seccomp-bpf/linux_seccomp.h" |
9 | 9 |
10 namespace sandbox { | 10 namespace sandbox { |
11 | 11 |
12 uint32_t SyscallIterator::Next() { | 12 uint32_t SyscallIterator::Next() { |
13 if (done_) { | 13 if (done_) { |
14 return num_; | 14 return num_; |
15 } | 15 } |
16 | 16 |
17 uint32_t val; | 17 uint32_t val; |
18 do { | 18 do { |
| 19 #if defined(__mips__) && (_MIPS_SIM == _MIPS_SIM_ABI32) |
| 20 // |num_| has been initialized to 4000, which we assume is also MIN_SYSCALL. |
| 21 // This is true for Mips O32 ABI. |
| 22 COMPILE_ASSERT(MIN_SYSCALL == __NR_Linux, min_syscall_should_be_4000); |
| 23 #else |
19 // |num_| has been initialized to 0, which we assume is also MIN_SYSCALL. | 24 // |num_| has been initialized to 0, which we assume is also MIN_SYSCALL. |
20 // This true for supported architectures (Intel and ARM EABI). | 25 // This true for supported architectures (Intel and ARM EABI). |
21 COMPILE_ASSERT(MIN_SYSCALL == 0u, min_syscall_should_always_be_zero); | 26 COMPILE_ASSERT(MIN_SYSCALL == 0u, min_syscall_should_always_be_zero); |
| 27 #endif |
22 val = num_; | 28 val = num_; |
23 | 29 |
| 30 // The syscall iterator always starts at zero. |
| 31 // If zero is not a valid system call, iterator first returns MIN_SYSCALL -1 |
| 32 // before continuing to iterate. |
| 33 if (num_ == 0 && MIN_SYSCALL != num_) { |
| 34 num_ = MIN_SYSCALL - 1; |
24 // First we iterate up to MAX_PUBLIC_SYSCALL, which is equal to MAX_SYSCALL | 35 // First we iterate up to MAX_PUBLIC_SYSCALL, which is equal to MAX_SYSCALL |
25 // on Intel architectures, but leaves room for private syscalls on ARM. | 36 // on Intel architectures, but leaves room for private syscalls on ARM. |
26 if (num_ <= MAX_PUBLIC_SYSCALL) { | 37 } else if (num_ <= MAX_PUBLIC_SYSCALL) { |
27 if (invalid_only_ && num_ < MAX_PUBLIC_SYSCALL) { | 38 if (invalid_only_ && num_ < MAX_PUBLIC_SYSCALL) { |
28 num_ = MAX_PUBLIC_SYSCALL; | 39 num_ = MAX_PUBLIC_SYSCALL; |
29 } else { | 40 } else { |
30 ++num_; | 41 ++num_; |
31 } | 42 } |
32 #if defined(__arm__) | 43 #if defined(__arm__) |
33 // ARM EABI includes "ARM private" system calls starting at | 44 // ARM EABI includes "ARM private" system calls starting at |
34 // MIN_PRIVATE_SYSCALL, and a "ghost syscall private to the kernel" at | 45 // MIN_PRIVATE_SYSCALL, and a "ghost syscall private to the kernel" at |
35 // MIN_GHOST_SYSCALL. | 46 // MIN_GHOST_SYSCALL. |
36 } else if (num_ < MIN_PRIVATE_SYSCALL - 1) { | 47 } else if (num_ < MIN_PRIVATE_SYSCALL - 1) { |
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
83 #if defined(__arm__) && (defined(__thumb__) || defined(__ARM_EABI__)) | 94 #if defined(__arm__) && (defined(__thumb__) || defined(__ARM_EABI__)) |
84 bool SyscallIterator::IsArmPrivate(uint32_t num) { | 95 bool SyscallIterator::IsArmPrivate(uint32_t num) { |
85 return (num >= MIN_PRIVATE_SYSCALL && num <= MAX_PRIVATE_SYSCALL) || | 96 return (num >= MIN_PRIVATE_SYSCALL && num <= MAX_PRIVATE_SYSCALL) || |
86 (num >= MIN_GHOST_SYSCALL && num <= MAX_SYSCALL); | 97 (num >= MIN_GHOST_SYSCALL && num <= MAX_SYSCALL); |
87 } | 98 } |
88 #else | 99 #else |
89 bool SyscallIterator::IsArmPrivate(uint32_t) { return false; } | 100 bool SyscallIterator::IsArmPrivate(uint32_t) { return false; } |
90 #endif | 101 #endif |
91 | 102 |
92 } // namespace sandbox | 103 } // namespace sandbox |
OLD | NEW |