diff options
author | Lennart Poettering <lennart@poettering.net> | 2021-02-25 16:56:07 +0100 |
---|---|---|
committer | Lennart Poettering <lennart@poettering.net> | 2021-02-26 09:21:51 +0100 |
commit | 420297c9e1bf13757394f7f4dd0f312ba953466d (patch) | |
tree | b70d19d8f2c6aa6c6be68800409662d5223b99d3 | |
parent | Merge pull request #18797 from keszybz/trivial-cleanups (diff) | |
download | systemd-420297c9e1bf13757394f7f4dd0f312ba953466d.tar.xz systemd-420297c9e1bf13757394f7f4dd0f312ba953466d.zip |
missing_syscall: add epoll_pwait2() wrapper
-rw-r--r-- | meson.build | 2 | ||||
-rw-r--r-- | src/basic/missing_syscall.h | 43 | ||||
-rw-r--r-- | src/basic/missing_syscall_def.h | 55 | ||||
-rw-r--r-- | src/basic/missing_syscalls.py | 3 |
4 files changed, 102 insertions, 1 deletions
diff --git a/meson.build b/meson.build index 2c5150bfc1..8fbfd5fc49 100644 --- a/meson.build +++ b/meson.build @@ -549,6 +549,7 @@ foreach ident : [ ['mallinfo', '''#include <malloc.h>'''], ['execveat', '''#include <unistd.h>'''], ['close_range', '''#include <unistd.h>'''], + ['epoll_pwait2', '''#include <sys/epoll.h>'''], ] have = cc.has_function(ident[0], prefix : ident[1], args : '-D_GNU_SOURCE') @@ -672,6 +673,7 @@ foreach header : ['crypt.h', 'sys/auxv.h', 'valgrind/memcheck.h', 'valgrind/valgrind.h', + 'linux/time_types.h', ] conf.set10('HAVE_' + header.underscorify().to_upper(), diff --git a/src/basic/missing_syscall.h b/src/basic/missing_syscall.h index 52e9d5dea4..1384324804 100644 --- a/src/basic/missing_syscall.h +++ b/src/basic/missing_syscall.h @@ -5,6 +5,11 @@ #include <errno.h> #include <fcntl.h> +#if HAVE_LINUX_TIME_TYPES_H +/* This header defines __kernel_timespec for us, but is only available since Linux 5.1, hence conditionally + * include this. */ +#include <linux/time_types.h> +#endif #include <signal.h> #include <sys/syscall.h> #include <sys/types.h> @@ -382,3 +387,41 @@ static inline int missing_close_range(int first_fd, int end_fd, unsigned flags) # define close_range missing_close_range #endif + +/* ======================================================================= */ + +#if !HAVE_EPOLL_PWAIT2 + +/* Defined to be equivalent to the kernel's _NSIG_WORDS, i.e. the size of the array of longs that is + * encapsulated by sigset_t. */ +#define KERNEL_NSIG_WORDS (64 / (sizeof(long) * 8)) +#define KERNEL_NSIG_BYTES (KERNEL_NSIG_WORDS * sizeof(long)) + +struct epoll_event; + +static inline int missing_epoll_pwait2( + int fd, + struct epoll_event *events, + int maxevents, + const struct timespec *timeout, + const sigset_t *sigset) { + +# if defined(__NR_epoll_pwait2) && HAVE_LINUX_TIME_TYPES_H + if (timeout) { + /* Convert from userspace timespec to kernel timespec */ + struct __kernel_timespec ts = { + .tv_sec = timeout->tv_sec, + .tv_nsec = timeout->tv_nsec, + }; + + return syscall(__NR_epoll_pwait2, fd, events, maxevents, &ts, sigset, sigset ? KERNEL_NSIG_BYTES : 0); + } else + return syscall(__NR_epoll_pwait2, fd, events, maxevents, NULL, sigset, sigset ? KERNEL_NSIG_BYTES : 0); +# else + errno = ENOSYS; + return -1; +# endif +} + +# define epoll_pwait2 missing_epoll_pwait2 +#endif diff --git a/src/basic/missing_syscall_def.h b/src/basic/missing_syscall_def.h index 44df37b37e..a66977cfec 100644 --- a/src/basic/missing_syscall_def.h +++ b/src/basic/missing_syscall_def.h @@ -673,3 +673,58 @@ assert_cc(__NR_statx == systemd_NR_statx); # endif #endif +#ifndef __IGNORE_epoll_pwait2 +# if defined(__aarch64__) +# define systemd_NR_epoll_pwait2 441 +# elif defined(__alpha__) +# define systemd_NR_epoll_pwait2 551 +# elif defined(__arc__) || defined(__tilegx__) +# define systemd_NR_epoll_pwait2 441 +# elif defined(__arm__) +# define systemd_NR_epoll_pwait2 441 +# elif defined(__i386__) +# define systemd_NR_epoll_pwait2 441 +# elif defined(__ia64__) +# define systemd_NR_epoll_pwait2 1465 +# elif defined(__m68k__) +# define systemd_NR_epoll_pwait2 441 +# elif defined(_MIPS_SIM) +# if _MIPS_SIM == _MIPS_SIM_ABI32 +# define systemd_NR_epoll_pwait2 4441 +# elif _MIPS_SIM == _MIPS_SIM_NABI32 +# define systemd_NR_epoll_pwait2 6441 +# elif _MIPS_SIM == _MIPS_SIM_ABI64 +# define systemd_NR_epoll_pwait2 5441 +# else +# error "Unknown MIPS ABI" +# endif +# elif defined(__powerpc__) +# define systemd_NR_epoll_pwait2 441 +# elif defined(__s390__) +# define systemd_NR_epoll_pwait2 441 +# elif defined(__sparc__) +# define systemd_NR_epoll_pwait2 441 +# elif defined(__x86_64__) +# if defined(__ILP32__) +# define systemd_NR_epoll_pwait2 (441 | /* __X32_SYSCALL_BIT */ 0x40000000) +# else +# define systemd_NR_epoll_pwait2 441 +# endif +# else +# warning "epoll_pwait2() syscall number is unknown for your architecture" +# endif + +/* may be an (invalid) negative number due to libseccomp, see PR 13319 */ +# if defined __NR_epoll_pwait2 && __NR_epoll_pwait2 >= 0 +# if defined systemd_NR_epoll_pwait2 +assert_cc(__NR_epoll_pwait2 == systemd_NR_epoll_pwait2); +# endif +# else +# if defined __NR_epoll_pwait2 +# undef __NR_epoll_pwait2 +# endif +# if defined systemd_NR_epoll_pwait2 && systemd_NR_epoll_pwait2 >= 0 +# define __NR_epoll_pwait2 systemd_NR_epoll_pwait2 +# endif +# endif +#endif diff --git a/src/basic/missing_syscalls.py b/src/basic/missing_syscalls.py index 746fbf4a26..650f62d1d4 100644 --- a/src/basic/missing_syscalls.py +++ b/src/basic/missing_syscalls.py @@ -17,7 +17,8 @@ SYSCALLS = [ 'pkey_mprotect', 'renameat2', 'setns', - 'statx'] + 'statx', + 'epoll_pwait2'] def dictify(f): def wrap(*args, **kwargs): |