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" |
(...skipping 207 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
218 // Enter the kernel | 218 // Enter the kernel |
219 "syscall\n" | 219 "syscall\n" |
220 // This is our "magic" return address that the BPF filter sees. | 220 // This is our "magic" return address that the BPF filter sees. |
221 // Restore the return address from the stack. | 221 // Restore the return address from the stack. |
222 "2:lw $ra, 36($sp)\n" | 222 "2:lw $ra, 36($sp)\n" |
223 "jr $ra\n" | 223 "jr $ra\n" |
224 " addiu $sp, $sp, 40\n" | 224 " addiu $sp, $sp, 40\n" |
225 ".set pop\n" | 225 ".set pop\n" |
226 ".end SyscallAsm\n" | 226 ".end SyscallAsm\n" |
227 ".size SyscallAsm,.-SyscallAsm\n" | 227 ".size SyscallAsm,.-SyscallAsm\n" |
| 228 #elif defined(__aarch64__) |
| 229 ".text\n" |
| 230 ".align 2\n" |
| 231 ".type SyscallAsm, %function\n" |
| 232 "SyscallAsm:\n" |
| 233 ".cfi_startproc\n" |
| 234 "cmp x0, #0\n" |
| 235 "b.ge 1f\n" |
| 236 "adr x0,2f\n" |
| 237 "b 2f\n" |
| 238 "1:ldr x5, [x6, #40]\n" |
| 239 "ldr x4, [x6, #32]\n" |
| 240 "ldr x3, [x6, #24]\n" |
| 241 "ldr x2, [x6, #16]\n" |
| 242 "ldr x1, [x6, #8]\n" |
| 243 "mov x8, x0\n" |
| 244 "ldr x0, [x6, #0]\n" |
| 245 // Enter the kernel |
| 246 "svc 0\n" |
| 247 "2:ret\n" |
| 248 ".cfi_endproc\n" |
| 249 ".size SyscallAsm, .-SyscallAsm\n" |
228 #endif | 250 #endif |
229 ); // asm | 251 ); // asm |
230 | 252 |
231 } // namespace | 253 } // namespace |
232 | 254 |
233 intptr_t Syscall::InvalidCall() { | 255 intptr_t Syscall::InvalidCall() { |
234 // Explicitly pass eight zero arguments just in case. | 256 // Explicitly pass eight zero arguments just in case. |
235 return Call(kInvalidSyscallNumber, 0, 0, 0, 0, 0, 0, 0, 0); | 257 return Call(kInvalidSyscallNumber, 0, 0, 0, 0, 0, 0, 0, 0); |
236 } | 258 } |
237 | 259 |
(...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
334 #elif defined(__mips__) | 356 #elif defined(__mips__) |
335 int err_status; | 357 int err_status; |
336 intptr_t ret = Syscall::SandboxSyscallRaw(nr, args, &err_status); | 358 intptr_t ret = Syscall::SandboxSyscallRaw(nr, args, &err_status); |
337 | 359 |
338 if (err_status) { | 360 if (err_status) { |
339 // On error, MIPS returns errno from syscall instead of -errno. | 361 // On error, MIPS returns errno from syscall instead of -errno. |
340 // The purpose of this negation is for SandboxSyscall() to behave | 362 // The purpose of this negation is for SandboxSyscall() to behave |
341 // more like it would on other architectures. | 363 // more like it would on other architectures. |
342 ret = -ret; | 364 ret = -ret; |
343 } | 365 } |
| 366 #elif defined(__aarch64__) |
| 367 intptr_t ret; |
| 368 { |
| 369 register intptr_t inout __asm__("x0") = nr; |
| 370 register const intptr_t* data __asm__("x6") = args; |
| 371 asm volatile("bl SyscallAsm\n" |
| 372 : "=r"(inout) |
| 373 : "0"(inout), "r"(data) |
| 374 : "memory", "x1", "x2", "x3", "x4", "x5", "x8", "x30"); |
| 375 ret = inout; |
| 376 } |
| 377 |
344 #else | 378 #else |
345 #error "Unimplemented architecture" | 379 #error "Unimplemented architecture" |
346 #endif | 380 #endif |
347 return ret; | 381 return ret; |
348 } | 382 } |
349 | 383 |
350 void Syscall::PutValueInUcontext(intptr_t ret_val, ucontext_t* ctx) { | 384 void Syscall::PutValueInUcontext(intptr_t ret_val, ucontext_t* ctx) { |
351 #if defined(__mips__) | 385 #if defined(__mips__) |
352 // Mips ABI states that on error a3 CPU register has non zero value and if | 386 // Mips ABI states that on error a3 CPU register has non zero value and if |
353 // there is no error, it should be zero. | 387 // there is no error, it should be zero. |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
385 } | 419 } |
386 | 420 |
387 // Set an error status so it can be used outside of this function | 421 // Set an error status so it can be used outside of this function |
388 *err_ret = err_stat; | 422 *err_ret = err_stat; |
389 | 423 |
390 return ret; | 424 return ret; |
391 } | 425 } |
392 #endif // defined(__mips__) | 426 #endif // defined(__mips__) |
393 | 427 |
394 } // namespace sandbox | 428 } // namespace sandbox |
OLD | NEW |