From 4d055d8a8310c630917a9a40d3f8483d2f653827 Mon Sep 17 00:00:00 2001 From: thorpej Date: Mon, 20 Sep 2021 00:09:01 +0000 Subject: [PATCH] Add the eventfd system calls to COMPAT_LINUX and COMPAT_LINUX32. --- sys/compat/linux/arch/alpha/syscalls.master | 7 ++- sys/compat/linux/arch/amd64/syscalls.master | 7 ++- sys/compat/linux/arch/arm/syscalls.master | 7 ++- sys/compat/linux/arch/i386/syscalls.master | 7 ++- sys/compat/linux/arch/m68k/syscalls.master | 7 ++- sys/compat/linux/arch/mips/syscalls.master | 7 ++- sys/compat/linux/arch/powerpc/syscalls.master | 7 ++- sys/compat/linux/common/linux_misc.c | 56 ++++++++++++++++++- sys/compat/linux32/arch/amd64/syscalls.master | 7 ++- sys/compat/linux32/common/linux32_misc.c | 34 ++++++++++- 10 files changed, 118 insertions(+), 28 deletions(-) diff --git a/sys/compat/linux/arch/alpha/syscalls.master b/sys/compat/linux/arch/alpha/syscalls.master index 51623335a01c..8fa2ec2adaec 100644 --- a/sys/compat/linux/arch/alpha/syscalls.master +++ b/sys/compat/linux/arch/alpha/syscalls.master @@ -1,4 +1,4 @@ - $NetBSD: syscalls.master,v 1.99 2021/09/19 23:51:36 thorpej Exp $ + $NetBSD: syscalls.master,v 1.100 2021/09/20 00:09:01 thorpej Exp $ ; ; @(#)syscalls.master 8.1 (Berkeley) 7/19/93 @@ -764,7 +764,7 @@ struct linux_timespec *times, int flag); } 476 UNIMPL signalfd 477 UNIMPL timerfd -478 UNIMPL eventfd +478 STD { int|linux_sys||eventfd(unsigned int initval); } 479 STD { int|linux_sys||recvmmsg(int s, \ struct linux_mmsghdr *msgvec, unsigned int vlen, \ unsigned int flags, struct timespec *timeout); } @@ -778,7 +778,8 @@ 483 STD { int|linux_sys||timerfd_gettime(int fd, \ struct linux_itimerspec *tim); } 484 UNIMPL signalfd4 -485 UNIMPL eventfd2 +485 STD { int|linux_sys||eventfd2(unsigned int initval, \ + int flags); } 486 UNIMPL epoll_create1 487 STD { int|linux_sys||dup3(int from, int to, int flags); } 488 STD { int|linux_sys||pipe2(int *pfds, int flags); } diff --git a/sys/compat/linux/arch/amd64/syscalls.master b/sys/compat/linux/arch/amd64/syscalls.master index 9a7e59ad071f..328a3faddfe2 100644 --- a/sys/compat/linux/arch/amd64/syscalls.master +++ b/sys/compat/linux/arch/amd64/syscalls.master @@ -1,4 +1,4 @@ - $NetBSD: syscalls.master,v 1.64 2021/09/19 23:51:36 thorpej Exp $ + $NetBSD: syscalls.master,v 1.65 2021/09/20 00:09:01 thorpej Exp $ ; @(#)syscalls.master 8.1 (Berkeley) 7/19/93 @@ -521,7 +521,7 @@ 282 UNIMPL signalfd 283 STD { int|linux_sys||timerfd_create(clockid_t clock_id, \ int flags); } -284 UNIMPL eventfd +284 STD { int|linux_sys||eventfd(unsigned int initval); } 285 STD { int|linux_sys||fallocate(int fd, int mode, \ off_t offset, off_t len); } 286 STD { int|linux_sys||timerfd_settime(int fd, int flags, \ @@ -533,7 +533,8 @@ struct osockaddr *name, \ int *anamelen, int flags); } 289 UNIMPL signalfd4 -290 UNIMPL eventfd2 +290 STD { int|linux_sys||eventfd2(unsigned int initval, \ + int flags); } 291 UNIMPL epoll_create1 292 STD { int|linux_sys||dup3(int from, int to, int flags); } 293 STD { int|linux_sys||pipe2(int *pfds, int flags); } diff --git a/sys/compat/linux/arch/arm/syscalls.master b/sys/compat/linux/arch/arm/syscalls.master index 2256d8e0d067..6e28818057db 100644 --- a/sys/compat/linux/arch/arm/syscalls.master +++ b/sys/compat/linux/arch/arm/syscalls.master @@ -1,4 +1,4 @@ - $NetBSD: syscalls.master,v 1.71 2021/09/19 23:51:36 thorpej Exp $ + $NetBSD: syscalls.master,v 1.72 2021/09/20 00:09:01 thorpej Exp $ ; Derived from sys/compat/linux/arch/*/syscalls.master ; and from Linux 2.4.12 arch/arm/kernel/calls.S @@ -564,7 +564,7 @@ 349 UNIMPL signalfd 350 STD { int|linux_sys||timerfd_create(clockid_t clock_id, \ int flags); } -351 UNIMPL eventfd +351 STD { int|linux_sys||eventfd(unsigned int initval); } 352 STD { int|linux_sys||fallocate(int fd, int mode, \ off_t offset, off_t len); } 353 STD { int|linux_sys||timerfd_settime(int fd, int flags, \ @@ -573,7 +573,8 @@ 354 STD { int|linux_sys||timerfd_gettime(int fd, \ struct linux_itimerspec *tim); } 355 UNIMPL signalfd4 -356 UNIMPL eventfd2 +356 STD { int|linux_sys||eventfd2(unsigned int initval, \ + int flags); } 357 UNIMPL epoll_create1 358 STD { int|linux_sys||dup3(int from, int to, int flags); } 359 STD { int|linux_sys||pipe2(int *pfds, int flags); } diff --git a/sys/compat/linux/arch/i386/syscalls.master b/sys/compat/linux/arch/i386/syscalls.master index ccbb825750a0..9458f6e6c600 100644 --- a/sys/compat/linux/arch/i386/syscalls.master +++ b/sys/compat/linux/arch/i386/syscalls.master @@ -1,4 +1,4 @@ - $NetBSD: syscalls.master,v 1.126 2021/09/19 23:51:36 thorpej Exp $ + $NetBSD: syscalls.master,v 1.127 2021/09/20 00:09:01 thorpej Exp $ ; @(#)syscalls.master 8.1 (Berkeley) 7/19/93 @@ -531,7 +531,7 @@ 321 UNIMPL signalfd 322 STD { int|linux_sys||timerfd_create(clockid_t clock_id, \ int flags); } -323 UNIMPL eventfd +323 STD { int|linux_sys||eventfd(unsigned int initval); } 324 STD { int|linux_sys||fallocate(int fd, int mode, \ off_t offset, off_t len); } 325 STD { int|linux_sys||timerfd_settime(int fd, int flags, \ @@ -540,7 +540,8 @@ 326 STD { int|linux_sys||timerfd_gettime(int fd, \ struct linux_itimerspec *tim); } 327 UNIMPL signalfd4 -328 UNIMPL eventfd2 +328 STD { int|linux_sys||eventfd2(unsigned int initval, \ + int flags); } 329 UNIMPL epoll_create1 330 STD { int|linux_sys||dup3(int from, int to, int flags); } 331 STD { int|linux_sys||pipe2( int *pfds, int flags); } diff --git a/sys/compat/linux/arch/m68k/syscalls.master b/sys/compat/linux/arch/m68k/syscalls.master index 73e0855dba13..f68d254ffe73 100644 --- a/sys/compat/linux/arch/m68k/syscalls.master +++ b/sys/compat/linux/arch/m68k/syscalls.master @@ -1,4 +1,4 @@ - $NetBSD: syscalls.master,v 1.97 2021/09/19 23:51:36 thorpej Exp $ + $NetBSD: syscalls.master,v 1.98 2021/09/20 00:09:01 thorpej Exp $ ; @(#)syscalls.master 8.1 (Berkeley) 7/19/93 @@ -549,7 +549,7 @@ 317 UNIMPL signalfd 318 STD { int|linux_sys||timerfd_create(clockid_t clock_id, \ int flags); } -319 UNIMPL eventfd +319 STD { int|linux_sys||eventfd(unsigned int initval); } 320 STD { int|linux_sys||fallocate(int fd, int mode, \ off_t offset, off_t len); } 321 STD { int|linux_sys||timerfd_settime(int fd, int flags, \ @@ -558,7 +558,8 @@ 322 STD { int|linux_sys||timerfd_gettime(int fd, \ struct linux_itimerspec *tim); } 323 UNIMPL signalfd4 -324 UNIMPL eventfd2 +324 STD { int|linux_sys||eventfd2(unsigned int initval, \ + int flags); } 325 UNIMPL epoll_create1 326 STD { int|linux_sys||dup3(int from, int to, int flags); } 327 STD { int|linux_sys||pipe2(int *pfds, int flags); } diff --git a/sys/compat/linux/arch/mips/syscalls.master b/sys/compat/linux/arch/mips/syscalls.master index 283463f0c5ad..fb4f0edf143c 100644 --- a/sys/compat/linux/arch/mips/syscalls.master +++ b/sys/compat/linux/arch/mips/syscalls.master @@ -1,4 +1,4 @@ - $NetBSD: syscalls.master,v 1.70 2021/09/19 23:51:37 thorpej Exp $ + $NetBSD: syscalls.master,v 1.71 2021/09/20 00:09:01 thorpej Exp $ ; @(#)syscalls.master 8.1 (Berkeley) 7/19/93 @@ -536,7 +536,7 @@ struct linux_timespec *times, int flag); } 317 UNIMPL signalfd 318 UNIMPL timerfd -319 UNIMPL eventfd +319 STD { int|linux_sys||eventfd(unsigned int initval); } 320 STD { int|linux_sys||fallocate(int fd, int mode, \ off_t offset, off_t len); } 321 STD { int|linux_sys||timerfd_create(clockid_t clock_id, \ @@ -547,7 +547,8 @@ const struct linux_itimerspec *tim, \ struct linux_itimerspec *otim); } 324 UNIMPL signalfd4 -325 UNIMPL eventfd2 +325 STD { int|linux_sys||eventfd2(unsigned int initval, \ + int flags); } 326 UNIMPL epoll_create1 327 STD { int|linux_sys||dup3(int from, int to, int flags); } 328 STD { int|linux_sys||pipe2(int *pfds, int flags); } diff --git a/sys/compat/linux/arch/powerpc/syscalls.master b/sys/compat/linux/arch/powerpc/syscalls.master index 783cb2ce84be..7bf500f0bbd8 100644 --- a/sys/compat/linux/arch/powerpc/syscalls.master +++ b/sys/compat/linux/arch/powerpc/syscalls.master @@ -1,4 +1,4 @@ - $NetBSD: syscalls.master,v 1.76 2021/09/19 23:51:37 thorpej Exp $ + $NetBSD: syscalls.master,v 1.77 2021/09/20 00:09:01 thorpej Exp $ ; @(#)syscalls.master 8.1 (Berkeley) 7/19/93 @@ -535,7 +535,7 @@ 305 UNIMPL signalfd 306 STD { int|linux_sys||timerfd_create(clockid_t clock_id, \ int flags); } -307 UNIMPL eventfd +307 STD { int|linux_sys||eventfd(unsigned int initval); } 308 UNIMPL sync_file_range2 309 STD { int|linux_sys||fallocate(int fd, int mode, \ off_t offset, off_t len); } @@ -546,7 +546,8 @@ 312 STD { int|linux_sys||timerfd_gettime(int fd, \ struct linux_itimerspec *tim); } 313 UNIMPL signalfd4 -314 UNIMPL eventfd2 +314 STD { int|linux_sys||eventfd2(unsigned int initval, \ + int flags); } 315 UNIMPL epoll_create1 316 STD { int|linux_sys||dup3(int from, int to, int flags); } 317 STD { int|linux_sys||pipe2(int *pfds, int flags); } diff --git a/sys/compat/linux/common/linux_misc.c b/sys/compat/linux/common/linux_misc.c index bb05299d4c0d..d282226b950c 100644 --- a/sys/compat/linux/common/linux_misc.c +++ b/sys/compat/linux/common/linux_misc.c @@ -1,4 +1,4 @@ -/* $NetBSD: linux_misc.c,v 1.252 2021/09/07 11:43:04 riastradh Exp $ */ +/* $NetBSD: linux_misc.c,v 1.253 2021/09/20 00:09:02 thorpej Exp $ */ /*- * Copyright (c) 1995, 1998, 1999, 2008 The NetBSD Foundation, Inc. @@ -57,13 +57,14 @@ */ #include -__KERNEL_RCSID(0, "$NetBSD: linux_misc.c,v 1.252 2021/09/07 11:43:04 riastradh Exp $"); +__KERNEL_RCSID(0, "$NetBSD: linux_misc.c,v 1.253 2021/09/20 00:09:02 thorpej Exp $"); #include #include #include #include #include +#include #include #include #include @@ -1583,3 +1584,54 @@ linux_do_futex(int *uaddr, int op, int val, struct timespec *timeout, return do_futex(uaddr, op & ~FUTEX_PRIVATE_FLAG, val, timeout, uaddr2, val2, val3, retval); } + +#define LINUX_EFD_SEMAPHORE 0x0001 +#define LINUX_EFD_CLOEXEC LINUX_O_CLOEXEC +#define LINUX_EFD_NONBLOCK LINUX_O_NONBLOCK + +static int +linux_do_eventfd2(struct lwp *l, unsigned int initval, int flags, + register_t *retval) +{ + int nflags = 0; + + if (flags & ~(LINUX_EFD_SEMAPHORE | LINUX_EFD_CLOEXEC | + LINUX_EFD_NONBLOCK)) { + return EINVAL; + } + if (flags & LINUX_EFD_SEMAPHORE) { + nflags |= EFD_SEMAPHORE; + } + if (flags & LINUX_EFD_CLOEXEC) { + nflags |= EFD_CLOEXEC; + } + if (flags & LINUX_EFD_NONBLOCK) { + nflags |= EFD_NONBLOCK; + } + + return do_eventfd(l, initval, nflags, retval); +} + +int +linux_sys_eventfd(struct lwp *l, const struct linux_sys_eventfd_args *uap, + register_t *retval) +{ + /* { + syscallarg(unsigned int) initval; + } */ + + return linux_do_eventfd2(l, SCARG(uap, initval), 0, retval); +} + +int +linux_sys_eventfd2(struct lwp *l, const struct linux_sys_eventfd2_args *uap, + register_t *retval) +{ + /* { + syscallarg(unsigned int) initval; + syscallarg(int) flags; + } */ + + return linux_do_eventfd2(l, SCARG(uap, initval), SCARG(uap, flags), + retval); +} diff --git a/sys/compat/linux32/arch/amd64/syscalls.master b/sys/compat/linux32/arch/amd64/syscalls.master index 55cf85bcfb4f..58bba2f62730 100644 --- a/sys/compat/linux32/arch/amd64/syscalls.master +++ b/sys/compat/linux32/arch/amd64/syscalls.master @@ -1,4 +1,4 @@ - $NetBSD: syscalls.master,v 1.73 2021/09/19 23:51:37 thorpej Exp $ + $NetBSD: syscalls.master,v 1.74 2021/09/20 00:09:02 thorpej Exp $ ; NetBSD i386 COMPAT_LINUX32 system call name/number "master" file. ; (See syscalls.conf to see what it is processed into.) @@ -552,7 +552,7 @@ 321 UNIMPL signalfd 322 NOARGS { int|linux_sys||timerfd_create(clockid_t clock_id, \ int flags); } -323 UNIMPL eventfd +323 STD { int|linux32_sys||eventfd(unsigned int initval); } 324 STD { int|linux32_sys||fallocate(int fd, int mode, \ off_t offset, off_t len); } 325 STD { int|linux32_sys||timerfd_settime(int fd, int flags, \ @@ -561,7 +561,8 @@ 326 STD { int|linux32_sys||timerfd_gettime(int fd, \ struct linux32_itimerspec *tim); } 327 UNIMPL signalfd4 -328 UNIMPL eventfd2 +328 STD { int|linux32_sys||eventfd2(unsigned int initval, \ + int flags); } 329 UNIMPL epoll_create1 330 STD { int|linux32_sys||dup3(int from, int to, int flags); } 331 STD { int|linux32_sys||pipe2(netbsd32_intp fd, int flags); } diff --git a/sys/compat/linux32/common/linux32_misc.c b/sys/compat/linux32/common/linux32_misc.c index 9441d9289fae..82f92e022e79 100644 --- a/sys/compat/linux32/common/linux32_misc.c +++ b/sys/compat/linux32/common/linux32_misc.c @@ -1,4 +1,4 @@ -/* $NetBSD: linux32_misc.c,v 1.31 2021/09/19 22:32:45 thorpej Exp $ */ +/* $NetBSD: linux32_misc.c,v 1.32 2021/09/20 00:09:02 thorpej Exp $ */ /*- * Copyright (c) 1995, 1998, 1999 The NetBSD Foundation, Inc. @@ -32,7 +32,7 @@ */ #include -__KERNEL_RCSID(0, "$NetBSD: linux32_misc.c,v 1.31 2021/09/19 22:32:45 thorpej Exp $"); +__KERNEL_RCSID(0, "$NetBSD: linux32_misc.c,v 1.32 2021/09/20 00:09:02 thorpej Exp $"); #include #include @@ -350,3 +350,33 @@ linux32_sys_ppoll(struct lwp *l, const struct linux32_sys_ppoll_args *uap, return pollcommon(retval, SCARG_P32(uap, fds), SCARG(uap, nfds), ts, sigmask); } + +int +linux32_sys_eventfd(struct lwp *l, const struct linux32_sys_eventfd_args *uap, + register_t *retval) +{ + /* { + syscallarg(unsigned int) initval; + } */ + struct linux_sys_eventfd_args ua; + + NETBSD32TO64_UAP(initval); + + return linux_sys_eventfd(l, &ua, retval); +} + +int +linux32_sys_eventfd2(struct lwp *l, const struct linux32_sys_eventfd2_args *uap, + register_t *retval) +{ + /* { + syscallarg(unsigned int) initval; + syscallarg(int) flags; + } */ + struct linux_sys_eventfd2_args ua; + + NETBSD32TO64_UAP(initval); + NETBSD32TO64_UAP(flags); + + return linux_sys_eventfd2(l, &ua, retval); +}