Date: Sun, 29 Dec 2002 16:50:02 -0800 (PST) From: Craig Rodrigues <rodrigc@attbi.com> To: freebsd-standards@FreeBSD.org Subject: Re: standards/44394: restrict qualifiers missing from sys/socket.h Message-ID: <200212300050.gBU0o24E043598@freefall.freebsd.org>
next in thread | raw e-mail | index | archive | help
The following reply was made to PR standards/44394; it has been noted by GNATS. From: Craig Rodrigues <rodrigc@attbi.com> To: freebsd-gnats-submit@freebsd.org Cc: Subject: Re: standards/44394: restrict qualifiers missing from sys/socket.h Date: Sun, 29 Dec 2002 19:42:40 -0500 --WIyZ46R2i8wDzkSu Content-Type: text/plain; charset=us-ascii Content-Disposition: inline Hi, Here is a followup patch which adds restrict qualifiers to accept(), getpeername(), getsockname(), getsockopt(), and recvfrom() as specified in the latest POSIX standard. After applying the patch, and before recompiling everything, you need to regenerate syscall.h, syscall.mk and sysproto.h by doing: cd /usr/src/sys/kern sh makesyscalls.sh syscalls.master Is the attached patch OK? -- Craig Rodrigues http://www.gis.net/~craigr rodrigc@attbi.com --WIyZ46R2i8wDzkSu Content-Type: text/plain; charset=us-ascii Content-Disposition: attachment; filename="socket-restrict.diff" Index: lib/libc/sys/accept.2 =================================================================== RCS file: /home/ncvs/src/lib/libc/sys/accept.2,v retrieving revision 1.26 diff -u -r1.26 accept.2 --- lib/libc/sys/accept.2 2002/12/19 09:40:24 1.26 +++ lib/libc/sys/accept.2 2002/12/29 23:59:40 @@ -44,7 +44,7 @@ .In sys/types.h .In sys/socket.h .Ft int -.Fn accept "int s" "struct sockaddr *addr" "socklen_t *addrlen" +.Fn accept "int s" "struct sockaddr * restrict addr" "socklen_t * restrict addrlen" .Sh DESCRIPTION The argument .Fa s Index: lib/libc/sys/getpeername.2 =================================================================== RCS file: /home/ncvs/src/lib/libc/sys/getpeername.2,v retrieving revision 1.21 diff -u -r1.21 getpeername.2 --- lib/libc/sys/getpeername.2 2002/12/19 09:40:24 1.21 +++ lib/libc/sys/getpeername.2 2002/12/29 23:59:40 @@ -44,7 +44,7 @@ .In sys/types.h .In sys/socket.h .Ft int -.Fn getpeername "int s" "struct sockaddr *name" "socklen_t *namelen" +.Fn getpeername "int s" "struct sockaddr * restrict name" "socklen_t * restrict namelen" .Sh DESCRIPTION The .Fn getpeername Index: lib/libc/sys/getsockname.2 =================================================================== RCS file: /home/ncvs/src/lib/libc/sys/getsockname.2,v retrieving revision 1.21 diff -u -r1.21 getsockname.2 --- lib/libc/sys/getsockname.2 2002/12/19 09:40:24 1.21 +++ lib/libc/sys/getsockname.2 2002/12/29 23:59:40 @@ -44,7 +44,7 @@ .In sys/types.h .In sys/socket.h .Ft int -.Fn getsockname "int s" "struct sockaddr *name" "socklen_t *namelen" +.Fn getsockname "int s" "struct sockaddr * restrict name" "socklen_t * restrict namelen" .Sh DESCRIPTION The .Fn getsockname Index: lib/libc/sys/getsockopt.2 =================================================================== RCS file: /home/ncvs/src/lib/libc/sys/getsockopt.2,v retrieving revision 1.28 diff -u -r1.28 getsockopt.2 --- lib/libc/sys/getsockopt.2 2002/12/19 09:40:25 1.28 +++ lib/libc/sys/getsockopt.2 2002/12/29 23:59:41 @@ -45,7 +45,7 @@ .In sys/types.h .In sys/socket.h .Ft int -.Fn getsockopt "int s" "int level" "int optname" "void *optval" "socklen_t *optlen" +.Fn getsockopt "int s" "int level" "int optname" "void * restrict optval" "socklen_t * restrict optlen" .Ft int .Fn setsockopt "int s" "int level" "int optname" "const void *optval" "socklen_t optlen" .Sh DESCRIPTION Index: lib/libc/sys/recv.2 =================================================================== RCS file: /home/ncvs/src/lib/libc/sys/recv.2,v retrieving revision 1.18 diff -u -r1.18 recv.2 --- lib/libc/sys/recv.2 2002/12/19 09:40:25 1.18 +++ lib/libc/sys/recv.2 2002/12/29 23:59:41 @@ -48,7 +48,7 @@ .Ft ssize_t .Fn recv "int s" "void *buf" "size_t len" "int flags" .Ft ssize_t -.Fn recvfrom "int s" "void *buf" "size_t len" "int flags" "struct sockaddr *from" "socklen_t *fromlen" +.Fn recvfrom "int s" "void * restrict buf" "size_t len" "int flags" "struct sockaddr * restrict from" "socklen_t * restrict fromlen" .Ft ssize_t .Fn recvmsg "int s" "struct msghdr *msg" "int flags" .Sh DESCRIPTION Index: sys/kern/syscalls.master =================================================================== RCS file: /home/ncvs/src/sys/kern/syscalls.master,v retrieving revision 1.138 diff -u -r1.138 syscalls.master --- sys/kern/syscalls.master 2002/12/15 19:17:56 1.138 +++ sys/kern/syscalls.master 2002/12/29 23:59:42 @@ -84,10 +84,11 @@ 27 MSTD BSD { int recvmsg(int s, struct msghdr *msg, int flags); } 28 MSTD BSD { int sendmsg(int s, caddr_t msg, int flags); } 29 MSTD BSD { int recvfrom(int s, caddr_t buf, size_t len, \ - int flags, caddr_t from, int *fromlenaddr); } -30 MSTD BSD { int accept(int s, caddr_t name, int *anamelen); } -31 MSTD BSD { int getpeername(int fdes, caddr_t asa, int *alen); } -32 MSTD BSD { int getsockname(int fdes, caddr_t asa, int *alen); } + int flags, struct sockaddr * __restrict from, \ + __socklen_t * __restrict fromlenaddr); } +30 MSTD BSD { int accept(int s, struct sockaddr * __restrict name, __socklen_t *__restrict anamelen); } +31 MSTD BSD { int getpeername(int fdes, struct sockaddr * __restrict asa, __socklen_t * __restrict alen); } +32 MSTD BSD { int getsockname(int fdes, struct sockaddr * __restrict asa, __socklen_t * __restrict alen); } 33 STD POSIX { int access(char *path, int flags); } 34 STD BSD { int chflags(char *path, int flags); } 35 STD BSD { int fchflags(int fd, int flags); } @@ -197,7 +198,8 @@ struct timezone *tzp); } 117 MSTD BSD { int getrusage(int who, struct rusage *rusage); } 118 MSTD BSD { int getsockopt(int s, int level, int name, \ - caddr_t val, int *avalsize); } + void * __restrict val, \ + __socklen_t * __restrict avalsize); } 119 UNIMPL NOHIDE resuba (BSD/OS 2.x) 120 MSTD BSD { int readv(int fd, struct iovec *iovp, u_int iovcnt); } 121 MSTD BSD { int writev(int fd, struct iovec *iovp, \ Index: sys/kern/uipc_syscalls.c =================================================================== RCS file: /home/ncvs/src/sys/kern/uipc_syscalls.c,v retrieving revision 1.133 diff -u -r1.133 uipc_syscalls.c --- sys/kern/uipc_syscalls.c 2002/12/23 22:46:47 1.133 +++ sys/kern/uipc_syscalls.c 2002/12/29 23:59:44 @@ -233,15 +235,16 @@ struct thread *td; register struct accept_args /* { int s; - caddr_t name; - int *anamelen; + struct sockaddr * __restrict name; + socklen_t * __restrict anamelen; } */ *uap; int compat; { struct filedesc *fdp; struct file *nfp = NULL; struct sockaddr *sa; - int namelen, error, s; + socklen_t namelen; + int error, s; struct socket *head, *so; int fd; u_int fflag; @@ -876,7 +879,8 @@ struct uio auio; register struct iovec *iov; register int i; - int len, error; + socklen_t len; + int error; struct mbuf *m, *control = 0; caddr_t ctlbuf; struct socket *so; @@ -925,7 +929,7 @@ (struct mbuf **)0, mp->msg_control ? &control : (struct mbuf **)0, &mp->msg_flags); if (error) { - if (auio.uio_resid != len && (error == ERESTART || + if (auio.uio_resid != (int)len && (error == ERESTART || error == EINTR || error == EWOULDBLOCK)) error = 0; } @@ -933,7 +937,7 @@ if (ktriov != NULL) { if (error == 0) { ktruio.uio_iov = ktriov; - ktruio.uio_resid = len - auio.uio_resid; + ktruio.uio_resid = (int)len - auio.uio_resid; ktrgenio(s, UIO_READ, &ktruio, error); } FREE(ktriov, M_TEMP); @@ -941,7 +945,7 @@ #endif if (error) goto out; - td->td_retval[0] = len - auio.uio_resid; + td->td_retval[0] = (int)len - auio.uio_resid; if (mp->msg_name) { len = mp->msg_namelen; if (len <= 0 || fromsa == 0) @@ -963,7 +967,7 @@ } mp->msg_namelen = len; if (namelenp && - (error = copyout(&len, namelenp, sizeof (int)))) { + (error = copyout(&len, namelenp, sizeof (socklen_t)))) { #ifdef COMPAT_OLDSOCK if (mp->msg_flags & MSG_COMPAT) error = 0; /* old recvfrom didn't check */ @@ -1038,8 +1042,8 @@ caddr_t buf; size_t len; int flags; - caddr_t from; - int *fromlenaddr; + struct sockaddr * __restrict from; + socklen_t * __restrict fromlenaddr; } */ *uap; { struct msghdr msg; @@ -1301,11 +1305,12 @@ int s; int level; int name; - caddr_t val; - int *avalsize; + void * __restrict val; + socklen_t * __restrict avalsize; } */ *uap; { - int valsize, error; + socklen_t valsize; + int error; struct socket *so; struct sockopt sopt; @@ -1354,14 +1359,15 @@ struct thread *td; register struct getsockname_args /* { int fdes; - caddr_t asa; - int *alen; + struct sockaddr * __restrict asa; + socklen_t * __restrict alen; } */ *uap; int compat; { struct socket *so; struct sockaddr *sa; - int len, error; + socklen_t len; + int error; mtx_lock(&Giant); if ((error = fgetsock(td, uap->fdes, &so, NULL)) != 0) @@ -1438,14 +1444,15 @@ struct thread *td; register struct getpeername_args /* { int fdes; - caddr_t asa; - int *alen; + struct sockaddr * __restrict asa; + socklen_t * __restrict alen; } */ *uap; int compat; { struct socket *so; struct sockaddr *sa; - int len, error; + socklen_t len; + int error; mtx_lock(&Giant); if ((error = fgetsock(td, uap->fdes, &so, NULL)) != 0) Index: sys/sys/socket.h =================================================================== RCS file: /home/ncvs/src/sys/sys/socket.h,v retrieving revision 1.70 diff -u -r1.70 socket.h --- sys/sys/socket.h 2002/12/28 22:17:29 1.70 +++ sys/sys/socket.h 2002/12/29 23:59:44 @@ -513,18 +513,15 @@ #include <sys/cdefs.h> __BEGIN_DECLS -/* - * XXX functions missing restrict type-qualifiers. - */ -int accept(int, struct sockaddr *, socklen_t *); +int accept(int, struct sockaddr * __restrict, socklen_t * __restrict); int bind(int, const struct sockaddr *, socklen_t); int connect(int, const struct sockaddr *, socklen_t); -int getpeername(int, struct sockaddr *, socklen_t *); -int getsockname(int, struct sockaddr *, socklen_t *); -int getsockopt(int, int, int, void *, socklen_t *); +int getpeername(int, struct sockaddr * __restrict, socklen_t * __restrict); +int getsockname(int, struct sockaddr * __restrict, socklen_t * __restrict); +int getsockopt(int, int, int, void * __restrict, socklen_t * __restrict); int listen(int, int); ssize_t recv(int, void *, size_t, int); -ssize_t recvfrom(int, void *, size_t, int, struct sockaddr *, socklen_t *); +ssize_t recvfrom(int, void *, size_t, int, struct sockaddr * __restrict, socklen_t * __restrict); ssize_t recvmsg(int, struct msghdr *, int); ssize_t send(int, const void *, size_t, int); ssize_t sendto(int, const void *, --WIyZ46R2i8wDzkSu-- To Unsubscribe: send mail to majordomo@FreeBSD.org with "unsubscribe freebsd-standards" in the body of the message
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?200212300050.gBU0o24E043598>