Skip site navigation (1)Skip section navigation (2)
Date:      Fri, 7 Nov 2014 21:44:25 +0300
From:      Chagin Dmitry <dchagin@freebsd.org>
To:        Konstantin Belousov <kostikbel@gmail.com>
Cc:        src-committers@freebsd.org, svn-src-user@freebsd.org
Subject:   Re: svn commit: r274242 - in user/dchagin/lemul/sys: kern sys
Message-ID:  <20141107184425.GA10199@dchagin.static.corbina.net>
In-Reply-To: <20141107181714.GT53947@kib.kiev.ua>
References:  <201411071625.sA7GP85K020870@svn.freebsd.org> <20141107181714.GT53947@kib.kiev.ua>

next in thread | previous in thread | raw e-mail | index | archive | help

--HlL+5n6rz5pIUxbD
Content-Type: text/plain; charset=us-ascii
Content-Disposition: inline
Content-Transfer-Encoding: quoted-printable

On Fri, Nov 07, 2014 at 08:17:14PM +0200, Konstantin Belousov wrote:
> On Fri, Nov 07, 2014 at 04:25:08PM +0000, Dmitry Chagin wrote:
> > Author: dchagin
> > Date: Fri Nov  7 16:25:07 2014
> > New Revision: 274242
> > URL: https://svnweb.freebsd.org/changeset/base/274242
> >=20
> > Log:
> >   Split up sys_poll() into a sys_ and kern_ counterparts, add kern_ppol=
l()
> >   version needed by an upcoming Linuxulator change.
> I think there must be native ppoll(2) if you added a helper and
> plan Linux one.
>=20

ok,

> >=20
> > Modified:
> >   user/dchagin/lemul/sys/kern/sys_generic.c
> >   user/dchagin/lemul/sys/sys/syscallsubr.h
> >=20
> > Modified: user/dchagin/lemul/sys/kern/sys_generic.c
> > =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D
> > --- user/dchagin/lemul/sys/kern/sys_generic.c	Fri Nov  7 16:22:58 2014	=
(r274241)
> > +++ user/dchagin/lemul/sys/kern/sys_generic.c	Fri Nov  7 16:25:07 2014	=
(r274242)
> > @@ -97,6 +97,8 @@ static int	pollout(struct thread *, stru
> >  		    u_int);
> >  static int	pollscan(struct thread *, struct pollfd *, u_int);
> >  static int	pollrescan(struct thread *);
> > +static int	kern_poll(struct thread *, struct pollfd *, uint32_t,
> > +		    sbintime_t, sbintime_t);
> >  static int	selscan(struct thread *, fd_mask **, fd_mask **, int);
> >  static int	selrescan(struct thread *, fd_mask **, fd_mask **);
> >  static void	selfdalloc(struct thread *, void *);
> > @@ -1301,30 +1303,12 @@ sys_poll(td, uap)
> >  	struct thread *td;
> >  	struct poll_args *uap;
> >  {
> > -	struct pollfd *bits;
> > -	struct pollfd smallbits[32];
> >  	sbintime_t asbt, precision, rsbt;
> > -	u_int nfds;
> > -	int error;
> > -	size_t ni;
> > =20
> > -	nfds =3D uap->nfds;
> > -	if (nfds > maxfilesperproc && nfds > FD_SETSIZE)=20
> > -		return (EINVAL);
> > -	ni =3D nfds * sizeof(struct pollfd);
> > -	if (ni > sizeof(smallbits))
> > -		bits =3D malloc(ni, M_TEMP, M_WAITOK);
> > -	else
> > -		bits =3D smallbits;
> > -	error =3D copyin(uap->fds, bits, ni);
> > -	if (error)
> > -		goto done;
> >  	precision =3D 0;
> >  	if (uap->timeout !=3D INFTIM) {
> > -		if (uap->timeout < 0) {
> > -			error =3D EINVAL;
> > -			goto done;
> > -		}
> > +		if (uap->timeout < 0)
> > +			return (EINVAL);
> >  		if (uap->timeout =3D=3D 0)
> >  			asbt =3D 0;
> >  		else {
> > @@ -1337,13 +1321,37 @@ sys_poll(td, uap)
> >  		}
> >  	} else
> >  		asbt =3D -1;
> > +
> > +	return (kern_poll(td, uap->fds, uap->nfds, asbt, precision));
> > +}
> > +
> > +static int
> > +kern_poll(struct thread *td, struct pollfd *fds, uint32_t nfds,
> > +    sbintime_t sbt, sbintime_t prec)
> uint32_t type fo nfds is weird and probably even wrong.
> Native syscalls use unsigned int for it, and this helper definitely
> should follow them.
>=20

ok

> > +{
> > +	struct pollfd *bits;
> > +	struct pollfd smallbits[32];
> > +	int error;
> > +	size_t ni;
> > +
> > +	if (nfds > maxfilesperproc && nfds > FD_SETSIZE)=20
> > +		return (EINVAL);
> This line was moved from the original code intact, but it still
> looks strange.  What is the purpose of FD_SETSIZE test ?
>=20

r72203, "we want to be reasonably safe, but not overly restrictive."
there are no complains from users, possibly it is acceptable for all.
thanks!



> > +	ni =3D nfds * sizeof(struct pollfd);
> > +	if (ni > sizeof(smallbits))
> > +		bits =3D malloc(ni, M_TEMP, M_WAITOK);
> > +	else
> > +		bits =3D smallbits;
> > +	error =3D copyin(fds, bits, ni);
> > +	if (error)
> > +		goto done;
> > +
> >  	seltdinit(td);
> >  	/* Iterate until the timeout expires or descriptors become ready. */
> >  	for (;;) {
> >  		error =3D pollscan(td, bits, nfds);
> >  		if (error || td->td_retval[0] !=3D 0)
> >  			break;
> > -		error =3D seltdwait(td, asbt, precision);
> > +		error =3D seltdwait(td, sbt, prec);
> >  		if (error)
> >  			break;
> >  		error =3D pollrescan(td);
> > @@ -1359,7 +1367,7 @@ done:
> >  	if (error =3D=3D EWOULDBLOCK)
> >  		error =3D 0;
> >  	if (error =3D=3D 0) {
> > -		error =3D pollout(td, bits, uap->fds, nfds);
> > +		error =3D pollout(td, bits, fds, nfds);
> >  		if (error)
> >  			goto out;
> >  	}
> > @@ -1369,6 +1377,59 @@ out:
> >  	return (error);
> >  }
> > =20
> > +int
> > +kern_ppoll(struct thread *td, struct pollfd *fds, uint32_t nfds,
> Same uint32_t.
>=20
> > +    struct timespec *tsp, sigset_t *uset)
> > +{
> > +	struct timespec ts;
> > +	sbintime_t sbt, precision, tmp;
> > +	time_t over;
> > +	int error;

--=20
Have fun!
chd

--HlL+5n6rz5pIUxbD
Content-Type: application/pgp-signature

-----BEGIN PGP SIGNATURE-----
Version: GnuPG v2

iEYEARECAAYFAlRdEwkACgkQ0t2Tb3OO/O2MiACgnnO7i+NQ1ATfdAlpZxLBkjeQ
IfQAnR/AMgP0stf3f1JwrawlvX4Ly60S
=MS2D
-----END PGP SIGNATURE-----

--HlL+5n6rz5pIUxbD--



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?20141107184425.GA10199>