qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: riku.voipio@iki.fi
To: qemu-devel@nongnu.org
Cc: "Wesley W. Terpstra" <terpstra@debian.org>
Subject: [Qemu-devel] [PATCH 12/15] mips: rlimit codes are not the same
Date: Wed, 13 Jul 2011 17:48:51 +0300	[thread overview]
Message-ID: <e22b7015353be824620b1f0f5e32a8575b898a8c.1310568214.git.riku.voipio@linaro.org> (raw)
In-Reply-To: <cover.1310568213.git.riku.voipio@linaro.org>

From: Wesley W. Terpstra <terpstra@debian.org>

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 <terpstra@debian.org>
Signed-off-by: Riku Voipio <riku.voipio@linaro.org>
---
 linux-user/syscall.c      |   45 ++++++++++++++++++++++++++++++++++++++++++---
 linux-user/syscall_defs.h |   34 ++++++++++++++++++++++++++++++++++
 2 files changed, 76 insertions(+), 3 deletions(-)

diff --git a/linux-user/syscall.c b/linux-user/syscall.c
index 4b9e3b8..9eb41a0 100644
--- a/linux-user/syscall.c
+++ b/linux-user/syscall.c
@@ -960,6 +960,44 @@ static inline target_ulong host_to_target_rlim(rlim_t rlim)
     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)
 {
@@ -5570,7 +5608,7 @@ abi_long do_syscall(void *cpu_env, int num, abi_long arg1,
         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))
@@ -5583,7 +5621,7 @@ abi_long do_syscall(void *cpu_env, int num, abi_long arg1,
         break;
     case TARGET_NR_getrlimit:
         {
-            int resource = arg1;
+            int resource = target_to_host_resource(arg1);
             struct target_rlimit *target_rlim;
             struct rlimit rlim;
 
@@ -6892,7 +6930,8 @@ abi_long do_syscall(void *cpu_env, int num, abi_long arg1,
     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 1fdc84d..a117407 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 */
-- 
1.7.4.1

  parent reply	other threads:[~2011-07-13 14:49 UTC|newest]

Thread overview: 16+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2011-07-13 14:48 [Qemu-devel] [PATCH 00/15] v2: pending linux-user patches riku.voipio
2011-07-13 14:48 ` [Qemu-devel] [PATCH 01/15] arm-semi: Provide access to CLI arguments passed through the "-append" option riku.voipio
2011-07-13 14:48 ` [Qemu-devel] [PATCH 02/15] linux-user: Add support for KD...LED ioctls riku.voipio
2011-07-13 14:48 ` [Qemu-devel] [PATCH 03/15] linux-user: Add support for more VT ioctls riku.voipio
2011-07-13 14:48 ` [Qemu-devel] [PATCH 04/15] linux-user: Add support for even more FB ioctls riku.voipio
2011-07-13 14:48 ` [Qemu-devel] [PATCH 05/15] linux-user: Add syscall numbers from kernel 2.6.39.2 riku.voipio
2011-07-13 14:48 ` [Qemu-devel] [PATCH 06/15] linux-user: Implement prlimit64 syscall riku.voipio
2011-07-13 14:48 ` [Qemu-devel] [PATCH 07/15] linux-user/syscall.c: Enforce pselect6 sigset size restrictions riku.voipio
2011-07-13 14:48 ` [Qemu-devel] [PATCH 08/15] mips: sigaltstack args riku.voipio
2011-07-13 14:48 ` [Qemu-devel] [PATCH 09/15] mips: missing syscall returns wrong errno riku.voipio
2011-07-13 14:48 ` [Qemu-devel] [PATCH 10/15] mips: null pointer deref should segfault riku.voipio
2011-07-13 14:48 ` [Qemu-devel] [PATCH 11/15] mips: rlimit incorrectly converts values riku.voipio
2011-07-13 14:48 ` riku.voipio [this message]
2011-07-13 14:48 ` [Qemu-devel] [PATCH 13/15] linux-user: correct syscall 123 on sh4 riku.voipio
2011-07-13 14:48 ` [Qemu-devel] [PATCH 14/15] linux-user: make MIPS and ARM eabi use same argument reordering riku.voipio
2011-07-13 14:48 ` [Qemu-devel] [PATCH 15/15] linux-user/signal.c: Rename s390 target_ucontext fields to fix ia64 riku.voipio

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=e22b7015353be824620b1f0f5e32a8575b898a8c.1310568214.git.riku.voipio@linaro.org \
    --to=riku.voipio@iki.fi \
    --cc=qemu-devel@nongnu.org \
    --cc=terpstra@debian.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).