svn commit: r274242 - in user/dchagin/lemul/sys: kern sys

Chagin Dmitry dchagin at freebsd.org
Fri Nov 7 18:44:29 UTC 2014


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
> > 
> > Log:
> >   Split up sys_poll() into a sys_ and kern_ counterparts, add kern_ppoll()
> >   version needed by an upcoming Linuxulator change.
> I think there must be native ppoll(2) if you added a helper and
> plan Linux one.
> 

ok,

> > 
> > Modified:
> >   user/dchagin/lemul/sys/kern/sys_generic.c
> >   user/dchagin/lemul/sys/sys/syscallsubr.h
> > 
> > Modified: user/dchagin/lemul/sys/kern/sys_generic.c
> > ==============================================================================
> > --- 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;
> >  
> > -	nfds = uap->nfds;
> > -	if (nfds > maxfilesperproc && nfds > FD_SETSIZE) 
> > -		return (EINVAL);
> > -	ni = nfds * sizeof(struct pollfd);
> > -	if (ni > sizeof(smallbits))
> > -		bits = malloc(ni, M_TEMP, M_WAITOK);
> > -	else
> > -		bits = smallbits;
> > -	error = copyin(uap->fds, bits, ni);
> > -	if (error)
> > -		goto done;
> >  	precision = 0;
> >  	if (uap->timeout != INFTIM) {
> > -		if (uap->timeout < 0) {
> > -			error = EINVAL;
> > -			goto done;
> > -		}
> > +		if (uap->timeout < 0)
> > +			return (EINVAL);
> >  		if (uap->timeout == 0)
> >  			asbt = 0;
> >  		else {
> > @@ -1337,13 +1321,37 @@ sys_poll(td, uap)
> >  		}
> >  	} else
> >  		asbt = -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.
> 

ok

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

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

-- 
Have fun!
chd
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 181 bytes
Desc: not available
URL: <http://lists.freebsd.org/pipermail/svn-src-user/attachments/20141107/08cb0f2b/attachment.sig>


More information about the svn-src-user mailing list