qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: "Kirill A. Shutemov" <k.shutemov@velesys.com>
To: qemu-devel@nongnu.org
Subject: Re: [Qemu-devel] [PATCH] linux-user, fix getgroups/getgroups32 when both args are zero.
Date: Tue, 26 Feb 2008 16:17:47 +0200	[thread overview]
Message-ID: <20080226141746.GA13627@localhost.localdomain> (raw)
In-Reply-To: <20080223072529.GA4717@localhost.localdomain>

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

On [Sat, 23.02.2008 09:25], Kirill A. Shutemov wrote:
> On [Sat, 23.02.2008 12:00], Takashi Yoshii wrote:
> > getgroups() and getgroups32() returns NGROUPS_MAX when both its two args are
> > zero. But because we pass a ptr to allocated space as 2nd arg, this function
> > are interfered. The patch attached fixed it.
> > /yoshii
> > ---
> >     linux-user/syscall.c: fix getgroups{,32} when both args are zero.
> > 
> 
> My version of patch to fix same problem:
> 
>     getgroups: return total number of supplementary group IDs for the
>     process if size == 0
> 
> diff --git a/linux-user/syscall.c b/linux-user/syscall.c
> index ad97871..96a11a9 100644
> --- a/linux-user/syscall.c
> +++ b/linux-user/syscall.c
> @@ -5029,6 +5029,8 @@ abi_long do_syscall(void *cpu_env, int num, abi_long arg1,
>  
>              grouplist = alloca(gidsetsize * sizeof(gid_t));
>              ret = get_errno(getgroups(gidsetsize, grouplist));
> +            if (gidsetsize == 0)
> +                break;
>              if (!is_error(ret)) {
>                  target_grouplist = lock_user(VERIFY_WRITE, arg2, gidsetsize * 2, 0);
>                  if (!target_grouplist)
> @@ -5179,6 +5181,8 @@ abi_long do_syscall(void *cpu_env, int num, abi_long arg1,
>  
>              grouplist = alloca(gidsetsize * sizeof(gid_t));
>              ret = get_errno(getgroups(gidsetsize, grouplist));
> +            if (gidsetsize == 0)
> +                break;
>              if (!is_error(ret)) {
>                  target_grouplist = lock_user(VERIFY_WRITE, arg2, gidsetsize * 4, 0);
>                  if (!target_grouplist) {
> 
> Another patch for getgroups:
> 
>     Trivial optimization of getgroups syscall implementation:
>     swap only returned groups, not all group in list.
> 
> diff --git a/linux-user/syscall.c b/linux-user/syscall.c
> index 6f2872f..ad97871 100644
> --- a/linux-user/syscall.c
> +++ b/linux-user/syscall.c
> @@ -5033,7 +5033,7 @@ abi_long do_syscall(void *cpu_env, int num, abi_long arg1,
>                  target_grouplist = lock_user(VERIFY_WRITE, arg2, gidsetsize * 2, 0);
>                  if (!target_grouplist)
>                      goto efault;
> -                for(i = 0;i < gidsetsize; i++)
> +                for(i = 0;i < ret; i++)
>                      target_grouplist[i] = tswap16(grouplist[i]);
>                  unlock_user(target_grouplist, arg2, gidsetsize * 2);
>              }
> @@ -5185,7 +5185,7 @@ abi_long do_syscall(void *cpu_env, int num, abi_long arg1,
>                      ret = -TARGET_EFAULT;
>                      goto fail;
>                  }
> -                for(i = 0;i < gidsetsize; i++)
> +                for(i = 0;i < ret; i++)
>                      target_grouplist[i] = tswap32(grouplist[i]);
>                  unlock_user(target_grouplist, arg2, gidsetsize * 4);
>              }
> 
> It makes getgroups much faster in some cases.

Can anybody commit it?

-- 
Regards,  Kirill A. Shutemov
 + Belarus, Minsk
 + Velesys Ltd, http://www.velesys.com/
 + ALT Linux Team, http://www.altlinux.com/

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

      parent reply	other threads:[~2008-02-26 14:15 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2008-02-23  3:00 [Qemu-devel] [PATCH] linux-user, fix getgroups/getgroups32 when both args are zero Takashi Yoshii
2008-02-23  7:25 ` Kirill A. Shutemov
2008-02-24  5:19   ` Takashi Yoshii
2008-02-26 14:17   ` Kirill A. Shutemov [this message]

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=20080226141746.GA13627@localhost.localdomain \
    --to=k.shutemov@velesys.com \
    --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).