All of lore.kernel.org
 help / color / mirror / Atom feed
* [Qemu-devel] [linux-user] Added posix message queue syscalls except mq_notify
@ 2008-12-13 12:39 Lionel Landwerlin
  2008-12-14 18:11 ` Kirill A. Shutemov
  0 siblings, 1 reply; 13+ messages in thread
From: Lionel Landwerlin @ 2008-12-13 12:39 UTC (permalink / raw)
  To: qemu-devel

>From 57a528de47a737e59f391ff7df2f87367b40529e Mon Sep 17 00:00:00 2001
From: Lionel Landwerlin <lionel.landwerlin@openwide.fr>
Date: Mon, 1 Dec 2008 02:42:24 +0100
Subject: [PATCH] Added posix message queue syscalls except mq_notify

Signed-off-by: Lionel Landwerlin <lionel.landwerlin@openwide.fr>

---
 linux-user/syscall.c |  151 ++++++++++++++++++++++++++++++++++++++++++++------
 1 files changed, 117 insertions(+), 0 deletions(-)

diff --git a/linux-user/syscall.c b/linux-user/syscall.c
index 4065917..c4dd38a 100644
--- a/linux-user/syscall.c
+++ b/linux-user/syscall.c
@@ -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);
-- 
1.5.6.5

^ permalink raw reply related	[flat|nested] 13+ messages in thread

* Re: [Qemu-devel] [linux-user] Added posix message queue syscalls except mq_notify
  2008-12-13 12:39 [Qemu-devel] [linux-user] Added posix message queue syscalls except mq_notify Lionel Landwerlin
@ 2008-12-14 18:11 ` Kirill A. Shutemov
  2008-12-14 19:19   ` Lionel Landwerlin
  2008-12-15 21:01   ` Lionel Landwerlin
  0 siblings, 2 replies; 13+ messages in thread
From: Kirill A. Shutemov @ 2008-12-14 18:11 UTC (permalink / raw)
  To: qemu-devel

[-- Attachment #1: Type: text/plain, Size: 5761 bytes --]

On Sat, Dec 13, 2008 at 01:39:27PM +0100, Lionel Landwerlin wrote:
> >From 57a528de47a737e59f391ff7df2f87367b40529e Mon Sep 17 00:00:00 2001
> From: Lionel Landwerlin <lionel.landwerlin@openwide.fr>
> Date: Mon, 1 Dec 2008 02:42:24 +0100
> Subject: [PATCH] Added posix message queue syscalls except mq_notify
> 
> Signed-off-by: Lionel Landwerlin <lionel.landwerlin@openwide.fr>
> 
> ---
>  linux-user/syscall.c |  151 ++++++++++++++++++++++++++++++++++++++++++++------
>  1 files changed, 117 insertions(+), 0 deletions(-)
> 
> diff --git a/linux-user/syscall.c b/linux-user/syscall.c
> index 4065917..c4dd38a 100644
> --- a/linux-user/syscall.c
> +++ b/linux-user/syscall.c
> @@ -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;

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

> +
> +    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);

Why - 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);
> +        }

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

> +        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);
> +        }

The same about locking.

> +        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?

> +
> +    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);
> -- 
> 1.5.6.5
-- 
Regards,  Kirill A. Shutemov
 + Belarus, Minsk
 + ALT Linux Team, http://www.altlinux.org/

[-- Attachment #2: Digital signature --]
[-- Type: application/pgp-signature, Size: 197 bytes --]

^ permalink raw reply	[flat|nested] 13+ messages in thread

* Re: [Qemu-devel] [linux-user] Added posix message queue syscalls except mq_notify
  2008-12-14 18:11 ` Kirill A. Shutemov
@ 2008-12-14 19:19   ` Lionel Landwerlin
  2008-12-14 19:37     ` Kirill A. Shutemov
  2008-12-15 21:01   ` Lionel Landwerlin
  1 sibling, 1 reply; 13+ messages in thread
From: Lionel Landwerlin @ 2008-12-14 19:19 UTC (permalink / raw)
  To: qemu-devel

Le dimanche 14 décembre 2008 à 20:11 +0200, Kirill A. Shutemov a écrit :
> On Sat, Dec 13, 2008 at 01:39:27PM +0100, Lionel Landwerlin wrote:
> > >From 57a528de47a737e59f391ff7df2f87367b40529e Mon Sep 17 00:00:00 2001
> > From: Lionel Landwerlin <lionel.landwerlin@openwide.fr>
> > Date: Mon, 1 Dec 2008 02:42:24 +0100
> > Subject: [PATCH] Added posix message queue syscalls except mq_notify
> > 
> > Signed-off-by: Lionel Landwerlin <lionel.landwerlin@openwide.fr>
> > 
> > ---
> >  linux-user/syscall.c |  151 ++++++++++++++++++++++++++++++++++++++++++++------
> >  1 files changed, 117 insertions(+), 0 deletions(-)
> > 
> > diff --git a/linux-user/syscall.c b/linux-user/syscall.c
> > index 4065917..c4dd38a 100644
> > --- a/linux-user/syscall.c
> > +++ b/linux-user/syscall.c
> > @@ -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;
> 
> 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.

> 
> > +
> > +    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);
> 
> Why - 1?

Look at glibc/uclibc implementation, the string argument is (str + 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);
> 
> ?

Same thing.

> 
> > +        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);
> > +        }
> 
> We can lock and unlock outside of if startament, I think.

Right.

> 
> > +        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);
> > +        }
> 
> The same about locking.
> 
> > +        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.

> 
> > +
> > +    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);
> > -- 
> > 1.5.6.5

^ permalink raw reply	[flat|nested] 13+ messages in thread

* Re: [Qemu-devel] [linux-user] Added posix message queue syscalls except mq_notify
  2008-12-14 19:19   ` Lionel Landwerlin
@ 2008-12-14 19:37     ` Kirill A. Shutemov
  2008-12-14 20:33       ` Lionel Landwerlin
  0 siblings, 1 reply; 13+ messages in thread
From: Kirill A. Shutemov @ 2008-12-14 19:37 UTC (permalink / raw)
  To: qemu-devel

[-- Attachment #1: Type: text/plain, Size: 375 bytes --]

On Sun, Dec 14, 2008 at 08:19:51PM +0100, Lionel Landwerlin wrote:
> > > +        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?

-- 
Regards,  Kirill A. Shutemov
 + Belarus, Minsk
 + ALT Linux Team, http://www.altlinux.org/

[-- Attachment #2: Digital signature --]
[-- Type: application/pgp-signature, Size: 197 bytes --]

^ permalink raw reply	[flat|nested] 13+ messages in thread

* Re: [Qemu-devel] [linux-user] Added posix message queue syscalls except mq_notify
  2008-12-14 19:37     ` Kirill A. Shutemov
@ 2008-12-14 20:33       ` Lionel Landwerlin
  0 siblings, 0 replies; 13+ messages in thread
From: Lionel Landwerlin @ 2008-12-14 20:33 UTC (permalink / raw)
  To: qemu-devel

Le dimanche 14 décembre 2008 à 21:37 +0200, Kirill A. Shutemov a écrit :
> On Sun, Dec 14, 2008 at 08:19:51PM +0100, Lionel Landwerlin wrote:
> > > > +        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.


-- 
Lione Landwerlin                                         

O p e n W i d e                    14, rue Gaillon 75002 Paris

^ permalink raw reply	[flat|nested] 13+ messages in thread

* Re: [Qemu-devel] [linux-user] Added posix message queue syscalls except mq_notify
  2008-12-14 18:11 ` Kirill A. Shutemov
  2008-12-14 19:19   ` Lionel Landwerlin
@ 2008-12-15 21:01   ` Lionel Landwerlin
  2008-12-15 21:24     ` Kirill A. Shutemov
  2009-01-12 12:12     ` [Qemu-devel] [linux-user] Added posix message queue syscalls except mq_notify Riku Voipio
  1 sibling, 2 replies; 13+ messages in thread
From: Lionel Landwerlin @ 2008-12-15 21:01 UTC (permalink / raw)
  To: qemu-devel

Le dimanche 14 décembre 2008 à 20:11 +0200, Kirill A. Shutemov a écrit :
> 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.

>From 2aaa1d66232da3bee0fcdac93bbab09f12ce4b19 Mon Sep 17 00:00:00 2001
From: Lionel Landwerlin <lionel.landwerlin@openwide.fr>
Date: Mon, 1 Dec 2008 02:42:24 +0100
Subject: [PATCH] Added posix message queue syscalls except mq_notify

Signed-off-by: Lionel Landwerlin <lionel.landwerlin@openwide.fr>
---
 linux-user/syscall.c      |  147 +++++++++++++++++++++++++++++++++++++++-----
 linux-user/syscall_defs.h |    9 +++-
 2 files changed, 138 insertions(+), 18 deletions(-)

diff --git a/linux-user/syscall.c b/linux-user/syscall.c
index 73427ab..39f26b5 100644
--- a/linux-user/syscall.c
+++ b/linux-user/syscall.c
@@ -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);
diff --git a/linux-user/syscall_defs.h b/linux-user/syscall_defs.h
index 86c9d82..728fedb 100644
--- a/linux-user/syscall_defs.h
+++ b/linux-user/syscall_defs.h
@@ -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"
-- 
1.5.6.5

^ permalink raw reply related	[flat|nested] 13+ messages in thread

* Re: [Qemu-devel] [linux-user] Added posix message queue syscalls except mq_notify
  2008-12-15 21:01   ` Lionel Landwerlin
@ 2008-12-15 21:24     ` Kirill A. Shutemov
  2008-12-20 18:20       ` Lionel Landwerlin
  2009-01-12 12:12     ` [Qemu-devel] [linux-user] Added posix message queue syscalls except mq_notify Riku Voipio
  1 sibling, 1 reply; 13+ messages in thread
From: Kirill A. Shutemov @ 2008-12-15 21:24 UTC (permalink / raw)
  To: qemu-devel

[-- Attachment #1: Type: text/plain, Size: 1144 bytes --]

On Mon, Dec 15, 2008 at 10:01:41PM +0100, Lionel Landwerlin wrote:
> Le dimanche 14 décembre 2008 à 20:11 +0200, Kirill A. Shutemov a écrit :
> > 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.
> 
> >From 2aaa1d66232da3bee0fcdac93bbab09f12ce4b19 Mon Sep 17 00:00:00 2001
> From: Lionel Landwerlin <lionel.landwerlin@openwide.fr>
> Date: Mon, 1 Dec 2008 02:42:24 +0100
> Subject: [PATCH] Added posix message queue syscalls except mq_notify
> 
> Signed-off-by: Lionel Landwerlin <lionel.landwerlin@openwide.fr>
> ---
>  linux-user/syscall.c      |  147 +++++++++++++++++++++++++++++++++++++++-----
>  linux-user/syscall_defs.h |    9 +++-
>  2 files changed, 138 insertions(+), 18 deletions(-)

Reviewed-by: Kirill A. Shutemov <kirill@shutemov.name>

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

-- 
Regards,  Kirill A. Shutemov
 + Belarus, Minsk
 + ALT Linux Team, http://www.altlinux.org/

[-- Attachment #2: Digital signature --]
[-- Type: application/pgp-signature, Size: 197 bytes --]

^ permalink raw reply	[flat|nested] 13+ messages in thread

* Re: [Qemu-devel] [linux-user] Added posix message queue syscalls except mq_notify
  2008-12-15 21:24     ` Kirill A. Shutemov
@ 2008-12-20 18:20       ` Lionel Landwerlin
  2008-12-20 18:33         ` Kirill A. Shutemov
  0 siblings, 1 reply; 13+ messages in thread
From: Lionel Landwerlin @ 2008-12-20 18:20 UTC (permalink / raw)
  To: qemu-devel; +Cc: Kirill A. Shutemov

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

>From faec50221490c953c229f1614a37f7d45bfe0ec7 Mon Sep 17 00:00:00 2001
From: Lionel Landwerlin <lionel.landwerlin@openwide.fr>
Date: Sat, 20 Dec 2008 19:15:58 +0100
Subject: [PATCH] Format mq_open strace arguments

Signed-off-by: Lionel Landwerlin <lionel.landwerlin@openwide.fr>
---
 linux-user/strace.list |    2 +-
 1 files changed, 1 insertions(+), 1 deletions(-)

diff --git a/linux-user/strace.list b/linux-user/strace.list
index 09a801f..45eb24d 100644
--- a/linux-user/strace.list
+++ b/linux-user/strace.list
@@ -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 },
-- 
1.5.6.5

^ permalink raw reply related	[flat|nested] 13+ messages in thread

* Re: [Qemu-devel] [linux-user] Added posix message queue syscalls except mq_notify
  2008-12-20 18:20       ` Lionel Landwerlin
@ 2008-12-20 18:33         ` Kirill A. Shutemov
  2008-12-20 20:20           ` [Qemu-devel] [PATCH] More strace formatting for posix message queues syscalls Lionel Landwerlin
  0 siblings, 1 reply; 13+ messages in thread
From: Kirill A. Shutemov @ 2008-12-20 18:33 UTC (permalink / raw)
  To: Lionel Landwerlin; +Cc: qemu-devel

[-- Attachment #1: Type: text/plain, Size: 1359 bytes --]

On Sat, Dec 20, 2008 at 07:20:55PM +0100, Lionel Landwerlin wrote:
> Here another patch to format mq_open strace arguments (very similar to
> the open format) :
> 
> >From faec50221490c953c229f1614a37f7d45bfe0ec7 Mon Sep 17 00:00:00 2001
> From: Lionel Landwerlin <lionel.landwerlin@openwide.fr>
> Date: Sat, 20 Dec 2008 19:15:58 +0100
> Subject: [PATCH] Format mq_open strace arguments
> 
> Signed-off-by: Lionel Landwerlin <lionel.landwerlin@openwide.fr>
> ---
>  linux-user/strace.list |    2 +-
>  1 files changed, 1 insertions(+), 1 deletions(-)
> 
> diff --git a/linux-user/strace.list b/linux-user/strace.list
> index 09a801f..45eb24d 100644
> --- a/linux-user/strace.list
> +++ b/linux-user/strace.list
> @@ -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 },
> -- 
> 1.5.6.5

Reviewed-by: Kirill A. Shutemov <kirill@shutemov.name>

Thanks. Added to my patchset.

Please, use git send-email next time.

-- 
Regards,  Kirill A. Shutemov
 + Belarus, Minsk
 + ALT Linux Team, http://www.altlinux.org/

[-- Attachment #2: Digital signature --]
[-- Type: application/pgp-signature, Size: 197 bytes --]

^ permalink raw reply	[flat|nested] 13+ messages in thread

* [Qemu-devel] [PATCH] More strace formatting for posix message queues syscalls
  2008-12-20 18:33         ` Kirill A. Shutemov
@ 2008-12-20 20:20           ` Lionel Landwerlin
  2008-12-21 13:55             ` [Qemu-devel] " Kirill A. Shutemov
  0 siblings, 1 reply; 13+ messages in thread
From: Lionel Landwerlin @ 2008-12-20 20:20 UTC (permalink / raw)
  To: qemu-devel; +Cc: Kirill A. Shutemov

More strace formatting for posix message queues syscalls

Signed-off-by: Lionel Landwerlin <lionel.landwerlin@openwide.fr>
---
 linux-user/strace.list |   10 +++++-----
 1 files changed, 5 insertions(+), 5 deletions(-)

diff --git a/linux-user/strace.list b/linux-user/strace.list
index 45eb24d..3f688db 100644
--- a/linux-user/strace.list
+++ b/linux-user/strace.list
@@ -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 },
-- 
1.5.6.5

^ permalink raw reply related	[flat|nested] 13+ messages in thread

* [Qemu-devel] Re: [PATCH] More strace formatting for posix message queues syscalls
  2008-12-20 20:20           ` [Qemu-devel] [PATCH] More strace formatting for posix message queues syscalls Lionel Landwerlin
@ 2008-12-21 13:55             ` Kirill A. Shutemov
  0 siblings, 0 replies; 13+ messages in thread
From: Kirill A. Shutemov @ 2008-12-21 13:55 UTC (permalink / raw)
  To: Lionel Landwerlin; +Cc: qemu-devel

[-- Attachment #1: Type: text/plain, Size: 370 bytes --]

On Sat, Dec 20, 2008 at 09:20:15PM +0100, Lionel Landwerlin wrote:
> More strace formatting for posix message queues syscalls
> 
> Signed-off-by: Lionel Landwerlin <lionel.landwerlin@openwide.fr>

Reviewed-by: Kirill A. Shutemov <kirill@shutemov.name>

Thanks.

-- 
Regards,  Kirill A. Shutemov
 + Belarus, Minsk
 + ALT Linux Team, http://www.altlinux.org/

[-- Attachment #2: Digital signature --]
[-- Type: application/pgp-signature, Size: 197 bytes --]

^ permalink raw reply	[flat|nested] 13+ messages in thread

* Re: [Qemu-devel] [linux-user] Added posix message queue syscalls except mq_notify
  2008-12-15 21:01   ` Lionel Landwerlin
  2008-12-15 21:24     ` Kirill A. Shutemov
@ 2009-01-12 12:12     ` Riku Voipio
  2009-01-12 12:59       ` Kirill A. Shutemov
  1 sibling, 1 reply; 13+ messages in thread
From: Riku Voipio @ 2009-01-12 12:12 UTC (permalink / raw)
  To: Lionel Landwerlin; +Cc: qemu-devel


On Mon, Dec 15, 2008 at 10:01:41PM +0100, Lionel Landwerlin wrote:
> +    case TARGET_NR_mq_getsetattr:
> +    {
> +        struct mq_attr posix_mq_attr_in, posix_mq_attr_out;

ret = 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.

^ permalink raw reply	[flat|nested] 13+ messages in thread

* Re: [Qemu-devel] [linux-user] Added posix message queue syscalls except mq_notify
  2009-01-12 12:12     ` [Qemu-devel] [linux-user] Added posix message queue syscalls except mq_notify Riku Voipio
@ 2009-01-12 12:59       ` Kirill A. Shutemov
  0 siblings, 0 replies; 13+ messages in thread
From: Kirill A. Shutemov @ 2009-01-12 12:59 UTC (permalink / raw)
  To: qemu-devel; +Cc: Lionel Landwerlin

[-- Attachment #1: Type: text/plain, Size: 921 bytes --]

On Mon, Jan 12, 2009 at 02:12:35PM +0200, Riku Voipio wrote:
> 
> On Mon, Dec 15, 2008 at 10:01:41PM +0100, Lionel Landwerlin wrote:
> > +    case TARGET_NR_mq_getsetattr:
> > +    {
> > +        struct mq_attr posix_mq_attr_in, posix_mq_attr_out;
> 
> ret = 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.

-- 
Regards,  Kirill A. Shutemov
 + Belarus, Minsk
 + ALT Linux Team, http://www.altlinux.org/

[-- Attachment #2: Digital signature --]
[-- Type: application/pgp-signature, Size: 197 bytes --]

^ permalink raw reply	[flat|nested] 13+ messages in thread

end of thread, other threads:[~2009-01-12 12:56 UTC | newest]

Thread overview: 13+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2008-12-13 12:39 [Qemu-devel] [linux-user] Added posix message queue syscalls except mq_notify Lionel Landwerlin
2008-12-14 18:11 ` Kirill A. Shutemov
2008-12-14 19:19   ` Lionel Landwerlin
2008-12-14 19:37     ` Kirill A. Shutemov
2008-12-14 20:33       ` Lionel Landwerlin
2008-12-15 21:01   ` Lionel Landwerlin
2008-12-15 21:24     ` Kirill A. Shutemov
2008-12-20 18:20       ` Lionel Landwerlin
2008-12-20 18:33         ` Kirill A. Shutemov
2008-12-20 20:20           ` [Qemu-devel] [PATCH] More strace formatting for posix message queues syscalls Lionel Landwerlin
2008-12-21 13:55             ` [Qemu-devel] " Kirill A. Shutemov
2009-01-12 12:12     ` [Qemu-devel] [linux-user] Added posix message queue syscalls except mq_notify Riku Voipio
2009-01-12 12:59       ` Kirill A. Shutemov

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.