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

Unified Diff: sandbox/linux/services/kernel_to_errno.h

Issue 260793003: [MIPS] Add seccomp bpf support (Closed) Base URL: https://git.chromium.org/git/chromium/src.git@master
Patch Set: Fix problem with truncation of syscall value in CrashSIGSYS_Handler 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/services/kernel_to_errno.h
diff --git a/sandbox/linux/services/kernel_to_errno.h b/sandbox/linux/services/kernel_to_errno.h
new file mode 100644
index 0000000000000000000000000000000000000000..42f9299f2db2bd77ed0623c3f5b312bab4100b9e
--- /dev/null
+++ b/sandbox/linux/services/kernel_to_errno.h
@@ -0,0 +1,37 @@
+// Copyright 2014 The Chromium Authors. All rights reserved.
jln (very slow on Chromium) 2014/05/16 19:30:17 - Please, add a _unittest.cc file for this with a
nedeljko 2014/05/19 17:37:23 These are pretty basic functions. Since functions
jln (very slow on Chromium) 2014/05/20 01:57:47 What should be tested is what these function do.
nedeljko 2014/05/20 14:36:41 I was thinking to move this (implementation of fun
nedeljko 2014/05/22 17:38:55 Done.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#ifndef SANDBOX_LINUX_SERVICES_KERNEL_TO_ERRNO_H
+#define SANDBOX_LINUX_SERVICES_KERNEL_TO_ERRNO_H
+
+namespace {
jln (very slow on Chromium) 2014/05/16 19:30:17 This should be "namespace sandbox".
nedeljko 2014/05/22 17:38:55 Done.
+
+inline int KernelRetToErrno(int kernel_ret) {
jln (very slow on Chromium) 2014/05/16 19:30:17 In practice I've only seen this used taking an err
nedeljko 2014/05/22 17:38:55 Done.
+#if defined(__mips__)
+ // On MIPS, kernel returns kernel_ret (instead of -kernel_ret)
+ return kernel_ret;
+#else
+ return -kernel_ret;
+#endif
+}
+
+inline int RetValToKernelRet(int ret_val, ucontext_t* ctx) {
jln (very slow on Chromium) 2014/05/16 19:30:17 Please add valid #include for ucontext_t.
jln (very slow on Chromium) 2014/05/16 19:30:17 Let's make this a function that returns void inste
jln (very slow on Chromium) 2014/05/16 21:27:10 Let's have the implementation hidden in a .cc file
nedeljko 2014/05/22 17:38:55 Done.
nedeljko 2014/05/22 17:38:55 Done.
nedeljko 2014/05/22 17:38:55 Done.
+#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;
+ (ctx)->uc_mcontext.gregs[7] = 1;
+ } else
+ (ctx)->uc_mcontext.gregs[7] = 0;
+ return ret_val;
+#else
+ return ret_val;
+#endif
+}
+
+} // namespace
+
+#endif // SANDBOX_LINUX_SERVICES_KERNEL_TO_ERRNO_H

Powered by Google App Engine
This is Rietveld 408576698