Chromium Code Reviews| Index: sandbox/linux/seccomp-bpf/kernel_return_value_helpers.cc |
| diff --git a/sandbox/linux/seccomp-bpf/kernel_return_value_helpers.cc b/sandbox/linux/seccomp-bpf/kernel_return_value_helpers.cc |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..db4d0f8f47be7718d4e744a5872e76e172f65aa5 |
| --- /dev/null |
| +++ b/sandbox/linux/seccomp-bpf/kernel_return_value_helpers.cc |
| @@ -0,0 +1,35 @@ |
| +// Copyright 2014 The Chromium Authors. All rights reserved. |
| +// Use of this source code is governed by a BSD-style license that can be |
| +// found in the LICENSE file. |
| + |
| +#include "sandbox/linux/seccomp-bpf/kernel_return_value_helpers.h" |
| +#include "sandbox/linux/seccomp-bpf/linux_seccomp.h" |
| + |
| +namespace sandbox { |
| + |
| +int ErrnoToKernelRet(int kernel_ret) { |
| +#if defined(__mips__) |
| + return kernel_ret; |
| +#else |
| + return -kernel_ret; |
| +#endif |
| +} |
| + |
| +void PutValueInUcontext(int ret_val, ucontext_t* ctx) { |
| +#if defined(__mips__) |
| + // Mips ABI states that on error a3 CPU register has non zero value and if |
| + // there is no error, it should be zero. |
| + if (ret_val < 0) { |
|
jln (very slow on Chromium)
2014/06/03 01:00:33
This can't work for instance with mmap(2). mmap()
|
| + // The sign of errno that is returned from the kernel was changed in |
| + // SandboxSyscall() in case of Mips in order for SandboxSyscall() to |
| + // behave the same for all supported architectures. In order to write |
| + // correct value to return register this sign needs to be changed back. |
| + ret_val = -ret_val; |
| + SECCOMP_PARM4(ctx) = 1; |
| + } else |
| + SECCOMP_PARM4(ctx) = 0; |
| +#endif |
| + SECCOMP_RESULT(ctx) = static_cast<greg_t>(ret_val); |
| +} |
| + |
| +} // namespace sandbox |