From 4f05201005b0679eb80208512d23ae806ce6b260 Mon Sep 17 00:00:00 2001 From: mbuhl Date: Sat, 3 Sep 2022 21:13:48 +0000 Subject: [PATCH] Make recvmmsg and sendmmsg look more alike. change the flag type to int like other flag parameters, NetBSD uses unsigned int, FreeBSD and Linux do int. OK bluhm@ --- sys/kern/init_sysent.c | 2 +- sys/kern/syscalls.c | 2 +- sys/kern/syscalls.master | 9 +++---- sys/kern/uipc_syscalls.c | 54 +++++++++++++++++++++------------------- sys/sys/socket.h | 7 +++--- sys/sys/syscall.h | 6 ++--- sys/sys/syscallargs.h | 6 ++--- 7 files changed, 44 insertions(+), 42 deletions(-) diff --git a/sys/kern/init_sysent.c b/sys/kern/init_sysent.c index ef8e59e225b..642881f1bf9 100644 --- a/sys/kern/init_sysent.c +++ b/sys/kern/init_sysent.c @@ -1,4 +1,4 @@ -/* $OpenBSD: init_sysent.c,v 1.247 2022/09/03 12:35:29 mbuhl Exp $ */ +/* $OpenBSD: init_sysent.c,v 1.248 2022/09/03 21:13:48 mbuhl Exp $ */ /* * System call switch table. diff --git a/sys/kern/syscalls.c b/sys/kern/syscalls.c index 9b4b152b49c..c41adedd22f 100644 --- a/sys/kern/syscalls.c +++ b/sys/kern/syscalls.c @@ -1,4 +1,4 @@ -/* $OpenBSD: syscalls.c,v 1.245 2022/09/03 12:35:29 mbuhl Exp $ */ +/* $OpenBSD: syscalls.c,v 1.246 2022/09/03 21:13:48 mbuhl Exp $ */ /* * System call names. diff --git a/sys/kern/syscalls.master b/sys/kern/syscalls.master index 9d88bf30dc1..63f3c65d57b 100644 --- a/sys/kern/syscalls.master +++ b/sys/kern/syscalls.master @@ -1,4 +1,4 @@ -; $OpenBSD: syscalls.master,v 1.231 2022/09/03 12:33:44 mbuhl Exp $ +; $OpenBSD: syscalls.master,v 1.232 2022/09/03 21:13:48 mbuhl Exp $ ; $NetBSD: syscalls.master,v 1.32 1996/04/23 10:24:21 mycroft Exp $ ; @(#)syscalls.master 8.2 (Berkeley) 1/13/94 @@ -245,11 +245,10 @@ 115 STD { int sys___realpath(const char *pathname, \ char *resolved); } 116 STD NOLOCK { int sys_recvmmsg(int s, struct mmsghdr *mmsg, \ - unsigned int vlen, unsigned int flags, \ + unsigned int vlen, int flags, \ struct timespec *timeout); } -117 STD NOLOCK { int sys_sendmmsg(int s, \ - struct mmsghdr *mmsg, unsigned int vlen, \ - unsigned int flags); } +117 STD NOLOCK { int sys_sendmmsg(int s, struct mmsghdr *mmsg,\ + unsigned int vlen, int flags); } 118 STD { int sys_getsockopt(int s, int level, int name, \ void *val, socklen_t *avalsize); } 119 STD { int sys_thrkill(pid_t tid, int signum, void *tcb); } diff --git a/sys/kern/uipc_syscalls.c b/sys/kern/uipc_syscalls.c index 02a36683b9f..ddb612a8043 100644 --- a/sys/kern/uipc_syscalls.c +++ b/sys/kern/uipc_syscalls.c @@ -1,4 +1,4 @@ -/* $OpenBSD: uipc_syscalls.c,v 1.203 2022/09/03 12:33:44 mbuhl Exp $ */ +/* $OpenBSD: uipc_syscalls.c,v 1.204 2022/09/03 21:13:48 mbuhl Exp $ */ /* $NetBSD: uipc_syscalls.c,v 1.19 1996/02/09 19:00:48 christos Exp $ */ /* @@ -612,14 +612,17 @@ sys_sendmmsg(struct proc *p, void *v, register_t *retval) syscallarg(int) s; syscallarg(struct mmsghdr *) mmsg; syscallarg(unsigned int) vlen; - syscallarg(unsigned int) flags; + syscallarg(int) flags; } */ *uap = v; struct mmsghdr mmsg, *mmsgp; struct iovec aiov[UIO_SMALLIOV], *iov = aiov, *uiov; size_t iovlen = UIO_SMALLIOV; register_t retsnd; unsigned int vlen, dgrams; - int error = 0; + int error = 0, flags, s; + + s = SCARG(uap, s); + flags = SCARG(uap, flags); /* Arbitrarily capped at 1024 datagrams. */ vlen = SCARG(uap, vlen); @@ -668,8 +671,7 @@ sys_sendmmsg(struct proc *p, void *v, register_t *retval) mmsg.msg_hdr.msg_iov = iov; mmsg.msg_hdr.msg_flags = 0; - error = sendit(p, SCARG(uap, s), &mmsg.msg_hdr, - SCARG(uap, flags), &retsnd); + error = sendit(p, s, &mmsg.msg_hdr, flags, &retsnd); if (error) break; @@ -686,9 +688,10 @@ sys_sendmmsg(struct proc *p, void *v, register_t *retval) *retval = dgrams; - if (dgrams) - return 0; - return error; + if (error && dgrams > 0) + error = 0; + + return (error); } int @@ -897,38 +900,34 @@ sys_recvmmsg(struct proc *p, void *v, register_t *retval) syscallarg(int) s; syscallarg(struct mmsghdr *) mmsg; syscallarg(unsigned int) vlen; - syscallarg(unsigned int) flags; + syscallarg(int) flags; syscallarg(struct timespec *) timeout; } */ *uap = v; struct mmsghdr mmsg, *mmsgp; - struct timespec ts, now; + struct timespec ts, now, *timeout; struct iovec aiov[UIO_SMALLIOV], *uiov, *iov = aiov; - struct file *fp; - struct socket *so; - struct timespec *timeout; size_t iovlen = UIO_SMALLIOV; register_t retrec; unsigned int vlen, dgrams; int error = 0, flags, s; - s = SCARG(uap, s); - if ((error = getsock(p, s, &fp))) - return (error); - so = (struct socket *)fp->f_data; - timeout = SCARG(uap, timeout); if (timeout != NULL) { error = copyin(timeout, &ts, sizeof(ts)); if (error) - return error; + return (error); #ifdef KTRACE if (KTRPOINT(p, KTR_STRUCT)) ktrreltimespec(p, &ts); #endif + if (!timespecisvalid(&ts)) + return (EINVAL); + getnanotime(&now); timespecadd(&now, &ts, &ts); } + s = SCARG(uap, s); flags = SCARG(uap, flags); /* Arbitrarily capped at 1024 datagrams. */ @@ -966,7 +965,7 @@ sys_recvmmsg(struct proc *p, void *v, register_t *retval) uiov = mmsg.msg_hdr.msg_iov; mmsg.msg_hdr.msg_iov = iov; - mmsg.msg_hdr.msg_flags = flags; + mmsg.msg_hdr.msg_flags = flags & ~MSG_WAITFORONE; error = recvit(p, s, &mmsg.msg_hdr, NULL, &retrec); if (error) { @@ -975,10 +974,8 @@ sys_recvmmsg(struct proc *p, void *v, register_t *retval) break; } - if (dgrams == 0 && flags & MSG_WAITFORONE) { - flags &= ~MSG_WAITFORONE; + if (flags & MSG_WAITFORONE) flags |= MSG_DONTWAIT; - } mmsg.msg_hdr.msg_iov = uiov; mmsg.msg_len = retrec; @@ -1016,11 +1013,18 @@ sys_recvmmsg(struct proc *p, void *v, register_t *retval) * will catch it next time. */ if (error && dgrams > 0) { - so->so_error = error; + struct file *fp; + struct socket *so; + + if (getsock(p, s, &fp) == 0) { + so = (struct socket *)fp->f_data; + so->so_error = error; + + FRELE(fp, p); + } error = 0; } - FRELE(fp, p); return (error); } diff --git a/sys/sys/socket.h b/sys/sys/socket.h index 06def618354..26c2a7bd1f5 100644 --- a/sys/sys/socket.h +++ b/sys/sys/socket.h @@ -1,4 +1,4 @@ -/* $OpenBSD: socket.h,v 1.104 2022/09/03 12:33:45 mbuhl Exp $ */ +/* $OpenBSD: socket.h,v 1.105 2022/09/03 21:13:48 mbuhl Exp $ */ /* $NetBSD: socket.h,v 1.14 1996/02/09 18:25:36 christos Exp $ */ /* @@ -573,13 +573,12 @@ 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 recvmsg(int, struct msghdr *, int); -int recvmmsg(int, struct mmsghdr *, unsigned int, unsigned int, - struct timespec *); +int recvmmsg(int, struct mmsghdr *, unsigned int, int, struct timespec *); ssize_t send(int, const void *, size_t, int); ssize_t sendto(int, const void *, size_t, int, const struct sockaddr *, socklen_t); ssize_t sendmsg(int, const struct msghdr *, int); -int sendmmsg(int, struct mmsghdr *, unsigned int, unsigned int); +int sendmmsg(int, struct mmsghdr *, unsigned int, int); int setsockopt(int, int, int, const void *, socklen_t); int shutdown(int, int); int sockatmark(int); diff --git a/sys/sys/syscall.h b/sys/sys/syscall.h index 9cbb16e8942..57d622faa65 100644 --- a/sys/sys/syscall.h +++ b/sys/sys/syscall.h @@ -1,4 +1,4 @@ -/* $OpenBSD: syscall.h,v 1.244 2022/09/03 12:35:29 mbuhl Exp $ */ +/* $OpenBSD: syscall.h,v 1.245 2022/09/03 21:13:48 mbuhl Exp $ */ /* * System call numbers. @@ -352,10 +352,10 @@ /* syscall: "__realpath" ret: "int" args: "const char *" "char *" */ #define SYS___realpath 115 -/* syscall: "recvmmsg" ret: "int" args: "int" "struct mmsghdr *" "unsigned int" "unsigned int" "struct timespec *" */ +/* syscall: "recvmmsg" ret: "int" args: "int" "struct mmsghdr *" "unsigned int" "int" "struct timespec *" */ #define SYS_recvmmsg 116 -/* syscall: "sendmmsg" ret: "int" args: "int" "struct mmsghdr *" "unsigned int" "unsigned int" */ +/* syscall: "sendmmsg" ret: "int" args: "int" "struct mmsghdr *" "unsigned int" "int" */ #define SYS_sendmmsg 117 /* syscall: "getsockopt" ret: "int" args: "int" "int" "int" "void *" "socklen_t *" */ diff --git a/sys/sys/syscallargs.h b/sys/sys/syscallargs.h index 6b01e862e69..709eccba5ad 100644 --- a/sys/sys/syscallargs.h +++ b/sys/sys/syscallargs.h @@ -1,4 +1,4 @@ -/* $OpenBSD: syscallargs.h,v 1.247 2022/09/03 12:35:29 mbuhl Exp $ */ +/* $OpenBSD: syscallargs.h,v 1.248 2022/09/03 21:13:48 mbuhl Exp $ */ /* * System call argument lists. @@ -599,7 +599,7 @@ struct sys_recvmmsg_args { syscallarg(int) s; syscallarg(struct mmsghdr *) mmsg; syscallarg(unsigned int) vlen; - syscallarg(unsigned int) flags; + syscallarg(int) flags; syscallarg(struct timespec *) timeout; }; @@ -607,7 +607,7 @@ struct sys_sendmmsg_args { syscallarg(int) s; syscallarg(struct mmsghdr *) mmsg; syscallarg(unsigned int) vlen; - syscallarg(unsigned int) flags; + syscallarg(int) flags; }; struct sys_getsockopt_args { -- 2.20.1