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 | |
10 // In order for errno to be converted to the value that kernel returns to | |
11 // indicate an error in syscall, errno needs to be negated on Intel/Arm. On | |
12 // Mips this is not the case since Mips has different mechanism for indicating | |
13 // error. | |
14 int ErrnoToKernelRet(int kernel_ret) { | |
15 #if defined(__mips__) | |
16 return kernel_ret; | |
17 #else | |
18 return -kernel_ret; | |
19 #endif | |
20 } | |
21 | |
22 void PutValueInUcontext(intptr_t ret_val, ucontext_t* ctx) { | |
23 #if defined(__mips__) | |
24 // Mips ABI states that on error a3 CPU register has non zero value and if | |
25 // there is no error, it should be zero. | |
26 if (ret_val < 0) { | |
jln (very slow on Chromium)
2014/06/13 02:47:36
This should be if (retval <= -1 && ret_val >= -409
nedeljko
2014/06/18 13:41:00
Done.
| |
27 // The sign of errno that is returned from the kernel was changed in | |
28 // SandboxSyscall() in case of Mips in order for SandboxSyscall() to | |
jln (very slow on Chromium)
2014/06/13 02:47:36
This code must not have knowledge of the codepath
nedeljko
2014/06/18 13:41:00
Done.
| |
29 // behave the same for all supported architectures. In order to write | |
30 // correct value to return register this sign needs to be changed back. | |
31 ret_val = -ret_val; | |
32 SECCOMP_PARM4(ctx) = 1; | |
33 } else | |
34 SECCOMP_PARM4(ctx) = 0; | |
35 #endif | |
36 SECCOMP_RESULT(ctx) = static_cast<greg_t>(ret_val); | |
37 } | |
38 | |
39 } // namespace sandbox | |
OLD | NEW |