Skip to contentSkip to conversation

Added posix message queue syscalls except mq_notify

Qemu-devel In review Lionel Landwerlin 3 participants 13 messages Dec 13, 2008 – Jan 12, 2009

lore
Share & tools
lore
#0 lore raw
Quoted 1 line

From 57a528de47a737e59f391ff7df2f87367b40529e Mon Sep 17 00:00:00 2001

From: Lionel Landwerlin <[email protected]>
Date: Mon, 1 Dec 2008 02:42:24 +0100
Subject: [PATCH] Added posix message queue syscalls except mq_notify

---
 linux-user/syscall.c |  151 ++++++++++++++++++++++++++++++++++++++++++++------
 1 files changed, 117 insertions(+), 0 deletions(-)
linux-user/syscall.c +117 -0
index 4065917..c4dd38a 100644
@@ -28,6 +28,7 @@
 #include <fcntl.h>
 #include <time.h>
 #include <limits.h>
+#include <mqueue.h>
 #include <sys/types.h>
 #include <sys/ipc.h>
 #include <sys/msg.h>
@@ -629,6 +630,43 @@ static inline abi_long copy_to_user_timeval(abi_ulong target_tv_addr,
     return 0;
 }
 
+static inline abi_long copy_from_user_mq_attr(struct mq_attr *attr,
+                                              abi_ulong target_mq_attr_addr)
+{
+    struct mq_attr *target_mq_attr;
+
+    if (!lock_user_struct(VERIFY_READ, target_mq_attr,
+                          target_mq_attr_addr, 1))
+        return -TARGET_EFAULT;
+
+    __get_user(attr->mq_flags, &target_mq_attr->mq_flags);
+    __get_user(attr->mq_maxmsg, &target_mq_attr->mq_maxmsg);
+    __get_user(attr->mq_msgsize, &target_mq_attr->mq_msgsize);
+    __get_user(attr->mq_curmsgs, &target_mq_attr->mq_curmsgs);
+
+    unlock_user_struct(target_mq_attr, target_mq_attr_addr, 0);
+
+    return 0;
+}
+
+static inline abi_long copy_to_user_mq_attr(abi_ulong target_mq_attr_addr,
+                                            const struct mq_attr *attr)
+{
+    struct mq_attr *target_mq_attr;
+
+    if (!lock_user_struct(VERIFY_WRITE, target_mq_attr,
+                          target_mq_attr_addr, 0))
+        return -TARGET_EFAULT;
+
+    __put_user(attr->mq_flags, &target_mq_attr->mq_flags);
+    __put_user(attr->mq_maxmsg, &target_mq_attr->mq_maxmsg);
+    __put_user(attr->mq_msgsize, &target_mq_attr->mq_msgsize);
+    __put_user(attr->mq_curmsgs, &target_mq_attr->mq_curmsgs);
+
+    unlock_user_struct(target_mq_attr, target_mq_attr_addr, 1);
+
+    return 0;
+}
 
 /* do_select() must return target values and target errnos. */
 static abi_long do_select(int n,
@@ -6033,6 +6071,85 @@ abi_long do_syscall(void *cpu_env, int num, abi_long arg1,
         break;
 #endif
 
+#ifdef TARGET_NR_mq_open
+    case TARGET_NR_mq_open:
+    {
+        struct mq_attr posix_mq_attr;
+
+        p = lock_user_string(arg1 - 1);
+        if (arg4 != 0)
+            copy_from_user_mq_attr (&posix_mq_attr, arg4);
+        ret = get_errno(mq_open(p, arg2, arg3, &posix_mq_attr));
+        unlock_user (p, arg1, 0);
+        break;
+    }
+
+    case TARGET_NR_mq_unlink:
+        p = lock_user_string(arg1 - 1);
+        ret = get_errno(mq_unlink(p));
+        unlock_user (p, arg1, 0);
+        break;
+
+    case TARGET_NR_mq_timedsend:
+    {
+        struct timespec ts;
+
+        if (arg5 != 0) {
+            p = lock_user (VERIFY_READ, arg2, arg3, 1);
+            target_to_host_timespec(&ts, arg5);
+            ret = get_errno(mq_timedsend(arg1, p, arg3, arg4, &ts));
+            host_to_target_timespec(arg5, &ts);
+            unlock_user (p, arg2, arg3);
+        } else {
+            p = lock_user (VERIFY_READ, arg2, arg3, 1);
+            ret = get_errno(mq_send(arg1, p, arg3, arg4));
+            unlock_user (p, arg2, arg3);
+        }
+        break;
+    }
+
+    case TARGET_NR_mq_timedreceive:
+    {
+        struct timespec ts;
+        unsigned int prio;
+
+        if (arg5 != 0) {
+            p = lock_user (VERIFY_READ, arg2, arg3, 1);
+            target_to_host_timespec(&ts, arg5);
+            ret = get_errno(mq_timedreceive(arg1, p, arg3, &prio, &ts));
+            host_to_target_timespec(arg5, &ts);
+            unlock_user (p, arg2, arg3);
+        } else {
+            p = lock_user (VERIFY_READ, arg2, arg3, 1);
+            ret = get_errno(mq_receive(arg1, p, arg3, &prio));
+            unlock_user (p, arg2, arg3);
+        }
+        if (arg4 != 0)
+            put_user_u32(prio, arg4);
+        break;
+    }
+
+    /* Not implemented for now... */
+/*     case TARGET_NR_mq_notify: */
+/*         break; */
+
+    case TARGET_NR_mq_getsetattr:
+    {
+        struct mq_attr posix_mq_attr_in, posix_mq_attr_out;
+
+        if (arg3 != 0) {
+            ret = mq_getattr(arg1, &posix_mq_attr_out);
+            copy_to_user_mq_attr(arg3, &posix_mq_attr_out);
+        }
+        if (arg2 != 0) {
+            copy_from_user_mq_attr(&posix_mq_attr_in, arg2);
+            ret |= mq_setattr(arg1, &posix_mq_attr_in, &posix_mq_attr_out);
+        }
+
+        break;
+    }
+#endif
+
     default:
     unimplemented:
         gemu_log("qemu: Unsupported syscall: %d\n", num);
Signature · 1 line
1.5.6.5
#1 lore raw
Quoted 24 lines · Lionel Landwerlin
Quoted 1 line

From 57a528de47a737e59f391ff7df2f87367b40529e Mon Sep 17 00:00:00 2001

From: Lionel Landwerlin <[email protected]>
Date: Mon, 1 Dec 2008 02:42:24 +0100
Subject: [PATCH] Added posix message queue syscalls except mq_notify

---
 linux-user/syscall.c |  151 ++++++++++++++++++++++++++++++++++++++++++++------
 1 files changed, 117 insertions(+), 0 deletions(-)
linux-user/syscall.c +1 -0
index 4065917..c4dd38a 100644
@@ -28,6 +28,7 @@
 #include <fcntl.h>
 #include <time.h>
 #include <limits.h>
+#include <mqueue.h>
 #include <sys/types.h>
 #include <sys/ipc.h>
 #include <sys/msg.h>

linux-user/syscall.c static inline abi_long copy_to_user_timeval(abi_ulong target_tv_addr, · line 636

Quoted 7 lines
linux-user/syscall.c +4 -0
@@ -629,6 +630,43 @@ static inline abi_long copy_to_user_timeval(abi_ulong target_tv_addr,
     return 0;
 }
 
+static inline abi_long copy_from_user_mq_attr(struct mq_attr *attr,
+                                              abi_ulong target_mq_attr_addr)
+{
+    struct mq_attr *target_mq_attr;

It's wrong. struct mq_attr has long int fields, so you should define struct target_mq_attr using abi_long.

Quoted 37 lines
linux-user/syscall.c +33 -0
+
+    if (!lock_user_struct(VERIFY_READ, target_mq_attr,
+                          target_mq_attr_addr, 1))
+        return -TARGET_EFAULT;
+
+    __get_user(attr->mq_flags, &target_mq_attr->mq_flags);
+    __get_user(attr->mq_maxmsg, &target_mq_attr->mq_maxmsg);
+    __get_user(attr->mq_msgsize, &target_mq_attr->mq_msgsize);
+    __get_user(attr->mq_curmsgs, &target_mq_attr->mq_curmsgs);
+
+    unlock_user_struct(target_mq_attr, target_mq_attr_addr, 0);
+
+    return 0;
+}
+
+static inline abi_long copy_to_user_mq_attr(abi_ulong target_mq_attr_addr,
+                                            const struct mq_attr *attr)
+{
+    struct mq_attr *target_mq_attr;
+
+    if (!lock_user_struct(VERIFY_WRITE, target_mq_attr,
+                          target_mq_attr_addr, 0))
+        return -TARGET_EFAULT;
+
+    __put_user(attr->mq_flags, &target_mq_attr->mq_flags);
+    __put_user(attr->mq_maxmsg, &target_mq_attr->mq_maxmsg);
+    __put_user(attr->mq_msgsize, &target_mq_attr->mq_msgsize);
+    __put_user(attr->mq_curmsgs, &target_mq_attr->mq_curmsgs);
+
+    unlock_user_struct(target_mq_attr, target_mq_attr_addr, 1);
+
+    return 0;
+}
 
 /* do_select() must return target values and target errnos. */
 static abi_long do_select(int n,

linux-user/syscall.c abi_long do_syscall(void *cpu_env, int num, abi_long arg1, · line 6079

Quoted 9 lines
linux-user/syscall.c +6 -0
@@ -6033,6 +6071,85 @@ abi_long do_syscall(void *cpu_env, int num, abi_long arg1,
         break;
 #endif
 
+#ifdef TARGET_NR_mq_open
+    case TARGET_NR_mq_open:
+    {
+        struct mq_attr posix_mq_attr;
+
+        p = lock_user_string(arg1 - 1);

Why - 1?

linux-user/syscall.c abi_long do_syscall(void *cpu_env, int num, abi_long arg1, · line 6088

Quoted 9 lines
linux-user/syscall.c +9 -0
+        if (arg4 != 0)
+            copy_from_user_mq_attr (&posix_mq_attr, arg4);
+        ret = get_errno(mq_open(p, arg2, arg3, &posix_mq_attr));
+        unlock_user (p, arg1, 0);
+        break;
+    }
+
+    case TARGET_NR_mq_unlink:
+        p = lock_user_string(arg1 - 1);

?

Quoted 9 lines
linux-user/syscall.c +9 -0
+        ret = get_errno(mq_unlink(p));
+        unlock_user (p, arg1, 0);
+        break;
+
+    case TARGET_NR_mq_timedsend:
+    {
+        struct timespec ts;
+
+        if (arg5 != 0) {

linux-user/syscall.c abi_long do_syscall(void *cpu_env, int num, abi_long arg1, · line 6107

Quoted 10 lines
linux-user/syscall.c +10 -0
+            p = lock_user (VERIFY_READ, arg2, arg3, 1);
+            target_to_host_timespec(&ts, arg5);
+            ret = get_errno(mq_timedsend(arg1, p, arg3, arg4, &ts));
+            host_to_target_timespec(arg5, &ts);
+            unlock_user (p, arg2, arg3);
+        } else {
+            p = lock_user (VERIFY_READ, arg2, arg3, 1);
+            ret = get_errno(mq_send(arg1, p, arg3, arg4));
+            unlock_user (p, arg2, arg3);
+        }

We can lock and unlock outside of if startament, I think.

Quoted 9 lines
linux-user/syscall.c +9 -0
+        break;
+    }
+
+    case TARGET_NR_mq_timedreceive:
+    {
+        struct timespec ts;
+        unsigned int prio;
+
+        if (arg5 != 0) {

linux-user/syscall.c abi_long do_syscall(void *cpu_env, int num, abi_long arg1, · line 6126

Quoted 10 lines
linux-user/syscall.c +10 -0
+            p = lock_user (VERIFY_READ, arg2, arg3, 1);
+            target_to_host_timespec(&ts, arg5);
+            ret = get_errno(mq_timedreceive(arg1, p, arg3, &prio, &ts));
+            host_to_target_timespec(arg5, &ts);
+            unlock_user (p, arg2, arg3);
+        } else {
+            p = lock_user (VERIFY_READ, arg2, arg3, 1);
+            ret = get_errno(mq_receive(arg1, p, arg3, &prio));
+            unlock_user (p, arg2, arg3);
+        }

The same about locking.

linux-user/syscall.c abi_long do_syscall(void *cpu_env, int num, abi_long arg1, · line 6134

Quoted 8 lines
linux-user/syscall.c +8 -0
+        if (arg4 != 0)
+            put_user_u32(prio, arg4);
+        break;
+    }
+
+    /* Not implemented for now... */
+/*     case TARGET_NR_mq_notify: */
+/*         break; */

Is there any problem with this syscall?

Quoted 23 lines
linux-user/syscall.c +18 -0
+
+    case TARGET_NR_mq_getsetattr:
+    {
+        struct mq_attr posix_mq_attr_in, posix_mq_attr_out;
+
+        if (arg3 != 0) {
+            ret = mq_getattr(arg1, &posix_mq_attr_out);
+            copy_to_user_mq_attr(arg3, &posix_mq_attr_out);
+        }
+        if (arg2 != 0) {
+            copy_from_user_mq_attr(&posix_mq_attr_in, arg2);
+            ret |= mq_setattr(arg1, &posix_mq_attr_in, &posix_mq_attr_out);
+        }
+
+        break;
+    }
+#endif
+
     default:
     unimplemented:
         gemu_log("qemu: Unsupported syscall: %d\n", num);
Signature · 1 line
1.5.6.5
Signature · 3 lines
Regards,  Kirill A. Shutemov
 + Belarus, Minsk
 + ALT Linux Team, http://www.altlinux.org/
#2 lore raw
Quoted 28 lines · Kirill A. Shutemov
Quoted 27 lines · Lionel Landwerlin
Quoted 1 line

From 57a528de47a737e59f391ff7df2f87367b40529e Mon Sep 17 00:00:00 2001

From: Lionel Landwerlin <[email protected]>
Date: Mon, 1 Dec 2008 02:42:24 +0100
Subject: [PATCH] Added posix message queue syscalls except mq_notify

---
 linux-user/syscall.c |  151 ++++++++++++++++++++++++++++++++++++++++++++------
 1 files changed, 117 insertions(+), 0 deletions(-)
linux-user/syscall.c +1 -0
index 4065917..c4dd38a 100644
@@ -28,6 +28,7 @@
 #include <fcntl.h>
 #include <time.h>
 #include <limits.h>
+#include <mqueue.h>
 #include <sys/types.h>
 #include <sys/ipc.h>
 #include <sys/msg.h>
@@ -629,6 +630,43 @@ static inline abi_long copy_to_user_timeval(abi_ulong target_tv_addr,
     return 0;
 }
 
Quoted 7 lines

linux-user/syscall.c static inline abi_long copy_to_user_timeval(abi_ulong target_tv_addr, · line 636

Quoted 4 lines
linux-user/syscall.c +4 -0
+static inline abi_long copy_from_user_mq_attr(struct mq_attr *attr,
+                                              abi_ulong target_mq_attr_addr)
+{
+    struct mq_attr *target_mq_attr;

It's wrong. struct mq_attr has long int fields, so you should define struct target_mq_attr using abi_long.

I will do that, thx.

Quoted 41 lines
Quoted 41 lines
linux-user/syscall.c +33 -0
+
+    if (!lock_user_struct(VERIFY_READ, target_mq_attr,
+                          target_mq_attr_addr, 1))
+        return -TARGET_EFAULT;
+
+    __get_user(attr->mq_flags, &target_mq_attr->mq_flags);
+    __get_user(attr->mq_maxmsg, &target_mq_attr->mq_maxmsg);
+    __get_user(attr->mq_msgsize, &target_mq_attr->mq_msgsize);
+    __get_user(attr->mq_curmsgs, &target_mq_attr->mq_curmsgs);
+
+    unlock_user_struct(target_mq_attr, target_mq_attr_addr, 0);
+
+    return 0;
+}
+
+static inline abi_long copy_to_user_mq_attr(abi_ulong target_mq_attr_addr,
+                                            const struct mq_attr *attr)
+{
+    struct mq_attr *target_mq_attr;
+
+    if (!lock_user_struct(VERIFY_WRITE, target_mq_attr,
+                          target_mq_attr_addr, 0))
+        return -TARGET_EFAULT;
+
+    __put_user(attr->mq_flags, &target_mq_attr->mq_flags);
+    __put_user(attr->mq_maxmsg, &target_mq_attr->mq_maxmsg);
+    __put_user(attr->mq_msgsize, &target_mq_attr->mq_msgsize);
+    __put_user(attr->mq_curmsgs, &target_mq_attr->mq_curmsgs);
+
+    unlock_user_struct(target_mq_attr, target_mq_attr_addr, 1);
+
+    return 0;
+}
 
 /* do_select() must return target values and target errnos. */
 static abi_long do_select(int n,
@@ -6033,6 +6071,85 @@ abi_long do_syscall(void *cpu_env, int num, abi_long arg1,
         break;
 #endif
 
Quoted 8 lines

linux-user/syscall.c abi_long do_syscall(void *cpu_env, int num, abi_long arg1, · line 6079

Quoted 6 lines
linux-user/syscall.c +6 -0
+#ifdef TARGET_NR_mq_open
+    case TARGET_NR_mq_open:
+    {
+        struct mq_attr posix_mq_attr;
+
+        p = lock_user_string(arg1 - 1);

Why - 1?

Look at glibc/uclibc implementation, the string argument is (str + 1).

Quoted 11 lines

linux-user/syscall.c abi_long do_syscall(void *cpu_env, int num, abi_long arg1, · line 6088

Quoted 10 lines
linux-user/syscall.c +9 -0
+        if (arg4 != 0)
+            copy_from_user_mq_attr (&posix_mq_attr, arg4);
+        ret = get_errno(mq_open(p, arg2, arg3, &posix_mq_attr));
+        unlock_user (p, arg1, 0);
+        break;
+    }
+
+    case TARGET_NR_mq_unlink:
+        p = lock_user_string(arg1 - 1);
Quoted 1 line

?

Same thing.

Quoted 14 lines
Quoted 14 lines
linux-user/syscall.c +13 -0
+        ret = get_errno(mq_unlink(p));
+        unlock_user (p, arg1, 0);
+        break;
+
+    case TARGET_NR_mq_timedsend:
+    {
+        struct timespec ts;
+
+        if (arg5 != 0) {
+            p = lock_user (VERIFY_READ, arg2, arg3, 1);
+            target_to_host_timespec(&ts, arg5);
+            ret = get_errno(mq_timedsend(arg1, p, arg3, arg4, &ts));
+            host_to_target_timespec(arg5, &ts);
Quoted 8 lines

linux-user/syscall.c abi_long do_syscall(void *cpu_env, int num, abi_long arg1, · line 6107

Quoted 6 lines
linux-user/syscall.c +6 -0
+            unlock_user (p, arg2, arg3);
+        } else {
+            p = lock_user (VERIFY_READ, arg2, arg3, 1);
+            ret = get_errno(mq_send(arg1, p, arg3, arg4));
+            unlock_user (p, arg2, arg3);
+        }

We can lock and unlock outside of if startament, I think.

Right.

Quoted 23 lines
Quoted 10 lines
linux-user/syscall.c +9 -0
+        break;
+    }
+
+    case TARGET_NR_mq_timedreceive:
+    {
+        struct timespec ts;
+        unsigned int prio;
+
+        if (arg5 != 0) {

linux-user/syscall.c abi_long do_syscall(void *cpu_env, int num, abi_long arg1, · line 6126

Quoted 10 lines
linux-user/syscall.c +10 -0
+            p = lock_user (VERIFY_READ, arg2, arg3, 1);
+            target_to_host_timespec(&ts, arg5);
+            ret = get_errno(mq_timedreceive(arg1, p, arg3, &prio, &ts));
+            host_to_target_timespec(arg5, &ts);
+            unlock_user (p, arg2, arg3);
+        } else {
+            p = lock_user (VERIFY_READ, arg2, arg3, 1);
+            ret = get_errno(mq_receive(arg1, p, arg3, &prio));
+            unlock_user (p, arg2, arg3);
+        }

The same about locking.

Quoted 10 lines

linux-user/syscall.c abi_long do_syscall(void *cpu_env, int num, abi_long arg1, · line 6134

Quoted 8 lines
linux-user/syscall.c +8 -0
+        if (arg4 != 0)
+            put_user_u32(prio, arg4);
+        break;
+    }
+
+    /* Not implemented for now... */
+/*     case TARGET_NR_mq_notify: */
+/*         break; */

Is there any problem with this syscall?

This syscall is a little bit more complicated. The implementation would be a kind of signal handler.

Quoted 24 lines
Quoted 24 lines
linux-user/syscall.c +18 -0
+
+    case TARGET_NR_mq_getsetattr:
+    {
+        struct mq_attr posix_mq_attr_in, posix_mq_attr_out;
+
+        if (arg3 != 0) {
+            ret = mq_getattr(arg1, &posix_mq_attr_out);
+            copy_to_user_mq_attr(arg3, &posix_mq_attr_out);
+        }
+        if (arg2 != 0) {
+            copy_from_user_mq_attr(&posix_mq_attr_in, arg2);
+            ret |= mq_setattr(arg1, &posix_mq_attr_in, &posix_mq_attr_out);
+        }
+
+        break;
+    }
+#endif
+
     default:
     unimplemented:
         gemu_log("qemu: Unsupported syscall: %d\n", num);
Signature · 1 line
1.5.6.5
#3 lore raw
Quoted 5 lines · Lionel Landwerlin
Quoted 3 lines
Quoted 1 line

+ p = lock_user_string(arg1 - 1);

Why - 1?

Look at glibc/uclibc implementation, the string argument is (str + 1).

Hm.. Do you have any explanation why glibc/uclibc do so?

Signature · 3 lines
Regards,  Kirill A. Shutemov
 + Belarus, Minsk
 + ALT Linux Team, http://www.altlinux.org/
#4 lore raw
Quoted 9 lines · Kirill A. Shutemov
Quoted 5 lines · Lionel Landwerlin
Quoted 3 lines
Quoted 1 line

+ p = lock_user_string(arg1 - 1);

Why - 1?

Look at glibc/uclibc implementation, the string argument is (str + 1).

Hm.. Do you have any explanation why glibc/uclibc do so?

No idea... but you can't create directory in mqueue filesystem on Linux, that's maybe why it's not useful to give a / as everything is at root level.

Signature · 3 lines
Lione Landwerlin                                         

O p e n W i d e                    14, rue Gaillon 75002 Paris
#5 lore raw
In reply to Kirill A. Shutemov
Quoted 1 line · Kirill A. Shutemov

On Sat, Dec 13, 2008 at 01:39:27PM +0100, Lionel Landwerlin wrote:

Here is a second version of my patch for mq_open, mq_getsetattr, mq_timedsend, mq_timedreceive and mq_unlink syscalls.

Quoted 1 line

From 2aaa1d66232da3bee0fcdac93bbab09f12ce4b19 Mon Sep 17 00:00:00 2001

From: Lionel Landwerlin <[email protected]>
Date: Mon, 1 Dec 2008 02:42:24 +0100
Subject: [PATCH] Added posix message queue syscalls except mq_notify

---
 linux-user/syscall.c      |  147 +++++++++++++++++++++++++++++++++++++++-----
 linux-user/syscall_defs.h |    9 +++-
 2 files changed, 138 insertions(+), 18 deletions(-)
linux-user/syscall.c +113 -0
index 73427ab..39f26b5 100644
@@ -28,6 +28,7 @@
 #include <fcntl.h>
 #include <time.h>
 #include <limits.h>
+#include <mqueue.h>
 #include <sys/types.h>
 #include <sys/ipc.h>
 #include <sys/msg.h>
@@ -629,6 +630,43 @@ static inline abi_long copy_to_user_timeval(abi_ulong target_tv_addr,
     return 0;
 }
 
+static inline abi_long copy_from_user_mq_attr(struct mq_attr *attr,
+                                              abi_ulong target_mq_attr_addr)
+{
+    struct target_mq_attr *target_mq_attr;
+
+    if (!lock_user_struct(VERIFY_READ, target_mq_attr,
+                          target_mq_attr_addr, 1))
+        return -TARGET_EFAULT;
+
+    __get_user(attr->mq_flags, &target_mq_attr->mq_flags);
+    __get_user(attr->mq_maxmsg, &target_mq_attr->mq_maxmsg);
+    __get_user(attr->mq_msgsize, &target_mq_attr->mq_msgsize);
+    __get_user(attr->mq_curmsgs, &target_mq_attr->mq_curmsgs);
+
+    unlock_user_struct(target_mq_attr, target_mq_attr_addr, 0);
+
+    return 0;
+}
+
+static inline abi_long copy_to_user_mq_attr(abi_ulong target_mq_attr_addr,
+                                            const struct mq_attr *attr)
+{
+    struct target_mq_attr *target_mq_attr;
+
+    if (!lock_user_struct(VERIFY_WRITE, target_mq_attr,
+                          target_mq_attr_addr, 0))
+        return -TARGET_EFAULT;
+
+    __put_user(attr->mq_flags, &target_mq_attr->mq_flags);
+    __put_user(attr->mq_maxmsg, &target_mq_attr->mq_maxmsg);
+    __put_user(attr->mq_msgsize, &target_mq_attr->mq_msgsize);
+    __put_user(attr->mq_curmsgs, &target_mq_attr->mq_curmsgs);
+
+    unlock_user_struct(target_mq_attr, target_mq_attr_addr, 1);
+
+    return 0;
+}
 
 /* do_select() must return target values and target errnos. */
 static abi_long do_select(int n,
@@ -6035,6 +6073,81 @@ abi_long do_syscall(void *cpu_env, int num, abi_long arg1,
         break;
 #endif
 
+#ifdef TARGET_NR_mq_open
+    case TARGET_NR_mq_open:
+    {
+        struct mq_attr posix_mq_attr;
+
+        p = lock_user_string(arg1 - 1);
+        if (arg4 != 0)
+            copy_from_user_mq_attr (&posix_mq_attr, arg4);
+        ret = get_errno(mq_open(p, arg2, arg3, &posix_mq_attr));
+        unlock_user (p, arg1, 0);
+        break;
+    }
+
+    case TARGET_NR_mq_unlink:
+        p = lock_user_string(arg1 - 1);
+        ret = get_errno(mq_unlink(p));
+        unlock_user (p, arg1, 0);
+        break;
+
+    case TARGET_NR_mq_timedsend:
+    {
+        struct timespec ts;
+
+        p = lock_user (VERIFY_READ, arg2, arg3, 1);
+        if (arg5 != 0) {
+            target_to_host_timespec(&ts, arg5);
+            ret = get_errno(mq_timedsend(arg1, p, arg3, arg4, &ts));
+            host_to_target_timespec(arg5, &ts);
+        }
+        else
+            ret = get_errno(mq_send(arg1, p, arg3, arg4));
+        unlock_user (p, arg2, arg3);
+        break;
+    }
+
+    case TARGET_NR_mq_timedreceive:
+    {
+        struct timespec ts;
+        unsigned int prio;
+
+        p = lock_user (VERIFY_READ, arg2, arg3, 1);
+        if (arg5 != 0) {
+            target_to_host_timespec(&ts, arg5);
+            ret = get_errno(mq_timedreceive(arg1, p, arg3, &prio, &ts));
+            host_to_target_timespec(arg5, &ts);
+        }
+        else
+            ret = get_errno(mq_receive(arg1, p, arg3, &prio));
+        unlock_user (p, arg2, arg3);
+        if (arg4 != 0)
+            put_user_u32(prio, arg4);
+        break;
+    }
+
+    /* Not implemented for now... */
+/*     case TARGET_NR_mq_notify: */
+/*         break; */
+
+    case TARGET_NR_mq_getsetattr:
+    {
+        struct mq_attr posix_mq_attr_in, posix_mq_attr_out;
+
+        if (arg3 != 0) {
+            ret = mq_getattr(arg1, &posix_mq_attr_out);
+            copy_to_user_mq_attr(arg3, &posix_mq_attr_out);
+        }
+        if (arg2 != 0) {
+            copy_from_user_mq_attr(&posix_mq_attr_in, arg2);
+            ret |= mq_setattr(arg1, &posix_mq_attr_in, &posix_mq_attr_out);
+        }
+
+        break;
+    }
+#endif
+
     default:
     unimplemented:
         gemu_log("qemu: Unsupported syscall: %d\n", num);
linux-user/syscall_defs.h +7 -0
index 86c9d82..728fedb 100644
@@ -1997,6 +1997,13 @@ struct linux_dirent64 {
     char            d_name[256];
 };
 
+struct target_mq_attr {
+    abi_long mq_flags;
+    abi_long mq_maxmsg;
+    abi_long mq_msgsize;
+    abi_long mq_curmsgs;
+};
+
 #include "socket.h"
 
 #include "errno_defs.h"
Signature · 1 line
1.5.6.5
Reviewed-by
#6 lore raw
Quoted 11 lines · Lionel Landwerlin
Quoted 1 line · Kirill A. Shutemov

On Sat, Dec 13, 2008 at 01:39:27PM +0100, Lionel Landwerlin wrote:

Here is a second version of my patch for mq_open, mq_getsetattr, mq_timedsend, mq_timedreceive and mq_unlink syscalls.

Quoted 1 line

From 2aaa1d66232da3bee0fcdac93bbab09f12ce4b19 Mon Sep 17 00:00:00 2001

From: Lionel Landwerlin <[email protected]>
Date: Mon, 1 Dec 2008 02:42:24 +0100
Subject: [PATCH] Added posix message queue syscalls except mq_notify

Quoted 5 lines
---
 linux-user/syscall.c      |  147 +++++++++++++++++++++++++++++++++++++++-----
 linux-user/syscall_defs.h |    9 +++-
 2 files changed, 138 insertions(+), 18 deletions(-)

I also have added it to my patchset:
http://git.altlinux.org/people/kas/packages/qemu.git?a=shortlog;h=refs/heads/for-upstream

Signature · 3 lines
Regards,  Kirill A. Shutemov
 + Belarus, Minsk
 + ALT Linux Team, http://www.altlinux.org/
#7 lore raw

Here another patch to format mq_open strace arguments (very similar to the open format) :

Quoted 1 line

From faec50221490c953c229f1614a37f7d45bfe0ec7 Mon Sep 17 00:00:00 2001

From: Lionel Landwerlin <[email protected]>
Date: Sat, 20 Dec 2008 19:15:58 +0100
Subject: [PATCH] Format mq_open strace arguments

---
 linux-user/strace.list |    2 +-
 1 files changed, 1 insertions(+), 1 deletions(-)
linux-user/strace.list +1 -1
index 09a801f..45eb24d 100644
@@ -530,7 +530,7 @@
 { TARGET_NR_mq_notify, "mq_notify" , NULL, NULL, NULL },
 #endif
 #ifdef TARGET_NR_mq_open
-{ TARGET_NR_mq_open, "mq_open" , NULL, NULL, NULL },
+{ TARGET_NR_mq_open, "mq_open" , "%s(\"/%s\",%#x,%#o,%p)", NULL, NULL },
 #endif
 #ifdef TARGET_NR_mq_timedreceive
 { TARGET_NR_mq_timedreceive, "mq_timedreceive" , NULL, NULL, NULL },
Signature · 1 line
1.5.6.5
Reviewed-by
#8 lore raw
Quoted 28 lines · Lionel Landwerlin

Here another patch to format mq_open strace arguments (very similar to the open format) :

Quoted 1 line

From faec50221490c953c229f1614a37f7d45bfe0ec7 Mon Sep 17 00:00:00 2001

From: Lionel Landwerlin <[email protected]>
Date: Sat, 20 Dec 2008 19:15:58 +0100
Subject: [PATCH] Format mq_open strace arguments

---
 linux-user/strace.list |    2 +-
 1 files changed, 1 insertions(+), 1 deletions(-)
linux-user/strace.list +1 -1
index 09a801f..45eb24d 100644
@@ -530,7 +530,7 @@
 { TARGET_NR_mq_notify, "mq_notify" , NULL, NULL, NULL },
 #endif
 #ifdef TARGET_NR_mq_open
-{ TARGET_NR_mq_open, "mq_open" , NULL, NULL, NULL },
+{ TARGET_NR_mq_open, "mq_open" , "%s(\"/%s\",%#x,%#o,%p)", NULL, NULL },
 #endif
 #ifdef TARGET_NR_mq_timedreceive
 { TARGET_NR_mq_timedreceive, "mq_timedreceive" , NULL, NULL, NULL },
Signature · 1 line
1.5.6.5

Thanks. Added to my patchset.

Please, use git send-email next time.

Signature · 3 lines
Regards,  Kirill A. Shutemov
 + Belarus, Minsk
 + ALT Linux Team, http://www.altlinux.org/
#9 lore raw

PATCH 1/1 More strace formatting for posix message queues syscalls

More strace formatting for posix message queues syscalls

---
 linux-user/strace.list |   10 +++++-----
 1 files changed, 5 insertions(+), 5 deletions(-)
linux-user/strace.list +5 -5
index 45eb24d..3f688db 100644
@@ -524,22 +524,22 @@
 { TARGET_NR_mpx, "mpx" , NULL, NULL, NULL },
 #endif
 #ifdef TARGET_NR_mq_getsetattr
-{ TARGET_NR_mq_getsetattr, "mq_getsetattr" , NULL, NULL, NULL },
+{ TARGET_NR_mq_getsetattr, "mq_getsetattr" , "%s(%d,%p,%p)", NULL, NULL },
 #endif
 #ifdef TARGET_NR_mq_notify
-{ TARGET_NR_mq_notify, "mq_notify" , NULL, NULL, NULL },
+{ TARGET_NR_mq_notify, "mq_notify" , "%s(%d,%p)", NULL, NULL },
 #endif
 #ifdef TARGET_NR_mq_open
 { TARGET_NR_mq_open, "mq_open" , "%s(\"/%s\",%#x,%#o,%p)", NULL, NULL },
 #endif
 #ifdef TARGET_NR_mq_timedreceive
-{ TARGET_NR_mq_timedreceive, "mq_timedreceive" , NULL, NULL, NULL },
+{ TARGET_NR_mq_timedreceive, "mq_timedreceive" , "%s(%d,%p,%d,%u,%p)", NULL, NULL },
 #endif
 #ifdef TARGET_NR_mq_timedsend
-{ TARGET_NR_mq_timedsend, "mq_timedsend" , NULL, NULL, NULL },
+{ TARGET_NR_mq_timedsend, "mq_timedsend" , "%s(%d,%p,%d,%u,%p)", NULL, NULL },
 #endif
 #ifdef TARGET_NR_mq_unlink
-{ TARGET_NR_mq_unlink, "mq_unlink" , NULL, NULL, NULL },
+{ TARGET_NR_mq_unlink, "mq_unlink" , "%s(%s)", NULL, NULL },
 #endif
 #ifdef TARGET_NR_mremap
 { TARGET_NR_mremap, "mremap" , NULL, NULL, NULL },
Signature · 1 line
1.5.6.5
#11 lore raw
In reply to Lionel Landwerlin

linux-user/syscall.c abi_long do_syscall(void *cpu_env, int num, abi_long arg1, · line 6136

Quoted 3 lines · Lionel Landwerlin
linux-user/syscall.c +3 -0
+    case TARGET_NR_mq_getsetattr:
+    {
+        struct mq_attr posix_mq_attr_in, posix_mq_attr_out;

ret = 0;

linux-user/syscall.c abi_long do_syscall(void *cpu_env, int num, abi_long arg1, · line 6147

Quoted 11 lines
linux-user/syscall.c +11 -0
+
+        if (arg3 != 0) {
+            ret = mq_getattr(arg1, &posix_mq_attr_out);
+            copy_to_user_mq_attr(arg3, &posix_mq_attr_out);
+        }
+        if (arg2 != 0) {
+            copy_from_user_mq_attr(&posix_mq_attr_in, arg2);
+            ret |= mq_setattr(arg1, &posix_mq_attr_in, &posix_mq_attr_out);
+        }
+
+        break;

mq_getsetattr might end up called without both arg3 and arg2. Other than that, looks good to me.

#12 lore raw
Quoted 8 lines · Riku Voipio

linux-user/syscall.c abi_long do_syscall(void *cpu_env, int num, abi_long arg1, · line 6136

Quoted 3 lines · Lionel Landwerlin
linux-user/syscall.c +3 -0
+    case TARGET_NR_mq_getsetattr:
+    {
+        struct mq_attr posix_mq_attr_in, posix_mq_attr_out;

ret = 0;

Quoted 14 lines

linux-user/syscall.c abi_long do_syscall(void *cpu_env, int num, abi_long arg1, · line 6147

Quoted 11 lines
linux-user/syscall.c +11 -0
+
+        if (arg3 != 0) {
+            ret = mq_getattr(arg1, &posix_mq_attr_out);
+            copy_to_user_mq_attr(arg3, &posix_mq_attr_out);
+        }
+        if (arg2 != 0) {
+            copy_from_user_mq_attr(&posix_mq_attr_in, arg2);
+            ret |= mq_setattr(arg1, &posix_mq_attr_in, &posix_mq_attr_out);
+        }
+
+        break;

mq_getsetattr might end up called without both arg3 and arg2. Other than that, looks good to me.

Fixed in my patchset. Thanks.

Signature · 3 lines
Regards,  Kirill A. Shutemov
 + Belarus, Minsk
 + ALT Linux Team, http://www.altlinux.org/