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

next in thread | previous in thread | raw e-mail | index | archive | help
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.

> 
> 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.

> +{
> +	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 ?

> +	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;



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