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

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..9086e153e1326dc801537c3503353237e8529b48
--- /dev/null
+++ b/sandbox/linux/seccomp-bpf/kernel_return_value_helpers.cc
@@ -0,0 +1,32 @@
+// 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__)
+ // On MIPS, kernel returns kernel_ret (instead of -kernel_ret)
+ 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 should be set to one
+ // and if there is no error, it should be zero.
+ if (ret_val < 0) {
+ // On MIPS, kernel returns errno (instead of -errno)
+ 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