From 9849b95b62baf47b0874dde016fa181099f0e83a Mon Sep 17 00:00:00 2001 From: "Todd C. Miller" Date: Wed, 10 Dec 2003 23:10:09 +0000 Subject: Add an nfds_t type as per POSIX and also add pollfd_t like Solaris has. --- lib/libc/sys/poll.2 | 8 ++++---- lib/libpthread/uthread/uthread_poll.c | 6 +++--- sys/kern/sys_generic.c | 22 +++++++++++----------- sys/kern/syscalls.master | 4 ++-- sys/sys/poll.h | 10 ++++++---- 5 files changed, 26 insertions(+), 24 deletions(-) diff --git a/lib/libc/sys/poll.2 b/lib/libc/sys/poll.2 index 7d6271a5c54..b9aae0a427d 100644 --- a/lib/libc/sys/poll.2 +++ b/lib/libc/sys/poll.2 @@ -1,4 +1,4 @@ -.\" $OpenBSD: poll.2,v 1.17 2003/09/23 16:53:34 millert Exp $ +.\" $OpenBSD: poll.2,v 1.18 2003/12/10 23:10:08 millert Exp $ .\" .\" Copyright (c) 1994 Jason R. Thorpe .\" All rights reserved. @@ -37,7 +37,7 @@ .Sh SYNOPSIS .Fd #include .Ft int -.Fn poll "struct pollfd *fds" "int nfds" "int timeout" +.Fn poll "struct pollfd *fds" "nfds_t nfds" "int timeout" .Sh DESCRIPTION .Fn poll provides a mechanism for multiplexing I/O across a set of file @@ -87,7 +87,7 @@ and members are bitmasks of conditions to monitor and conditions found, respectively. .It Fa nfds -The number of +An unsigned integer specifying the number of .Fa pollfd structures in the array. .It Fa timeout @@ -224,7 +224,7 @@ points outside the process's allocated address space. caught a signal during the polling process. .It Bq Er EINVAL .Fa nfds -was either a negative number or greater than the number of available +was greater than the number of available file descriptors. .It Bq Er EINVAL The timeout passed to diff --git a/lib/libpthread/uthread/uthread_poll.c b/lib/libpthread/uthread/uthread_poll.c index cb6915fbd36..239b3f62da6 100644 --- a/lib/libpthread/uthread/uthread_poll.c +++ b/lib/libpthread/uthread/uthread_poll.c @@ -1,4 +1,4 @@ -/* $OpenBSD: uthread_poll.c,v 1.7 2002/01/10 00:38:39 fgsch Exp $ */ +/* $OpenBSD: uthread_poll.c,v 1.8 2003/12/10 23:10:08 millert Exp $ */ /* * Copyright (c) 1999 Daniel Eischen * All rights reserved. @@ -45,11 +45,11 @@ int -poll(struct pollfd fds[], int nfds, int timeout) +poll(struct pollfd fds[], nfds_t nfds, int timeout) { struct pthread *curthread = _get_curthread(); struct timespec ts; - int numfds = nfds; + nfds_t numfds = nfds; int i, ret = 0; struct pthread_poll_data data; diff --git a/sys/kern/sys_generic.c b/sys/kern/sys_generic.c index 713de532eaa..a6fdd09c95e 100644 --- a/sys/kern/sys_generic.c +++ b/sys/kern/sys_generic.c @@ -1,4 +1,4 @@ -/* $OpenBSD: sys_generic.c,v 1.46 2003/09/23 16:51:12 millert Exp $ */ +/* $OpenBSD: sys_generic.c,v 1.47 2003/12/10 23:10:08 millert Exp $ */ /* $NetBSD: sys_generic.c,v 1.24 1996/03/29 00:25:32 cgd Exp $ */ /* @@ -63,7 +63,7 @@ int selscan(struct proc *, fd_set *, fd_set *, int, register_t *); int seltrue(dev_t, int, struct proc *); -void pollscan(struct proc *, struct pollfd *, int, register_t *); +void pollscan(struct proc *, struct pollfd *, u_int, register_t *); /* * Read system call. @@ -868,12 +868,13 @@ void pollscan(p, pl, nfd, retval) struct proc *p; struct pollfd *pl; - int nfd; + u_int nfd; register_t *retval; { struct filedesc *fdp = p->p_fd; struct file *fp; - int i, n = 0; + u_int i; + int n = 0; for (i = 0; i < nfd; i++, pl++) { /* Check the file descriptor. */ @@ -902,19 +903,18 @@ pollscan(p, pl, nfd, retval) int sys_poll(struct proc *p, void *v, register_t *retval) { - struct sys_poll_args *uap = v; + struct sys_poll_args /* { + syscallarg(struct pollfd *) fds; + syscallarg(u_int) nfds; + syscallarg(int) timeout; + } */ *uap = v; size_t sz; struct pollfd pfds[4], *pl = pfds; int msec = SCARG(uap, timeout); struct timeval atv; int timo, ncoll, i, s, error; extern int nselcoll, selwait; - u_int nfds; - - if (SCARG(uap, nfds) < 0) - return (EINVAL); - - nfds = SCARG(uap, nfds); + u_int nfds = SCARG(uap, nfds); /* Standards say no more than MAX_OPEN; this is possibly better. */ if (nfds > min((int)p->p_rlimit[RLIMIT_NOFILE].rlim_cur, maxfiles)) diff --git a/sys/kern/syscalls.master b/sys/kern/syscalls.master index 2cacada8c32..80d9878d0b7 100644 --- a/sys/kern/syscalls.master +++ b/sys/kern/syscalls.master @@ -1,4 +1,4 @@ -; $OpenBSD: syscalls.master,v 1.62 2003/09/07 21:00:27 miod Exp $ +; $OpenBSD: syscalls.master,v 1.63 2003/12/10 23:10:08 millert Exp $ ; $NetBSD: syscalls.master,v 1.32 1996/04/23 10:24:21 mycroft Exp $ ; @(#)syscalls.master 8.2 (Berkeley) 1/13/94 @@ -487,7 +487,7 @@ int inherit); } 251 STD { int sys_rfork(int flags); } 252 STD { int sys_poll(struct pollfd *fds, \ - int nfds, int timeout); } + u_int nfds, int timeout); } 253 STD { int sys_issetugid(void); } 254 STD { int sys_lchown(const char *path, uid_t uid, gid_t gid); } 255 STD { pid_t sys_getsid(pid_t pid); } diff --git a/sys/sys/poll.h b/sys/sys/poll.h index c64bd67bed4..84d28658937 100644 --- a/sys/sys/poll.h +++ b/sys/sys/poll.h @@ -1,4 +1,4 @@ -/* $OpenBSD: poll.h,v 1.10 2003/06/02 04:04:54 deraadt Exp $ */ +/* $OpenBSD: poll.h,v 1.11 2003/12/10 23:10:08 millert Exp $ */ /* * Copyright (c) 1996 Theo de Raadt @@ -28,11 +28,13 @@ #ifndef _SYS_POLL_H_ #define _SYS_POLL_H_ -struct pollfd { +typedef struct pollfd { int fd; short events; short revents; -}; +} pollfd_t; + +typedef unsigned int nfds_t; #define POLLIN 0x0001 #define POLLPRI 0x0002 @@ -52,7 +54,7 @@ struct pollfd { #include __BEGIN_DECLS -int poll(struct pollfd[], int, int); +int poll(struct pollfd[], nfds_t, int); __END_DECLS #endif /* _KERNEL */ -- cgit v1.2.3