qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: Aurelien Jarno <aurelien@aurel32.net>
To: qemu-devel@nongnu.org
Cc: "Kirill A. Shutemov" <kirill@shutemov.name>
Subject: Re: [Qemu-devel] [PATCH] Fix and cleanup IPCOP_msg* ipc calls handling
Date: Mon, 13 Oct 2008 17:53:11 +0200	[thread overview]
Message-ID: <20081013155311.GA14963@volta.aurel32.net> (raw)
In-Reply-To: <1223892640-15545-3-git-send-email-kirill@shutemov.name>

On Mon, Oct 13, 2008 at 01:10:30PM +0300, Kirill A. Shutemov wrote:
> Signed-off-by: Kirill A. Shutemov <kirill@shutemov.name>
> ---
>  linux-user/syscall.c |  173 ++++++++++++++++++++++++++++++++++----------------
>  1 files changed, 117 insertions(+), 56 deletions(-)

Please find my comments below. In general, please avoid mixing
indentation changes with code changes. This only makes the code more
difficult to review.

> diff --git a/linux-user/syscall.c b/linux-user/syscall.c
> index 40e985a..7e67093 100644
> --- a/linux-user/syscall.c
> +++ b/linux-user/syscall.c
> @@ -1611,7 +1611,6 @@ static abi_long do_socketcall(int num, abi_ulong vptr)
>  }
>  #endif
>  
> -#ifdef TARGET_NR_ipc
>  #define N_SHM_REGIONS	32
>  
>  static struct shm_region {
> @@ -1845,20 +1844,26 @@ static inline abi_long do_semctl(int first, int second, int third,
>  
>  struct target_msqid_ds
>  {
> -  struct target_ipc_perm msg_perm;
> -  abi_ulong msg_stime;
> -  abi_ulong __unused1;
> -  abi_ulong msg_rtime;
> -  abi_ulong __unused2;
> -  abi_ulong msg_ctime;
> -  abi_ulong __unused3;
> -  abi_ulong __msg_cbytes;
> -  abi_ulong msg_qnum;
> -  abi_ulong msg_qbytes;
> -  abi_ulong msg_lspid;
> -  abi_ulong msg_lrpid;
> -  abi_ulong __unused4;
> -  abi_ulong __unused5;
> +    struct target_ipc_perm msg_perm;
> +    abi_ulong msg_stime;
> +#if TARGET_ABI_BITS == 32
> +    abi_ulong __unused1;
> +#endif
> +    abi_ulong msg_rtime;
> +#if TARGET_ABI_BITS == 32
> +    abi_ulong __unused2;
> +#endif
> +    abi_ulong msg_ctime;
> +#if TARGET_ABI_BITS == 32
> +    abi_ulong __unused3;
> +#endif

Could you explain me why those __unused* are only present with
TARGET_ABI_BITS? This is not consistent with the kernel interface
defined in the glibc.

> +    abi_ulong __msg_cbytes;
> +    abi_ulong msg_qnum;
> +    abi_ulong msg_qbytes;
> +    abi_ulong msg_lspid;
> +    abi_ulong msg_lrpid;
> +    abi_ulong __unused4;
> +    abi_ulong __unused5;
>  };
>  
>  static inline abi_long target_to_host_msqid_ds(struct msqid_ds *host_md,
> @@ -1868,7 +1873,8 @@ static inline abi_long target_to_host_msqid_ds(struct msqid_ds *host_md,
>  
>      if (!lock_user_struct(VERIFY_READ, target_md, target_addr, 1))
>          return -TARGET_EFAULT;
> -    target_to_host_ipc_perm(&(host_md->msg_perm),target_addr);
> +    if (target_to_host_ipc_perm(&(host_md->msg_perm),target_addr))
> +        return -TARGET_EFAULT;
>      host_md->msg_stime = tswapl(target_md->msg_stime);
>      host_md->msg_rtime = tswapl(target_md->msg_rtime);
>      host_md->msg_ctime = tswapl(target_md->msg_ctime);
> @@ -1888,7 +1894,8 @@ static inline abi_long host_to_target_msqid_ds(abi_ulong target_addr,
>  
>      if (!lock_user_struct(VERIFY_WRITE, target_md, target_addr, 0))
>          return -TARGET_EFAULT;
> -    host_to_target_ipc_perm(target_addr,&(host_md->msg_perm));
> +    if (host_to_target_ipc_perm(target_addr,&(host_md->msg_perm)))
> +        return -TARGET_EFAULT;
>      target_md->msg_stime = tswapl(host_md->msg_stime);
>      target_md->msg_rtime = tswapl(host_md->msg_rtime);
>      target_md->msg_ctime = tswapl(host_md->msg_ctime);
> @@ -1901,26 +1908,69 @@ static inline abi_long host_to_target_msqid_ds(abi_ulong target_addr,
>      return 0;
>  }
>  
> -static inline abi_long do_msgctl(int first, int second, abi_long ptr)
> +struct target_msginfo {
> +    int msgpool;
> +    int msgmap;
> +    int msgmax;
> +    int msgmnb;
> +    int msgmni;
> +    int msgssz;
> +    int msgtql;
> +    unsigned short int msgseg;
> +};
> +
> +static inline abi_long host_to_target_msginfo(abi_ulong target_addr,
> +                                              struct msginfo *host_msginfo)
> +{
> +    struct target_msginfo *target_msginfo;
> +    if (!lock_user_struct(VERIFY_WRITE, target_msginfo, target_addr, 0))
> +        return -TARGET_EFAULT;
> +    __put_user(host_msginfo->msgpool, &target_msginfo->msgpool);
> +    __put_user(host_msginfo->msgmap, &target_msginfo->msgmap);
> +    __put_user(host_msginfo->msgmax, &target_msginfo->msgmax);
> +    __put_user(host_msginfo->msgmnb, &target_msginfo->msgmnb);
> +    __put_user(host_msginfo->msgmni, &target_msginfo->msgmni);
> +    __put_user(host_msginfo->msgssz, &target_msginfo->msgssz);
> +    __put_user(host_msginfo->msgtql, &target_msginfo->msgtql);
> +    __put_user(host_msginfo->msgseg, &target_msginfo->msgseg);
> +    unlock_user_struct(target_msginfo, target_addr, 1);
> +}
> +
> +static inline abi_long do_msgctl(int msgid, int cmd, abi_long ptr)
>  {
>      struct msqid_ds dsarg;
> -    int cmd = second&0xff;
> -    abi_long ret = 0;
> -    switch( cmd ) {
> +    struct msginfo msginfo;
> +    abi_long ret = -TARGET_EINVAL;
> +
> +    cmd &= 0xff;
> +
> +    switch (cmd) {
>      case IPC_STAT:
>      case IPC_SET:
> -        target_to_host_msqid_ds(&dsarg,ptr);
> -        ret = get_errno(msgctl(first, cmd, &dsarg));
> -        host_to_target_msqid_ds(ptr,&dsarg);
> -    default:
> -        ret = get_errno(msgctl(first, cmd, &dsarg));

	How is default handled now?

> +    case MSG_STAT:
> +        if (target_to_host_msqid_ds(&dsarg,ptr))
> +            return -TARGET_EFAULT;
> +        ret = get_errno(msgctl(msgid, cmd, &dsarg));
> +        if (host_to_target_msqid_ds(ptr,&dsarg))
> +            return -TARGET_EFAULT;
> +        break;
> +    case IPC_RMID:
> +        ret = get_errno(msgctl(msgid, cmd, NULL));
> +        break;
> +    case IPC_INFO:
> +    case MSG_INFO:
> +        ret = get_errno(msgctl(msgid, cmd, (struct msqid_ds *)&msginfo));
> +        if (host_to_target_msginfo(ptr, &msginfo))
> +            return -TARGET_EFAULT;
> +        break;
>      }
> +
>      return ret;
>  }
>  
>  struct target_msgbuf {
> -	abi_ulong mtype;
> -	char	mtext[1];
> +    abi_long mtype;
> +    char	mtext[1];
>  };
>  
>  static inline abi_long do_msgsnd(int msqid, abi_long msgp,
> @@ -1933,8 +1983,8 @@ static inline abi_long do_msgsnd(int msqid, abi_long msgp,
>      if (!lock_user_struct(VERIFY_READ, target_mb, msgp, 0))
>          return -TARGET_EFAULT;
>      host_mb = malloc(msgsz+sizeof(long));
> -    host_mb->mtype = tswapl(target_mb->mtype);
> -    memcpy(host_mb->mtext,target_mb->mtext,msgsz);
> +    host_mb->mtype = (abi_long) tswapl(target_mb->mtype);
> +    memcpy(host_mb->mtext, target_mb->mtext, msgsz);
>      ret = get_errno(msgsnd(msqid, host_mb, msgsz, msgflg));
>      free(host_mb);
>      unlock_user_struct(target_mb, msgp, 0);
> @@ -1943,7 +1993,7 @@ static inline abi_long do_msgsnd(int msqid, abi_long msgp,
>  }
>  
>  static inline abi_long do_msgrcv(int msqid, abi_long msgp,
> -                                 unsigned int msgsz, int msgtype,
> +                                 unsigned int msgsz, abi_long msgtyp,
>                                   int msgflg)
>  {
>      struct target_msgbuf *target_mb;
> @@ -1953,8 +2003,10 @@ static inline abi_long do_msgrcv(int msqid, abi_long msgp,
>  
>      if (!lock_user_struct(VERIFY_WRITE, target_mb, msgp, 0))
>          return -TARGET_EFAULT;
> +
>      host_mb = malloc(msgsz+sizeof(long));
> -    ret = get_errno(msgrcv(msqid, host_mb, msgsz, 1, msgflg));
> +    ret = get_errno(msgrcv(msqid, host_mb, msgsz, tswapl(msgtyp), msgflg));
> +
>      if (ret > 0) {
>          abi_ulong target_mtext_addr = msgp + sizeof(abi_ulong);
>          target_mtext = lock_user(VERIFY_WRITE, target_mtext_addr, ret, 0);
> @@ -1962,9 +2014,10 @@ static inline abi_long do_msgrcv(int msqid, abi_long msgp,
>              ret = -TARGET_EFAULT;
>              goto end;
>          }
> -    	memcpy(target_mb->mtext, host_mb->mtext, ret);
> +        memcpy(target_mb->mtext, host_mb->mtext, ret);
>          unlock_user(target_mtext, target_mtext_addr, ret);
>      }
> +
>      target_mb->mtype = tswapl(host_mb->mtype);
>      free(host_mb);
>  
> @@ -1974,6 +2027,7 @@ end:
>      return ret;
>  }
>  
> +#ifdef TARGET_NR_ipc
>  /* ??? This only works with linear mappings.  */
>  /* do_ipc() must return target values and target errnos. */
>  static abi_long do_ipc(unsigned int call, int first,
> @@ -2006,34 +2060,41 @@ static abi_long do_ipc(unsigned int call, int first,
>          ret = -TARGET_ENOSYS;
>          break;
>  
> -	case IPCOP_msgget:
> -		ret = get_errno(msgget(first, second));
> -		break;
> +    case IPCOP_msgget:
> +        ret = get_errno(msgget(first, second));
> +        break;
>  
> -	case IPCOP_msgsnd:
> -		ret = do_msgsnd(first, ptr, second, third);
> -		break;
> +    case IPCOP_msgsnd:
> +        ret = do_msgsnd(first, ptr, second, third);
> +        break;
>  
> -	case IPCOP_msgctl:
> -        	ret = do_msgctl(first, second, ptr);
> -		break;
> +    case IPCOP_msgctl:
> +        ret = do_msgctl(first, second, ptr);
> +        break;
>  
> -	case IPCOP_msgrcv:
> -                {
> -                      /* XXX: this code is not correct */
> -                      struct ipc_kludge
> -                      {
> -                              void *__unbounded msgp;
> -                              long int msgtyp;
> -                      };
> +    case IPCOP_msgrcv:
> +        switch (version) {
> +        case 0:
> +            {
> +                struct target_ipc_kludge {
> +                    abi_long msgp;
> +                    abi_long msgtyp;
> +                } *tmp;
>  
> -                      struct ipc_kludge *foo = (struct ipc_kludge *)g2h(ptr);
> -                      struct msgbuf *msgp = (struct msgbuf *) foo->msgp;
> +                if (!lock_user_struct(VERIFY_READ, tmp, ptr, 1)) {
> +                    ret = -TARGET_EFAULT;
> +                    break;
> +                }
>  
> -                      ret = do_msgrcv(first, (long)msgp, second, 0, third);
> +                ret = do_msgrcv(first, tmp->msgp, second, tmp->msgtyp, third);
>  
> -                }
> -		break;
> +                unlock_user_struct(tmp, ptr, 0);
> +                break;
> +            }
> +        default:
> +            ret = do_msgrcv(first, ptr, second, fifth, third);
> +        }
> +        break;
>  
>      case IPCOP_shmat:
>          {
> -- 
> 1.5.6.5.GIT
> 
> 
> 
> 

-- 
  .''`.  Aurelien Jarno	            | GPG: 1024D/F1BCDB73
 : :' :  Debian developer           | Electrical Engineer
 `. `'   aurel32@debian.org         | aurelien@aurel32.net
   `-    people.debian.org/~aurel32 | www.aurel32.net

  parent reply	other threads:[~2008-10-13 15:53 UTC|newest]

Thread overview: 72+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2008-10-13 10:10 [Qemu-devel] [PATCH] Add readahead syscall Kirill A. Shutemov
2008-10-13 10:10 ` [Qemu-devel] [PATCH] Fix getdents* syscalls Kirill A. Shutemov
2008-10-13 10:10   ` [Qemu-devel] [PATCH] Fix and cleanup IPCOP_msg* ipc calls handling Kirill A. Shutemov
2008-10-13 10:10     ` [Qemu-devel] [PATCH] Implement msg* syscalls Kirill A. Shutemov
2008-10-13 10:10       ` [Qemu-devel] [PATCH] Fix and cleanup IPCOP_sem* ipc calls handling Kirill A. Shutemov
2008-10-13 10:10         ` [Qemu-devel] [PATCH] Implement sem* syscalls Kirill A. Shutemov
2008-10-13 10:10           ` [Qemu-devel] [PATCH] Fix and cleanup IPCOP_shm* ipc calls handling Kirill A. Shutemov
2008-10-13 10:10             ` [Qemu-devel] [PATCH] Implement shm* syscalls Kirill A. Shutemov
2008-10-13 10:10               ` [Qemu-devel] [PATCH] Fix fstatat64()/newfstatat() syscall implementation Kirill A. Shutemov
2008-10-13 10:10                 ` [Qemu-devel] [PATCH] Introduce --enable-binfmt-misc configure option Kirill A. Shutemov
2008-10-13 10:10                   ` [Qemu-devel] [PATCH] Rewrite mmap_find_vma() to work fine on 64-bit hosts with 32-bit targets Kirill A. Shutemov
2008-10-13 10:10                     ` [Qemu-devel] [PATCH] mremap(): handle MREMAP_FIXED and MREMAP_MAYMOVE correctly Kirill A. Shutemov
2008-10-13 10:10                       ` [Qemu-devel] [PATCH] shmat(): use mmap_find_vma to find free memory area Kirill A. Shutemov
2008-10-17  6:34                         ` [Qemu-devel] [PATCH] mmap: add check if requested memory area fits target address space Kirill A. Shutemov
2008-10-17  6:34                           ` [Qemu-devel] [PATCH] linux-user, x86: use target_mmap() to allocate idt, gdt and ldt tables Kirill A. Shutemov
2008-11-01  9:33                             ` [Qemu-devel] " Jan Kiszka
2008-11-01 10:27                               ` Kirill A. Shutemov
2008-11-01 10:54                                 ` Jan Kiszka
2008-11-01 11:12                                   ` Kirill A. Shutemov
2008-11-01 11:16                                     ` Kirill A. Shutemov
2008-11-02 19:36                                       ` Jan Kiszka
2008-11-01 11:34                               ` Laurent Desnogues
2008-11-01 10:06                             ` [Qemu-devel] [PATCH, v2] " Kirill A. Shutemov
2008-10-27 13:08                           ` [Qemu-devel] [PATCH] mmap: add check if requested memory area fits target address space andrzej zaborowski
2008-10-27 15:48                             ` Kirill A. Shutemov
2008-10-27 15:55                               ` Andreas Schwab
2008-10-27 17:32                                 ` Kirill A. Shutemov
2008-10-27 19:37                               ` andrzej zaborowski
2008-10-27 20:06                                 ` Kirill A. Shutemov
2008-11-10  3:30                                   ` andrzej zaborowski
2008-11-10  5:55                                     ` Kirill A. Shutemov
2008-11-10 12:45                                       ` andrzej zaborowski
2008-10-27 17:48                           ` [Qemu-devel] [PATCH, v2] " Kirill A. Shutemov
2008-11-10  7:11                             ` [Qemu-devel] [PATCH, v3] " Kirill A. Shutemov
2008-11-10  7:09                         ` [Qemu-devel] [PATCH, v3] shmat(): use mmap_find_vma to find free memory area Kirill A. Shutemov
2008-10-14  4:04                       ` [Qemu-devel] [PATCH] mremap(): handle MREMAP_FIXED and MREMAP_MAYMOVE correctly Vince Weaver
2008-10-14  5:22                         ` Kirill A. Shutemov
2008-10-26 16:14                     ` [Qemu-devel] [PATCH] Rewrite mmap_find_vma() to work fine on 64-bit hosts with 32-bit targets Vince Weaver
2008-10-27 17:49                     ` [Qemu-devel] [PATCH, v2] " Kirill A. Shutemov
2008-11-01 16:51                       ` Jamie Lokier
2008-11-01 16:55                         ` Kirill A. Shutemov
2008-11-10  3:54                           ` andrzej zaborowski
2008-11-10  6:07                             ` Kirill A. Shutemov
2008-11-10  8:02                             ` Jamie Lokier
2008-11-10 12:55                               ` andrzej zaborowski
2008-11-10 14:38                                 ` Kirill A. Shutemov
2008-11-11  0:53                                   ` Jamie Lokier
2008-11-14 12:23                                     ` Kirill A. Shutemov
2008-11-14 12:51                                       ` Paul Brook
2008-11-14 13:08                                         ` Jamie Lokier
2008-11-14 13:51                                           ` Kirill A. Shutemov
2008-11-10  7:07                       ` [Qemu-devel] [PATCH, v3] " Kirill A. Shutemov
2008-11-14 13:57                         ` [Qemu-devel] [PATCH, v4] " Kirill A. Shutemov
2008-11-01 10:10                   ` [Qemu-devel] [PATCH, v2] Introduce --enable-binfmt-misc configure option Kirill A. Shutemov
2008-11-10 13:03                     ` andrzej zaborowski
2008-10-16 20:55               ` [Qemu-devel] [PATCH] Implement shm* syscalls + Implement sem* syscalls Martin Mohring
2008-10-17  4:09                 ` Kirill A. Shutemov
2008-10-17  8:27                   ` Martin Mohring
2008-10-17 10:12                     ` Kirill A. Shutemov
2008-11-01  9:56                 ` Aurelien Jarno
2008-11-01 10:08                   ` Kirill A. Shutemov
2008-10-24  7:24         ` [Qemu-devel] Re: [PATCH] Fix and cleanup IPCOP_sem* ipc calls handling Kirill A. Shutemov
2008-10-13 21:09       ` [Qemu-devel] [PATCH] Implement msg* syscalls Aurelien Jarno
2008-10-13 15:53     ` Aurelien Jarno [this message]
2008-10-13 18:48       ` [Qemu-devel] [PATCH] Fix and cleanup IPCOP_msg* ipc calls handling Kirill A. Shutemov
2008-10-13 20:52         ` Aurelien Jarno
2008-10-13 21:09     ` Aurelien Jarno
2008-10-13 12:48   ` [Qemu-devel] [PATCH] Fix getdents* syscalls Aurelien Jarno
2008-10-13 12:59     ` Kirill A. Shutemov
2008-10-13 13:10       ` Aurelien Jarno
  -- strict thread matches above, loose matches on Subject: below --
2008-10-08 18:54 [Qemu-devel] [PATCH] Add readahead syscall Kirill A. Shutemov
2008-10-08 18:54 ` [Qemu-devel] [PATCH] Fix getdents* syscalls Kirill A. Shutemov
2008-10-08 18:54   ` [Qemu-devel] [PATCH] Fix and cleanup IPCOP_msg* ipc calls handling Kirill A. Shutemov
2008-10-01 13:56 [Qemu-devel] [PATCH] Add fadvise64 stubs Kirill A. Shutemov
2008-10-01 13:56 ` [Qemu-devel] [PATCH] Add mincore syscall Kirill A. Shutemov
2008-10-01 13:56   ` [Qemu-devel] [PATCH] Add readahead syscall Kirill A. Shutemov
2008-10-01 13:56     ` [Qemu-devel] [PATCH] Add inotify syscall family Kirill A. Shutemov
2008-10-01 13:56       ` [Qemu-devel] [PATCH] Fix getdents* syscalls Kirill A. Shutemov
2008-10-01 13:56         ` [Qemu-devel] [PATCH] Fix and cleanup IPCOP_msg* ipc calls handling Kirill A. Shutemov

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=20081013155311.GA14963@volta.aurel32.net \
    --to=aurelien@aurel32.net \
    --cc=kirill@shutemov.name \
    --cc=qemu-devel@nongnu.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).