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 #ifndef SANDBOX_LINUX_SECCOMP_BPF_SYSCALL_H__ | 5 #ifndef SANDBOX_LINUX_SECCOMP_BPF_SYSCALL_H__ |
6 #define SANDBOX_LINUX_SECCOMP_BPF_SYSCALL_H__ | 6 #define SANDBOX_LINUX_SECCOMP_BPF_SYSCALL_H__ |
7 | 7 |
| 8 #include <signal.h> |
8 #include <stdint.h> | 9 #include <stdint.h> |
9 | 10 |
10 #include "base/macros.h" | 11 #include "base/macros.h" |
11 #include "sandbox/sandbox_export.h" | 12 #include "sandbox/sandbox_export.h" |
12 | 13 |
| 14 // Android's signal.h doesn't define ucontext etc. |
| 15 #if defined(OS_ANDROID) |
| 16 #include "sandbox/linux/services/android_ucontext.h" |
| 17 #endif |
| 18 |
13 namespace sandbox { | 19 namespace sandbox { |
14 | 20 |
15 // This purely static class can be used to perform system calls with some | 21 // This purely static class can be used to perform system calls with some |
16 // low-level control. | 22 // low-level control. |
17 class SANDBOX_EXPORT Syscall { | 23 class SANDBOX_EXPORT Syscall { |
18 public: | 24 public: |
19 // System calls can take up to six parameters (up to eight on some | 25 // System calls can take up to six parameters (up to eight on some |
20 // architectures). Traditionally, glibc | 26 // architectures). Traditionally, glibc |
21 // implements this property by using variadic argument lists. This works, but | 27 // implements this property by using variadic argument lists. This works, but |
22 // confuses modern tools such as valgrind, because we are nominally passing | 28 // confuses modern tools such as valgrind, because we are nominally passing |
(...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
105 | 111 |
106 template <class T0> | 112 template <class T0> |
107 static inline intptr_t Call(int nr, T0 p0) { | 113 static inline intptr_t Call(int nr, T0 p0) { |
108 return Call(nr, p0, 0, 0, 0, 0, 0, 0, 0); | 114 return Call(nr, p0, 0, 0, 0, 0, 0, 0, 0); |
109 } | 115 } |
110 | 116 |
111 static inline intptr_t Call(int nr) { | 117 static inline intptr_t Call(int nr) { |
112 return Call(nr, 0, 0, 0, 0, 0, 0, 0, 0); | 118 return Call(nr, 0, 0, 0, 0, 0, 0, 0, 0); |
113 } | 119 } |
114 | 120 |
| 121 // Set the registers in |ctx| to match what they would be after a system call |
| 122 // returning |ret_val|. |ret_val| must follow the Syscall::Call() convention |
| 123 // of being -errno on errors. |
| 124 static void PutValueInUcontext(intptr_t ret_val, ucontext_t* ctx); |
| 125 |
115 private: | 126 private: |
116 // This performs system call |nr| with the arguments p0 to p7 from a constant | 127 // This performs system call |nr| with the arguments p0 to p7 from a constant |
117 // userland address, which is for instance observable by seccomp-bpf filters. | 128 // userland address, which is for instance observable by seccomp-bpf filters. |
118 // The constant userland address from which these system calls are made will | 129 // The constant userland address from which these system calls are made will |
119 // be returned if |nr| is passed as -1. | 130 // be returned if |nr| is passed as -1. |
120 // On error, this function will return a value between -1 and -4095 which | 131 // On error, this function will return a value between -1 and -4095 which |
121 // should be interpreted as -errno. | 132 // should be interpreted as -errno. |
122 static intptr_t Call(int nr, | 133 static intptr_t Call(int nr, |
123 intptr_t p0, | 134 intptr_t p0, |
124 intptr_t p1, | 135 intptr_t p1, |
125 intptr_t p2, | 136 intptr_t p2, |
126 intptr_t p3, | 137 intptr_t p3, |
127 intptr_t p4, | 138 intptr_t p4, |
128 intptr_t p5, | 139 intptr_t p5, |
129 intptr_t p6, | 140 intptr_t p6, |
130 intptr_t p7); | 141 intptr_t p7); |
131 | 142 |
| 143 #if defined(__mips__) |
| 144 // This function basically does on MIPS what SandboxSyscall() is doing on |
| 145 // other architectures. However, because of specificity of MIPS regarding |
| 146 // handling syscall errors, SandboxSyscall() is made as a wrapper for this |
| 147 // function in order for SandboxSyscall() to behave more like on other |
| 148 // architectures on places where return value from SandboxSyscall() is used |
| 149 // directly (like in most tests). |
| 150 // The syscall "nr" is called with arguments that are set in an array on which |
| 151 // pointer "args" points to and an information weather there is an error or no |
| 152 // is returned to SandboxSyscall() by err_stat. |
| 153 static intptr_t SandboxSyscallRaw(int nr, |
| 154 const intptr_t* args, |
| 155 intptr_t* err_stat); |
| 156 #endif // defined(__mips__) |
| 157 |
132 DISALLOW_IMPLICIT_CONSTRUCTORS(Syscall); | 158 DISALLOW_IMPLICIT_CONSTRUCTORS(Syscall); |
133 }; | 159 }; |
134 | 160 |
135 } // namespace sandbox | 161 } // namespace sandbox |
136 | 162 |
137 #endif // SANDBOX_LINUX_SECCOMP_BPF_SYSCALL_H__ | 163 #endif // SANDBOX_LINUX_SECCOMP_BPF_SYSCALL_H__ |
OLD | NEW |