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.h" | 5 #include "sandbox/linux/seccomp-bpf/syscall.h" |
6 | 6 |
7 #include <asm/unistd.h> | 7 #include <asm/unistd.h> |
8 #include <errno.h> | 8 #include <errno.h> |
9 | 9 |
10 #include "base/basictypes.h" | 10 #include "base/basictypes.h" |
| 11 #include "base/logging.h" |
11 | 12 |
12 namespace sandbox { | 13 namespace sandbox { |
13 | 14 |
14 namespace { | 15 namespace { |
15 | 16 |
16 asm(// We need to be able to tell the kernel exactly where we made a | 17 asm(// We need to be able to tell the kernel exactly where we made a |
17 // system call. The C++ compiler likes to sometimes clone or | 18 // system call. The C++ compiler likes to sometimes clone or |
18 // inline code, which would inadvertently end up duplicating | 19 // inline code, which would inadvertently end up duplicating |
19 // the entry point. | 20 // the entry point. |
20 // "gcc" can suppress code duplication with suitable function | 21 // "gcc" can suppress code duplication with suitable function |
(...skipping 153 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
174 ); // asm | 175 ); // asm |
175 | 176 |
176 } // namespace | 177 } // namespace |
177 | 178 |
178 intptr_t Syscall::Call(int nr, | 179 intptr_t Syscall::Call(int nr, |
179 intptr_t p0, | 180 intptr_t p0, |
180 intptr_t p1, | 181 intptr_t p1, |
181 intptr_t p2, | 182 intptr_t p2, |
182 intptr_t p3, | 183 intptr_t p3, |
183 intptr_t p4, | 184 intptr_t p4, |
184 intptr_t p5) { | 185 intptr_t p5, |
| 186 intptr_t p6, |
| 187 intptr_t p7) { |
185 // We rely on "intptr_t" to be the exact size as a "void *". This is | 188 // We rely on "intptr_t" to be the exact size as a "void *". This is |
186 // typically true, but just in case, we add a check. The language | 189 // typically true, but just in case, we add a check. The language |
187 // specification allows platforms some leeway in cases, where | 190 // specification allows platforms some leeway in cases, where |
188 // "sizeof(void *)" is not the same as "sizeof(void (*)())". We expect | 191 // "sizeof(void *)" is not the same as "sizeof(void (*)())". We expect |
189 // that this would only be an issue for IA64, which we are currently not | 192 // that this would only be an issue for IA64, which we are currently not |
190 // planning on supporting. And it is even possible that this would work | 193 // planning on supporting. And it is even possible that this would work |
191 // on IA64, but for lack of actual hardware, I cannot test. | 194 // on IA64, but for lack of actual hardware, I cannot test. |
192 COMPILE_ASSERT(sizeof(void*) == sizeof(intptr_t), | 195 COMPILE_ASSERT(sizeof(void*) == sizeof(intptr_t), |
193 pointer_types_and_intptr_must_be_exactly_the_same_size); | 196 pointer_types_and_intptr_must_be_exactly_the_same_size); |
194 | 197 |
| 198 // TODO(nedeljko): Enable use of more than six parameters on architectures |
| 199 // where that makes sense. |
| 200 DCHECK_EQ(p6, 0) << " Support for syscalls with more than six arguments not " |
| 201 "added for this architecture"; |
| 202 DCHECK_EQ(p7, 0) << " Support for syscalls with more than six arguments not " |
| 203 "added for this architecture"; |
195 const intptr_t args[6] = {p0, p1, p2, p3, p4, p5}; | 204 const intptr_t args[6] = {p0, p1, p2, p3, p4, p5}; |
196 | 205 |
197 // Invoke our file-scope assembly code. The constraints have been picked | 206 // Invoke our file-scope assembly code. The constraints have been picked |
198 // carefully to match what the rest of the assembly code expects in input, | 207 // carefully to match what the rest of the assembly code expects in input, |
199 // output, and clobbered registers. | 208 // output, and clobbered registers. |
200 #if defined(__i386__) | 209 #if defined(__i386__) |
201 intptr_t ret = nr; | 210 intptr_t ret = nr; |
202 asm volatile( | 211 asm volatile( |
203 "call SyscallAsm\n" | 212 "call SyscallAsm\n" |
204 // N.B. These are not the calling conventions normally used by the ABI. | 213 // N.B. These are not the calling conventions normally used by the ABI. |
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
259 ); | 268 ); |
260 ret = inout; | 269 ret = inout; |
261 } | 270 } |
262 #else | 271 #else |
263 #error "Unimplemented architecture" | 272 #error "Unimplemented architecture" |
264 #endif | 273 #endif |
265 return ret; | 274 return ret; |
266 } | 275 } |
267 | 276 |
268 } // namespace sandbox | 277 } // namespace sandbox |
OLD | NEW |