qemu-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Qemu-devel] [PATCH 5/6] mips: rlimit codes are not the same


From: Wesley W. Terpstra
Subject: [Qemu-devel] [PATCH 5/6] mips: rlimit codes are not the same
Date: Fri, 8 Jul 2011 15:06:09 +0200

The codes for get/setrlimit differ between linux target platforms.
This patch adds conversion.
This is important else programs (rsyslog, python, ...) can go into a
near infinite loop trying to close all the file descriptors from 0 to
-1.

Signed-off-by: Wesley W. Terpstra <address@hidden>
---

diff --git a/linux-user/syscall.c b/linux-user/syscall.c
index fed7a8f..2011e66 100644
--- a/linux-user/syscall.c
+++ b/linux-user/syscall.c
@@ -945,6 +945,44 @@
     return result;
 }

+static inline int target_to_host_resource(int code)
+{
+    switch (code) {
+    case TARGET_RLIMIT_AS:
+        return RLIMIT_AS;
+    case TARGET_RLIMIT_CORE:
+        return RLIMIT_CORE;
+    case TARGET_RLIMIT_CPU:
+        return RLIMIT_CPU;
+    case TARGET_RLIMIT_DATA:
+        return RLIMIT_DATA;
+    case TARGET_RLIMIT_FSIZE:
+        return RLIMIT_FSIZE;
+    case TARGET_RLIMIT_LOCKS:
+        return RLIMIT_LOCKS;
+    case TARGET_RLIMIT_MEMLOCK:
+        return RLIMIT_MEMLOCK;
+    case TARGET_RLIMIT_MSGQUEUE:
+        return RLIMIT_MSGQUEUE;
+    case TARGET_RLIMIT_NICE:
+        return RLIMIT_NICE;
+    case TARGET_RLIMIT_NOFILE:
+        return RLIMIT_NOFILE;
+    case TARGET_RLIMIT_NPROC:
+        return RLIMIT_NPROC;
+    case TARGET_RLIMIT_RSS:
+        return RLIMIT_RSS;
+    case TARGET_RLIMIT_RTPRIO:
+        return RLIMIT_RTPRIO;
+    case TARGET_RLIMIT_SIGPENDING:
+        return RLIMIT_SIGPENDING;
+    case TARGET_RLIMIT_STACK:
+        return RLIMIT_STACK;
+    default:
+        return code;
+    }
+}
+
 static inline abi_long copy_from_user_timeval(struct timeval *tv,
                                               abi_ulong target_tv_addr)
 {
@@ -5555,7 +5593,7 @@
         break;
     case TARGET_NR_setrlimit:
         {
-            int resource = arg1;
+            int resource = target_to_host_resource(arg1);
             struct target_rlimit *target_rlim;
             struct rlimit rlim;
             if (!lock_user_struct(VERIFY_READ, target_rlim, arg2, 1))
@@ -5568,7 +5606,7 @@
         break;
     case TARGET_NR_getrlimit:
         {
-            int resource = arg1;
+            int resource = target_to_host_resource(arg1);
             struct target_rlimit *target_rlim;
             struct rlimit rlim;

@@ -6872,7 +6910,8 @@
     case TARGET_NR_ugetrlimit:
     {
        struct rlimit rlim;
-       ret = get_errno(getrlimit(arg1, &rlim));
+       int resource = target_to_host_resource(arg1);
+       ret = get_errno(getrlimit(resource, &rlim));
        if (!is_error(ret)) {
            struct target_rlimit *target_rlim;
             if (!lock_user_struct(VERIFY_WRITE, target_rlim, arg2, 0))
diff --git a/linux-user/syscall_defs.h b/linux-user/syscall_defs.h
index 04c268d..6ec9c31 100644
--- a/linux-user/syscall_defs.h
+++ b/linux-user/syscall_defs.h
@@ -693,6 +693,40 @@ struct target_rlimit {
 #define TARGET_RLIM_INFINITY   ((target_ulong)~0UL)
 #endif

+#if defined(TARGET_MIPS)
+#define TARGET_RLIMIT_CPU              0
+#define TARGET_RLIMIT_FSIZE            1
+#define TARGET_RLIMIT_DATA             2
+#define TARGET_RLIMIT_STACK            3
+#define TARGET_RLIMIT_CORE             4
+#define TARGET_RLIMIT_RSS              7
+#define TARGET_RLIMIT_NPROC            8
+#define TARGET_RLIMIT_NOFILE           5
+#define TARGET_RLIMIT_MEMLOCK          9
+#define TARGET_RLIMIT_AS               6
+#define TARGET_RLIMIT_LOCKS            10
+#define TARGET_RLIMIT_SIGPENDING       11
+#define TARGET_RLIMIT_MSGQUEUE         12
+#define TARGET_RLIMIT_NICE             13
+#define TARGET_RLIMIT_RTPRIO           14
+#else
+#define TARGET_RLIMIT_CPU              0
+#define TARGET_RLIMIT_FSIZE            1
+#define TARGET_RLIMIT_DATA             2
+#define TARGET_RLIMIT_STACK            3
+#define TARGET_RLIMIT_CORE             4
+#define TARGET_RLIMIT_RSS              5
+#define TARGET_RLIMIT_NPROC            6
+#define TARGET_RLIMIT_NOFILE           7
+#define TARGET_RLIMIT_MEMLOCK          8
+#define TARGET_RLIMIT_AS               9
+#define TARGET_RLIMIT_LOCKS            10
+#define TARGET_RLIMIT_SIGPENDING       11
+#define TARGET_RLIMIT_MSGQUEUE         12
+#define TARGET_RLIMIT_NICE             13
+#define TARGET_RLIMIT_RTPRIO           14
+#endif
+
 struct target_pollfd {
     int fd;           /* file descriptor */
     short events;     /* requested events */

Attachment: 04-mips-rlimit-codes.patch
Description: Text Data


reply via email to

[Prev in Thread] Current Thread [Next in Thread]