From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1JU0aM-0004MM-MD for qemu-devel@nongnu.org; Tue, 26 Feb 2008 09:15:10 -0500 Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1JU0aM-0004Lw-3l for qemu-devel@nongnu.org; Tue, 26 Feb 2008 09:15:10 -0500 Received: from [199.232.76.173] (helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1JU0aL-0004Lt-Rz for qemu-devel@nongnu.org; Tue, 26 Feb 2008 09:15:09 -0500 Received: from partizan.velesys.com ([213.184.230.195]) by monty-python.gnu.org with esmtp (Exim 4.60) (envelope-from ) id 1JU0aK-00027g-UC for qemu-devel@nongnu.org; Tue, 26 Feb 2008 09:15:09 -0500 Received: from localhost (mail.velesys.com [10.0.5.31]) by partizan.velesys.com (partizan.velesys.com) with ESMTP id 74039136B29 for ; Tue, 26 Feb 2008 14:14:21 +0000 (UTC) Received: from partizan.velesys.com ([10.0.5.31]) by localhost (mail.velesys.com [10.0.5.31]) (amavisd-new, port 10024) with ESMTP id xyIhtuEvojt7 for ; Tue, 26 Feb 2008 14:14:18 +0000 (UTC) Received: from localhost.localdomain (unknown [10.0.0.74]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (No client certificate requested) by partizan.velesys.com (partizan.velesys.com) with ESMTP id EC0FE136B15 for ; Tue, 26 Feb 2008 14:14:18 +0000 (UTC) Date: Tue, 26 Feb 2008 16:17:47 +0200 From: "Kirill A. Shutemov" Subject: Re: [Qemu-devel] [PATCH] linux-user, fix getgroups/getgroups32 when both args are zero. Message-ID: <20080226141746.GA13627@localhost.localdomain> References: <20080223120023.2ce6ed1e.takasi-y@ops.dti.ne.jp> <20080223072529.GA4717@localhost.localdomain> MIME-Version: 1.0 Content-Type: multipart/signed; micalg=pgp-sha1; protocol="application/pgp-signature"; boundary="vtzGhvizbBRQ85DL" Content-Disposition: inline In-Reply-To: <20080223072529.GA4717@localhost.localdomain> Reply-To: qemu-devel@nongnu.org List-Id: qemu-devel.nongnu.org List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: qemu-devel@nongnu.org --vtzGhvizbBRQ85DL Content-Type: text/plain; charset=us-ascii Content-Disposition: inline Content-Transfer-Encoding: quoted-printable 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 arg= s are > > zero. But because we pass a ptr to allocated space as 2nd arg, this fun= ction > > are interfered. The patch attached fixed it. > > /yoshii > > --- > > linux-user/syscall.c: fix getgroups{,32} when both args are zero. > >=20 >=20 > My version of patch to fix same problem: >=20 > getgroups: return total number of supplementary group IDs for the > process if size =3D=3D 0 >=20 > 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_lon= g arg1, > =20 > grouplist =3D alloca(gidsetsize * sizeof(gid_t)); > ret =3D get_errno(getgroups(gidsetsize, grouplist)); > + if (gidsetsize =3D=3D 0) > + break; > if (!is_error(ret)) { > target_grouplist =3D lock_user(VERIFY_WRITE, arg2, gidse= tsize * 2, 0); > if (!target_grouplist) > @@ -5179,6 +5181,8 @@ abi_long do_syscall(void *cpu_env, int num, abi_lon= g arg1, > =20 > grouplist =3D alloca(gidsetsize * sizeof(gid_t)); > ret =3D get_errno(getgroups(gidsetsize, grouplist)); > + if (gidsetsize =3D=3D 0) > + break; > if (!is_error(ret)) { > target_grouplist =3D lock_user(VERIFY_WRITE, arg2, gidse= tsize * 4, 0); > if (!target_grouplist) { >=20 > Another patch for getgroups: >=20 > Trivial optimization of getgroups syscall implementation: > swap only returned groups, not all group in list. >=20 > 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_lon= g arg1, > target_grouplist =3D lock_user(VERIFY_WRITE, arg2, gidse= tsize * 2, 0); > if (!target_grouplist) > goto efault; > - for(i =3D 0;i < gidsetsize; i++) > + for(i =3D 0;i < ret; i++) > target_grouplist[i] =3D tswap16(grouplist[i]); > unlock_user(target_grouplist, arg2, gidsetsize * 2); > } > @@ -5185,7 +5185,7 @@ abi_long do_syscall(void *cpu_env, int num, abi_lon= g arg1, > ret =3D -TARGET_EFAULT; > goto fail; > } > - for(i =3D 0;i < gidsetsize; i++) > + for(i =3D 0;i < ret; i++) > target_grouplist[i] =3D tswap32(grouplist[i]); > unlock_user(target_grouplist, arg2, gidsetsize * 4); > } >=20 > It makes getgroups much faster in some cases. Can anybody commit it? --=20 Regards, Kirill A. Shutemov + Belarus, Minsk + Velesys Ltd, http://www.velesys.com/ + ALT Linux Team, http://www.altlinux.com/ --vtzGhvizbBRQ85DL Content-Type: application/pgp-signature; name="signature.asc" Content-Description: Digital signature Content-Disposition: inline -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.4.8 (GNU/Linux) iEYEARECAAYFAkfEH4oACgkQbWYnhzC5v6oa8ACfePeEZ7yz1iuqRptoIOLrQSs4 /iQAnRsDTVS6BRNg4yLxzxwz31SkqAn8 =sPe1 -----END PGP SIGNATURE----- --vtzGhvizbBRQ85DL--