Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(38)

Unified Diff: sandbox/linux/seccomp-bpf/kernel_return_value_helpers.cc

Issue 260793003: [MIPS] Add seccomp bpf support (Closed) Base URL: https://git.chromium.org/git/chromium/src.git@master
Patch Set: Update per code review Created 6 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
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..888bec58b5f169f35efa419bf18c8e66c1c48680
--- /dev/null
+++ b/sandbox/linux/seccomp-bpf/kernel_return_value_helpers.cc
@@ -0,0 +1,39 @@
+// 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 {
+
+// In order for errno to be converted to the value that kernel returns to
+// indicate an error in syscall, errno needs to be negated on Intel/Arm. On
+// Mips this is not the case since Mips has different mechanism for indicating
+// error.
+int ErrnoToKernelRet(int kernel_ret) {
+#if defined(__mips__)
+ return kernel_ret;
+#else
+ return -kernel_ret;
+#endif
+}
+
+void PutValueInUcontext(intptr_t 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/13 02:47:36 This should be if (retval <= -1 && ret_val >= -409
nedeljko 2014/06/18 13:41:00 Done.
+ // The sign of errno that is returned from the kernel was changed in
+ // 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.
+ // 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

Powered by Google App Engine
This is Rietveld 408576698