OLD | NEW |
(Empty) | |
| 1 // Copyright 2014 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/kernel_return_value_helpers.h" |
| 6 #include "sandbox/linux/seccomp-bpf/linux_seccomp.h" |
| 7 |
| 8 namespace sandbox { |
| 9 int ErrnoToKernelRet(int kernel_ret) { |
| 10 #if defined(__mips__) |
| 11 // On MIPS, kernel returns kernel_ret (instead of -kernel_ret) |
| 12 return kernel_ret; |
| 13 #else |
| 14 return -kernel_ret; |
| 15 #endif |
| 16 } |
| 17 |
| 18 void PutValueInUcontext(int ret_val, ucontext_t* ctx) { |
| 19 #if defined(__mips__) |
| 20 // Mips ABI states that on error a3 CPU register should be set to one |
| 21 // and if there is no error, it should be zero. |
| 22 if (ret_val < 0) { |
| 23 // On MIPS, kernel returns errno (instead of -errno) |
| 24 ret_val = -ret_val; |
| 25 SECCOMP_PARM4(ctx) = 1; |
| 26 } else |
| 27 SECCOMP_PARM4(ctx) = 0; |
| 28 #endif |
| 29 SECCOMP_RESULT(ctx) = static_cast<greg_t>(ret_val); |
| 30 } |
| 31 |
| 32 } // namespace sandbox |
OLD | NEW |