]> git.ipfire.org Git - thirdparty/glibc.git/commitdiff
Linux: Add epoll_pwait2 (BZ #27359)
authorAdhemerval Zanella <adhemerval.zanella@linaro.org>
Wed, 12 Jan 2022 14:31:53 +0000 (11:31 -0300)
committerAdhemerval Zanella <adhemerval.zanella@linaro.org>
Mon, 17 Jan 2022 17:34:54 +0000 (14:34 -0300)
It is similar to epoll_wait, with the difference the timeout has
nanosecond resoluting by using struct timespec instead of int.

Although Linux interface only provides 64 bit time_t support, old
32 bit interface is also provided (so keep in sync with current
practice and to no force opt-in on 64 bit time_t).

Checked on x86_64-linux-gnu and i686-linux-gnu.

Reviewed-by: Florian Weimer <fweimer@redhat.com>
41 files changed:
NEWS
include/sys/epoll.h
sysdeps/unix/sysv/linux/Makefile
sysdeps/unix/sysv/linux/Versions
sysdeps/unix/sysv/linux/aarch64/libc.abilist
sysdeps/unix/sysv/linux/alpha/libc.abilist
sysdeps/unix/sysv/linux/arc/libc.abilist
sysdeps/unix/sysv/linux/arm/be/libc.abilist
sysdeps/unix/sysv/linux/arm/le/libc.abilist
sysdeps/unix/sysv/linux/csky/libc.abilist
sysdeps/unix/sysv/linux/epoll_pwait2.c [new file with mode: 0644]
sysdeps/unix/sysv/linux/hppa/libc.abilist
sysdeps/unix/sysv/linux/i386/libc.abilist
sysdeps/unix/sysv/linux/ia64/libc.abilist
sysdeps/unix/sysv/linux/m68k/coldfire/libc.abilist
sysdeps/unix/sysv/linux/m68k/m680x0/libc.abilist
sysdeps/unix/sysv/linux/microblaze/be/libc.abilist
sysdeps/unix/sysv/linux/microblaze/le/libc.abilist
sysdeps/unix/sysv/linux/mips/mips32/fpu/libc.abilist
sysdeps/unix/sysv/linux/mips/mips32/nofpu/libc.abilist
sysdeps/unix/sysv/linux/mips/mips64/n32/libc.abilist
sysdeps/unix/sysv/linux/mips/mips64/n64/libc.abilist
sysdeps/unix/sysv/linux/nios2/libc.abilist
sysdeps/unix/sysv/linux/or1k/libc.abilist
sysdeps/unix/sysv/linux/powerpc/powerpc32/fpu/libc.abilist
sysdeps/unix/sysv/linux/powerpc/powerpc32/nofpu/libc.abilist
sysdeps/unix/sysv/linux/powerpc/powerpc64/be/libc.abilist
sysdeps/unix/sysv/linux/powerpc/powerpc64/le/libc.abilist
sysdeps/unix/sysv/linux/riscv/rv32/libc.abilist
sysdeps/unix/sysv/linux/riscv/rv64/libc.abilist
sysdeps/unix/sysv/linux/s390/s390-32/libc.abilist
sysdeps/unix/sysv/linux/s390/s390-64/libc.abilist
sysdeps/unix/sysv/linux/sh/be/libc.abilist
sysdeps/unix/sysv/linux/sh/le/libc.abilist
sysdeps/unix/sysv/linux/sparc/sparc32/libc.abilist
sysdeps/unix/sysv/linux/sparc/sparc64/libc.abilist
sysdeps/unix/sysv/linux/sys/epoll.h
sysdeps/unix/sysv/linux/tst-epoll-time64.c [new file with mode: 0644]
sysdeps/unix/sysv/linux/tst-epoll.c [new file with mode: 0644]
sysdeps/unix/sysv/linux/x86_64/64/libc.abilist
sysdeps/unix/sysv/linux/x86_64/x32/libc.abilist

diff --git a/NEWS b/NEWS
index 38802f0673da017d3c059bdf88f696c401122dd2..6ed9fa97878cdc12aa7b3a36e3f90243a1e491ff 100644 (file)
--- a/NEWS
+++ b/NEWS
@@ -126,6 +126,9 @@ Major new features:
   checks, this can help to ensure that proper diagnostics are printed if
   the dynamic loader runs on an incompatible CPU.
 
+* On Linux, the epoll_pwait2 function has been added.  It is similar to
+  epoll_wait with the difference the timeout has nanoseconds resolution.
+
 Deprecated and removed features, and other changes affecting compatibility:
 
 * On x86-64, the LD_PREFER_MAP_32BIT_EXEC environment variable support
index 86e0a54e62a5628b078ddd9ae757acb4f625f773..8049381a269956ce354dcb8977a5fef1ba5e0646 100644 (file)
@@ -4,6 +4,14 @@
 # ifndef _ISOMAC
 
 libc_hidden_proto (epoll_pwait)
+#if __TIMESIZE == 64
+# define __epoll_pwait2_time64 epoll_pwait2
+#else
+extern int __epoll_pwait2_time64 (int fd, struct epoll_event *ev, int maxev,
+                                 const struct __timespec64 *tmo,
+                                 const sigset_t *s);
+libc_hidden_proto (__epoll_pwait2_time64)
+#endif
 
 # endif /* !_ISOMAC */
 #endif
index 61acc1987d4a60ffa396c955214e0f8d4599e315..85fc8cbf7566314874d316f93e5f1421f36f46b8 100644 (file)
@@ -55,7 +55,7 @@ endif
 
 ifeq ($(subdir),misc)
 sysdep_routines += adjtimex clone umount umount2 readahead sysctl \
-                  setfsuid setfsgid epoll_pwait signalfd \
+                  setfsuid setfsgid epoll_pwait epoll_pwait2 signalfd \
                   eventfd eventfd_read eventfd_write prlimit prlimit64 \
                   personality epoll_wait tee vmsplice splice \
                   open_by_handle_at mlock2 pkey_mprotect pkey_set pkey_get \
@@ -125,6 +125,7 @@ tests += tst-clone tst-clone2 tst-clone3 tst-fanotify tst-personality \
         tst-ntp_gettimex tst-sigtimedwait tst-misalign-clone \
   tst-prctl \
   tst-scm_rights \
+  tst-epoll \
   # tests
 
 # Test for the symbol version of fcntl that was replaced in glibc 2.28.
@@ -146,6 +147,7 @@ endif
 tests-time64 += \
   tst-adjtimex-time64 \
   tst-clock_adjtime-time64 \
+  tst-epoll-time64 \
   tst-ntp_adjtime-time64 \
   tst-ntp_gettime-time64 \
   tst-ntp_gettimex-time64 \
index 3f8809a1581f27d042b2526d2250c5e0e2898770..ded087f30ea953fc0312aaa708d76697db2c7354 100644 (file)
@@ -293,6 +293,12 @@ libc {
 %endif
     close_range;
   }
+  GLIBC_2.35 {
+%ifdef TIME64_NON_DEFAULT
+    __epoll_pwait2_time64;
+%endif
+    epoll_pwait2;
+  }
   GLIBC_PRIVATE {
     # functions used in other libraries
     __syscall_rt_sigqueueinfo;
index fed942ed4b9ef469e0ff5cac0c94c3d3a483eb41..c1a5ee90e6d4c63e68bfd046048e7d05e9ff386d 100644 (file)
@@ -2614,3 +2614,4 @@ GLIBC_2.34 tss_get F
 GLIBC_2.34 tss_set F
 GLIBC_2.35 __memcmpeq F
 GLIBC_2.35 _dl_find_object F
+GLIBC_2.35 epoll_pwait2 F
index 28679327043ff0f222e4d9cc69f1a2d443d1626a..1a30d0666bb76f41da06cb9fc3b6469ee290e794 100644 (file)
@@ -2711,6 +2711,7 @@ GLIBC_2.34 tss_get F
 GLIBC_2.34 tss_set F
 GLIBC_2.35 __memcmpeq F
 GLIBC_2.35 _dl_find_object F
+GLIBC_2.35 epoll_pwait2 F
 GLIBC_2.4 _IO_fprintf F
 GLIBC_2.4 _IO_printf F
 GLIBC_2.4 _IO_sprintf F
index 239db7bab0a18a87b729324eca84cdc4efa5b29a..e5dfdab357c724405c7621ea24982fe67fe5943d 100644 (file)
@@ -2375,3 +2375,4 @@ GLIBC_2.34 tss_get F
 GLIBC_2.34 tss_set F
 GLIBC_2.35 __memcmpeq F
 GLIBC_2.35 _dl_find_object F
+GLIBC_2.35 epoll_pwait2 F
index bc79dcfe8ab4c723ebac4f59add7d3db31abaa24..4d3fd872788ba1f03a6b06bb1908e1eef95db13c 100644 (file)
@@ -491,8 +491,10 @@ GLIBC_2.34 tss_create F
 GLIBC_2.34 tss_delete F
 GLIBC_2.34 tss_get F
 GLIBC_2.34 tss_set F
+GLIBC_2.35 __epoll_pwait2_time64 F
 GLIBC_2.35 __memcmpeq F
 GLIBC_2.35 _dl_find_object F
+GLIBC_2.35 epoll_pwait2 F
 GLIBC_2.4 _Exit F
 GLIBC_2.4 _IO_2_1_stderr_ D 0xa0
 GLIBC_2.4 _IO_2_1_stdin_ D 0xa0
index 614607fd6baa8c6f24bdb214f0b8b9e15d638dfd..009dc9da14ee5eed52380b8f7b4d31862e5a660d 100644 (file)
@@ -488,8 +488,10 @@ GLIBC_2.34 tss_create F
 GLIBC_2.34 tss_delete F
 GLIBC_2.34 tss_get F
 GLIBC_2.34 tss_set F
+GLIBC_2.35 __epoll_pwait2_time64 F
 GLIBC_2.35 __memcmpeq F
 GLIBC_2.35 _dl_find_object F
+GLIBC_2.35 epoll_pwait2 F
 GLIBC_2.4 _Exit F
 GLIBC_2.4 _IO_2_1_stderr_ D 0xa0
 GLIBC_2.4 _IO_2_1_stdin_ D 0xa0
index 2b61543f0dd47034466f457b8253e3502a78226e..df8da506cde36eebf527d3a080c6ff9016d042b7 100644 (file)
@@ -2647,5 +2647,7 @@ GLIBC_2.34 tss_create F
 GLIBC_2.34 tss_delete F
 GLIBC_2.34 tss_get F
 GLIBC_2.34 tss_set F
+GLIBC_2.35 __epoll_pwait2_time64 F
 GLIBC_2.35 __memcmpeq F
 GLIBC_2.35 _dl_find_object F
+GLIBC_2.35 epoll_pwait2 F
diff --git a/sysdeps/unix/sysv/linux/epoll_pwait2.c b/sysdeps/unix/sysv/linux/epoll_pwait2.c
new file mode 100644 (file)
index 0000000..e38a1b2
--- /dev/null
@@ -0,0 +1,44 @@
+/* Implementation of epoll_pwait2 syscall wrapper.
+   Copyright (C) 2022 Free Software Foundation, Inc.
+   This file is part of the GNU C Library.
+
+   The GNU C Library is free software; you can redistribute it and/or
+   modify it under the terms of the GNU Lesser General Public
+   License as published by the Free Software Foundation; either
+   version 2.1 of the License, or (at your option) any later version.
+
+   The GNU C Library is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+   Lesser General Public License for more details.
+
+   You should have received a copy of the GNU Lesser General Public
+   License along with the GNU C Library; if not, see
+   <https://www.gnu.org/licenses/>.  */
+
+#include <sys/epoll.h>
+#include <sysdep.h>
+
+int
+__epoll_pwait2_time64 (int fd, struct epoll_event *ev, int maxev,
+                      const struct __timespec64 *tmo, const sigset_t *s)
+{
+  /* The syscall only supports 64-bit time_t.  */
+  return SYSCALL_CANCEL (epoll_pwait2, fd, ev, maxev, tmo, s, __NSIG_BYTES);
+}
+#if __TIMESIZE != 64
+libc_hidden_def (__epoll_pwait2_time64)
+
+int
+epoll_pwait2 (int fd, struct epoll_event *ev, int maxev,
+             const struct timespec *tmo, const sigset_t *s)
+{
+  struct __timespec64 tmo64, *ptmo64 = NULL;
+  if (tmo != NULL)
+    {
+      tmo64 = valid_timespec_to_timespec64 (*tmo);
+      ptmo64 = &tmo64;
+    }
+  return __epoll_pwait2_time64 (fd, ev, maxev, ptmo64, s);
+}
+#endif
index 6b3cb1adb40c0a017420dbb19524626d8276bb74..7ea1b017d05cc1fb22b169b14fcfeee52f9c647d 100644 (file)
@@ -2596,8 +2596,10 @@ GLIBC_2.34 tss_create F
 GLIBC_2.34 tss_delete F
 GLIBC_2.34 tss_get F
 GLIBC_2.34 tss_set F
+GLIBC_2.35 __epoll_pwait2_time64 F
 GLIBC_2.35 __memcmpeq F
 GLIBC_2.35 _dl_find_object F
+GLIBC_2.35 epoll_pwait2 F
 GLIBC_2.4 __confstr_chk F
 GLIBC_2.4 __fgets_chk F
 GLIBC_2.4 __fgets_unlocked_chk F
index 7f608c1b64454bff6ad3a62d2bed8a3733896a1e..99ccf354b3d1a762f0b117fd1bd5e34cfeb4e7c9 100644 (file)
@@ -2780,8 +2780,10 @@ GLIBC_2.34 tss_create F
 GLIBC_2.34 tss_delete F
 GLIBC_2.34 tss_get F
 GLIBC_2.34 tss_set F
+GLIBC_2.35 __epoll_pwait2_time64 F
 GLIBC_2.35 __memcmpeq F
 GLIBC_2.35 _dl_find_object F
+GLIBC_2.35 epoll_pwait2 F
 GLIBC_2.4 __confstr_chk F
 GLIBC_2.4 __fgets_chk F
 GLIBC_2.4 __fgets_unlocked_chk F
index 865deec43f99a03645631f58eb89bd3f46a71366..201542d1e76daa601396445297feecb8c0df4d63 100644 (file)
@@ -2549,6 +2549,7 @@ GLIBC_2.34 tss_get F
 GLIBC_2.34 tss_set F
 GLIBC_2.35 __memcmpeq F
 GLIBC_2.35 _dl_find_object F
+GLIBC_2.35 epoll_pwait2 F
 GLIBC_2.4 __confstr_chk F
 GLIBC_2.4 __fgets_chk F
 GLIBC_2.4 __fgets_unlocked_chk F
index a172d746328ddeeb09efd2bc8a3a0423ce113b6f..32fd72a78df65bd82be2253ecf38b8849145dfa5 100644 (file)
@@ -492,8 +492,10 @@ GLIBC_2.34 tss_create F
 GLIBC_2.34 tss_delete F
 GLIBC_2.34 tss_get F
 GLIBC_2.34 tss_set F
+GLIBC_2.35 __epoll_pwait2_time64 F
 GLIBC_2.35 __memcmpeq F
 GLIBC_2.35 _dl_find_object F
+GLIBC_2.35 epoll_pwait2 F
 GLIBC_2.4 _Exit F
 GLIBC_2.4 _IO_2_1_stderr_ D 0x98
 GLIBC_2.4 _IO_2_1_stdin_ D 0x98
index 174e9c7739f966acea42b14fa4de3ad8b9b20feb..d26f0ae6c247598406f2593c37d9a8e693a734e7 100644 (file)
@@ -2723,8 +2723,10 @@ GLIBC_2.34 tss_create F
 GLIBC_2.34 tss_delete F
 GLIBC_2.34 tss_get F
 GLIBC_2.34 tss_set F
+GLIBC_2.35 __epoll_pwait2_time64 F
 GLIBC_2.35 __memcmpeq F
 GLIBC_2.35 _dl_find_object F
+GLIBC_2.35 epoll_pwait2 F
 GLIBC_2.4 __confstr_chk F
 GLIBC_2.4 __fgets_chk F
 GLIBC_2.4 __fgets_unlocked_chk F
index d042be1369b7d264cb92e6bf8a2bbea210a0e384..520ca0882d8d720b64c0d5a136ecb6c3158c730b 100644 (file)
@@ -2696,5 +2696,7 @@ GLIBC_2.34 tss_create F
 GLIBC_2.34 tss_delete F
 GLIBC_2.34 tss_get F
 GLIBC_2.34 tss_set F
+GLIBC_2.35 __epoll_pwait2_time64 F
 GLIBC_2.35 __memcmpeq F
 GLIBC_2.35 _dl_find_object F
+GLIBC_2.35 epoll_pwait2 F
index 332da62de23b88b8f5f6231d6c5fd8ba88e8c4fa..9162c3139661b2c9972bb6eb762c7563d9e32ecc 100644 (file)
@@ -2693,5 +2693,7 @@ GLIBC_2.34 tss_create F
 GLIBC_2.34 tss_delete F
 GLIBC_2.34 tss_get F
 GLIBC_2.34 tss_set F
+GLIBC_2.35 __epoll_pwait2_time64 F
 GLIBC_2.35 __memcmpeq F
 GLIBC_2.35 _dl_find_object F
+GLIBC_2.35 epoll_pwait2 F
index 2d6ec0d0e8f3c797b0e45bbdc68a7b4d35b789d9..656fdbdcaa70dad61f0555b2f351b45449df3e5a 100644 (file)
@@ -2688,8 +2688,10 @@ GLIBC_2.34 tss_create F
 GLIBC_2.34 tss_delete F
 GLIBC_2.34 tss_get F
 GLIBC_2.34 tss_set F
+GLIBC_2.35 __epoll_pwait2_time64 F
 GLIBC_2.35 __memcmpeq F
 GLIBC_2.35 _dl_find_object F
+GLIBC_2.35 epoll_pwait2 F
 GLIBC_2.4 __confstr_chk F
 GLIBC_2.4 __fgets_chk F
 GLIBC_2.4 __fgets_unlocked_chk F
index 6c5befa72bb5602bb3bf166abc18485db99cf1b3..5f0b90d3180306227746b8307ce90534874c0f2b 100644 (file)
@@ -2686,8 +2686,10 @@ GLIBC_2.34 tss_create F
 GLIBC_2.34 tss_delete F
 GLIBC_2.34 tss_get F
 GLIBC_2.34 tss_set F
+GLIBC_2.35 __epoll_pwait2_time64 F
 GLIBC_2.35 __memcmpeq F
 GLIBC_2.35 _dl_find_object F
+GLIBC_2.35 epoll_pwait2 F
 GLIBC_2.4 __confstr_chk F
 GLIBC_2.4 __fgets_chk F
 GLIBC_2.4 __fgets_unlocked_chk F
index 5fb24c97e1e6f05da46056e5f19a1c1bdbf37bc4..9f4891fc08d7152170a2a660882549e0f0327676 100644 (file)
@@ -2694,8 +2694,10 @@ GLIBC_2.34 tss_create F
 GLIBC_2.34 tss_delete F
 GLIBC_2.34 tss_get F
 GLIBC_2.34 tss_set F
+GLIBC_2.35 __epoll_pwait2_time64 F
 GLIBC_2.35 __memcmpeq F
 GLIBC_2.35 _dl_find_object F
+GLIBC_2.35 epoll_pwait2 F
 GLIBC_2.4 __confstr_chk F
 GLIBC_2.4 __fgets_chk F
 GLIBC_2.4 __fgets_unlocked_chk F
index f4f29fc15ee8f1a28474eeccb8fd46931c234012..f1b0644bc33ba065bc2e0b6d244a3e2e5c42b9c2 100644 (file)
@@ -2600,6 +2600,7 @@ GLIBC_2.34 tss_get F
 GLIBC_2.34 tss_set F
 GLIBC_2.35 __memcmpeq F
 GLIBC_2.35 _dl_find_object F
+GLIBC_2.35 epoll_pwait2 F
 GLIBC_2.4 __confstr_chk F
 GLIBC_2.4 __fgets_chk F
 GLIBC_2.4 __fgets_unlocked_chk F
index 2e7300cd0512ad78928e155ce157113ab48eb3ed..1cf88e38b943eeb9e666e78cb5db371563b1846c 100644 (file)
@@ -2735,5 +2735,7 @@ GLIBC_2.34 tss_create F
 GLIBC_2.34 tss_delete F
 GLIBC_2.34 tss_get F
 GLIBC_2.34 tss_set F
+GLIBC_2.35 __epoll_pwait2_time64 F
 GLIBC_2.35 __memcmpeq F
 GLIBC_2.35 _dl_find_object F
+GLIBC_2.35 epoll_pwait2 F
index eea4e3dc3fd50ecfd1ec4baee8ffa869584bc284..ac2a8284ce31442869b6d1d4729fb9ff5f0041c4 100644 (file)
@@ -697,6 +697,7 @@ GLIBC_2.35 epoll_create F
 GLIBC_2.35 epoll_create1 F
 GLIBC_2.35 epoll_ctl F
 GLIBC_2.35 epoll_pwait F
+GLIBC_2.35 epoll_pwait2 F
 GLIBC_2.35 epoll_wait F
 GLIBC_2.35 erand48 F
 GLIBC_2.35 erand48_r F
index 129a2f16a7b731d3f9401e39450dfab93718decf..9692335d106f9400f35b71e867dea0b539412def 100644 (file)
@@ -2750,8 +2750,10 @@ GLIBC_2.34 tss_create F
 GLIBC_2.34 tss_delete F
 GLIBC_2.34 tss_get F
 GLIBC_2.34 tss_set F
+GLIBC_2.35 __epoll_pwait2_time64 F
 GLIBC_2.35 __memcmpeq F
 GLIBC_2.35 _dl_find_object F
+GLIBC_2.35 epoll_pwait2 F
 GLIBC_2.4 _IO_fprintf F
 GLIBC_2.4 _IO_printf F
 GLIBC_2.4 _IO_sprintf F
index 7e232267791057a387a8765d3d715ab0e6d48c2a..7da0ed59f2ccb080965f33c99b00ac7a3c5d34ea 100644 (file)
@@ -2783,8 +2783,10 @@ GLIBC_2.34 tss_create F
 GLIBC_2.34 tss_delete F
 GLIBC_2.34 tss_get F
 GLIBC_2.34 tss_set F
+GLIBC_2.35 __epoll_pwait2_time64 F
 GLIBC_2.35 __memcmpeq F
 GLIBC_2.35 _dl_find_object F
+GLIBC_2.35 epoll_pwait2 F
 GLIBC_2.4 _IO_fprintf F
 GLIBC_2.4 _IO_printf F
 GLIBC_2.4 _IO_sprintf F
index 6f97392b7030ee9570a1908e1aef8d41e9671885..72cf6851988a7b91accdc83f6cc4c65860078d60 100644 (file)
@@ -2508,6 +2508,7 @@ GLIBC_2.34 tss_get F
 GLIBC_2.34 tss_set F
 GLIBC_2.35 __memcmpeq F
 GLIBC_2.35 _dl_find_object F
+GLIBC_2.35 epoll_pwait2 F
 GLIBC_2.4 _IO_fprintf F
 GLIBC_2.4 _IO_printf F
 GLIBC_2.4 _IO_sprintf F
index 29058a041a9cdba1f044560af8d87c6636babf2d..ee7f67f4d09ba7aef31caee7448c4679728894c7 100644 (file)
@@ -2810,3 +2810,4 @@ GLIBC_2.34 tss_get F
 GLIBC_2.34 tss_set F
 GLIBC_2.35 __memcmpeq F
 GLIBC_2.35 _dl_find_object F
+GLIBC_2.35 epoll_pwait2 F
index d2924766d2f330395b148de2994512c2a5328b2f..b8c0854508ec87144ad90ff89e6f85b85ddd01c5 100644 (file)
@@ -2377,3 +2377,4 @@ GLIBC_2.34 tss_get F
 GLIBC_2.34 tss_set F
 GLIBC_2.35 __memcmpeq F
 GLIBC_2.35 _dl_find_object F
+GLIBC_2.35 epoll_pwait2 F
index b770e05da3ae0350ee612f3a9afdf7651ff6dc7c..90f331fc0bc0627820a21d8da381354631718170 100644 (file)
@@ -2577,3 +2577,4 @@ GLIBC_2.34 tss_get F
 GLIBC_2.34 tss_set F
 GLIBC_2.35 __memcmpeq F
 GLIBC_2.35 _dl_find_object F
+GLIBC_2.35 epoll_pwait2 F
index bed3433a2b75d3b4a4f05ff853a44434205804cb..ded5e3c0ce4da82ca185ed649d4ba1b24da385eb 100644 (file)
@@ -2748,8 +2748,10 @@ GLIBC_2.34 tss_create F
 GLIBC_2.34 tss_delete F
 GLIBC_2.34 tss_get F
 GLIBC_2.34 tss_set F
+GLIBC_2.35 __epoll_pwait2_time64 F
 GLIBC_2.35 __memcmpeq F
 GLIBC_2.35 _dl_find_object F
+GLIBC_2.35 epoll_pwait2 F
 GLIBC_2.4 _IO_fprintf F
 GLIBC_2.4 _IO_printf F
 GLIBC_2.4 _IO_sprintf F
index 4f1a143da504d98c2fcb88d0016296f50d5113fc..4b262992540d18d691d763f413aa63db9475fd84 100644 (file)
@@ -2545,6 +2545,7 @@ GLIBC_2.34 tss_get F
 GLIBC_2.34 tss_set F
 GLIBC_2.35 __memcmpeq F
 GLIBC_2.35 _dl_find_object F
+GLIBC_2.35 epoll_pwait2 F
 GLIBC_2.4 _IO_fprintf F
 GLIBC_2.4 _IO_printf F
 GLIBC_2.4 _IO_sprintf F
index 92c8dec8ec28c54a6835532a839e1888acdeb10b..8bfd716fd238a35b09f3552415eacdb090ce0068 100644 (file)
@@ -2603,8 +2603,10 @@ GLIBC_2.34 tss_create F
 GLIBC_2.34 tss_delete F
 GLIBC_2.34 tss_get F
 GLIBC_2.34 tss_set F
+GLIBC_2.35 __epoll_pwait2_time64 F
 GLIBC_2.35 __memcmpeq F
 GLIBC_2.35 _dl_find_object F
+GLIBC_2.35 epoll_pwait2 F
 GLIBC_2.4 __confstr_chk F
 GLIBC_2.4 __fgets_chk F
 GLIBC_2.4 __fgets_unlocked_chk F
index 263da58cb7dada2cc2aa681f6bface3105df757b..47fd204d84ea2432e48fc60d7d4c5f5b53789685 100644 (file)
@@ -2600,8 +2600,10 @@ GLIBC_2.34 tss_create F
 GLIBC_2.34 tss_delete F
 GLIBC_2.34 tss_get F
 GLIBC_2.34 tss_set F
+GLIBC_2.35 __epoll_pwait2_time64 F
 GLIBC_2.35 __memcmpeq F
 GLIBC_2.35 _dl_find_object F
+GLIBC_2.35 epoll_pwait2 F
 GLIBC_2.4 __confstr_chk F
 GLIBC_2.4 __fgets_chk F
 GLIBC_2.4 __fgets_unlocked_chk F
index 0171efe7db1091530de48c2700e64ef02910a48c..9b82f15109ca4b1a93b717907622ba3717d22d17 100644 (file)
@@ -2743,8 +2743,10 @@ GLIBC_2.34 tss_create F
 GLIBC_2.34 tss_delete F
 GLIBC_2.34 tss_get F
 GLIBC_2.34 tss_set F
+GLIBC_2.35 __epoll_pwait2_time64 F
 GLIBC_2.35 __memcmpeq F
 GLIBC_2.35 _dl_find_object F
+GLIBC_2.35 epoll_pwait2 F
 GLIBC_2.4 _IO_fprintf F
 GLIBC_2.4 _IO_printf F
 GLIBC_2.4 _IO_sprintf F
index 7f8d45f362e635841b8b7fccb1f2fe5b42c2ae2e..94caf012a7e9cada759b0d767647c145d4e0c8a8 100644 (file)
@@ -2572,6 +2572,7 @@ GLIBC_2.34 tss_get F
 GLIBC_2.34 tss_set F
 GLIBC_2.35 __memcmpeq F
 GLIBC_2.35 _dl_find_object F
+GLIBC_2.35 epoll_pwait2 F
 GLIBC_2.4 __confstr_chk F
 GLIBC_2.4 __fgets_chk F
 GLIBC_2.4 __fgets_unlocked_chk F
index 0d013c3e209aab1e74aac617d0c45bb7219b5403..b95ca68749c4763cc62d42231fc3ccd843c78bc0 100644 (file)
@@ -22,6 +22,7 @@
 #include <sys/types.h>
 
 #include <bits/types/sigset_t.h>
+#include <bits/types/struct_timespec.h>
 
 /* Get the platform-dependent flags.  */
 #include <bits/epoll.h>
@@ -133,6 +134,26 @@ extern int epoll_pwait (int __epfd, struct epoll_event *__events,
                        int __maxevents, int __timeout,
                        const __sigset_t *__ss);
 
+/* Same as epoll_pwait, but the timeout as a timespec.
+
+   This function is a cancellation point and therefore not marked with
+   __THROW.  */
+#ifndef __USE_TIME_BITS64
+extern int epoll_pwait2 (int __epfd, struct epoll_event *__events,
+                        int __maxevents, const struct timespec *__timeout,
+                        const __sigset_t *__ss);
+#else
+# ifdef __REDIRECT
+extern int __REDIRECT (epoll_pwait2, (int __epfd, struct epoll_event *__ev,
+                                     int __maxevs,
+                                     const struct timespec *__timeout,
+                                     const __sigset_t *__ss),
+                      __epoll_pwait2_time64);
+# else
+#  define epoll_pwait2 __epoll_pwait2_time64
+# endif
+#endif
+
 __END_DECLS
 
 #endif /* sys/epoll.h */
diff --git a/sysdeps/unix/sysv/linux/tst-epoll-time64.c b/sysdeps/unix/sysv/linux/tst-epoll-time64.c
new file mode 100644 (file)
index 0000000..2e02367
--- /dev/null
@@ -0,0 +1 @@
+#include "tst-epoll.c"
diff --git a/sysdeps/unix/sysv/linux/tst-epoll.c b/sysdeps/unix/sysv/linux/tst-epoll.c
new file mode 100644 (file)
index 0000000..3ef6ca9
--- /dev/null
@@ -0,0 +1,211 @@
+/* Basic tests for Linux epoll_* wrappers.
+   Copyright (C) 2022 Free Software Foundation, Inc.
+   This file is part of the GNU C Library.
+
+   The GNU C Library is free software; you can redistribute it and/or
+   modify it under the terms of the GNU Lesser General Public
+   License as published by the Free Software Foundation; either
+   version 2.1 of the License, or (at your option) any later version.
+
+   The GNU C Library is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+   Lesser General Public License for more details.
+
+   You should have received a copy of the GNU Lesser General Public
+   License along with the GNU C Library; if not, see
+   <https://www.gnu.org/licenses/>.  */
+
+#include <errno.h>
+#include <intprops.h>
+#include <support/check.h>
+#include <support/support.h>
+#include <support/xsignal.h>
+#include <support/xunistd.h>
+#include <support/xtime.h>
+#include <stdlib.h>
+#include <sys/epoll.h>
+
+/* The test focus on checking if the timeout argument is correctly handled
+   by glibc wrappers.  */
+
+static void
+handler (int sig)
+{
+}
+
+typedef int (*epoll_wait_check_t) (int, struct epoll_event *, int,
+                                  int, const sigset_t *);
+
+static void
+test_epoll_basic (epoll_wait_check_t epoll_wait_check)
+{
+  {
+    sigset_t ss_usr1;
+    sigemptyset (&ss_usr1);
+    sigaddset (&ss_usr1, SIGUSR1);
+    TEST_COMPARE (sigprocmask (SIG_BLOCK, &ss_usr1, NULL), 0);
+  }
+
+  int fds[2][2];
+  xpipe (fds[0]);
+  xpipe (fds[1]);
+
+  sigset_t ss;
+  TEST_COMPARE (sigprocmask (SIG_SETMASK, NULL, &ss), 0);
+  sigdelset (&ss, SIGUSR1);
+
+  int efd = epoll_create1 (0);
+  TEST_VERIFY_EXIT (efd != -1);
+
+  struct epoll_event event;
+
+  event.data.fd = fds[1][0];
+  event.events = EPOLLIN | EPOLLET;
+  TEST_COMPARE (epoll_ctl (efd, EPOLL_CTL_ADD, fds[1][0], &event), 0);
+
+  pid_t parent = getpid ();
+  pid_t p = xfork ();
+  if (p == 0)
+    {
+      xclose (fds[0][1]);
+      xclose (fds[1][0]);
+
+      event.data.fd = fds[0][0];
+      event.events = EPOLLIN | EPOLLET;
+      TEST_COMPARE (epoll_ctl (efd, EPOLL_CTL_ADD, fds[0][0], &event), 0);
+
+      int e;
+      do
+       {
+         if (getppid () != parent)
+           FAIL_EXIT1 ("getppid()=%d != parent=%d", getppid(), parent);
+
+         errno = 0;
+         e = epoll_wait_check (efd, &event, 1, 500, &ss);
+       }
+      while (e == 0);
+
+      TEST_COMPARE (e, -1);
+      TEST_COMPARE (errno, EINTR);
+
+      TEMP_FAILURE_RETRY (write (fds[1][1], "foo", 3));
+
+      exit (0);
+    }
+
+  xclose (fds[0][0]);
+  xclose (fds[1][1]);
+
+  /* Wait some time so child is blocked on the syscall.  */
+  nanosleep (&(struct timespec) {0, 10000000}, NULL);
+  TEST_COMPARE (kill (p, SIGUSR1), 0);
+
+  int e = epoll_wait_check (efd, &event, 1, 500000000, &ss);
+  TEST_COMPARE (e, 1);
+  TEST_VERIFY (event.events & EPOLLIN);
+
+  xclose (fds[0][1]);
+  xclose (fds[1][0]);
+  xclose (efd);
+}
+
+
+static void
+test_epoll_large_timeout (epoll_wait_check_t epoll_wait_check)
+{
+  timer_t t = support_create_timer (0, 100000000, true, NULL);
+
+  int fds[2];
+  xpipe (fds);
+
+  fd_set rfds;
+  FD_ZERO (&rfds);
+  FD_SET (fds[0], &rfds);
+
+  sigset_t ss;
+  TEST_COMPARE (sigprocmask (SIG_SETMASK, NULL, &ss), 0);
+  sigdelset (&ss, SIGALRM);
+
+  int efd = epoll_create1 (0);
+  TEST_VERIFY_EXIT (efd != -1);
+
+  struct epoll_event event;
+  event.data.fd = fds[0];
+  event.events = EPOLLIN | EPOLLET;
+  TEST_COMPARE (epoll_ctl (efd, EPOLL_CTL_ADD, fds[0], &event), 0);
+
+  int tmo = TYPE_MAXIMUM (int);
+  TEST_COMPARE (epoll_wait_check (efd, &event, 1, tmo, &ss), -1);
+  TEST_VERIFY (errno == EINTR || errno == EOVERFLOW);
+
+  TEST_COMPARE (epoll_wait_check (efd, &event, 1, -1, &ss), -1);
+  TEST_VERIFY (errno == EINTR || errno == EOVERFLOW);
+
+  support_delete_timer (t);
+
+  xclose (fds[0]);
+  xclose (fds[1]);
+  xclose (efd);
+}
+
+
+static int
+epoll_wait_check (int epfd, struct epoll_event *ev, int maxev, int tmo,
+                 const sigset_t *ss)
+{
+  sigset_t orig;
+  TEST_COMPARE (sigprocmask (SIG_SETMASK, ss, &orig), 0);
+  int r = epoll_wait (epfd, ev, maxev, tmo);
+  TEST_COMPARE (sigprocmask (SIG_SETMASK, &orig, NULL), 0);
+  return r;
+}
+
+static int
+epoll_pwait_check (int epfd, struct epoll_event *ev, int maxev, int tmo,
+                  const sigset_t *ss)
+{
+  return epoll_pwait (epfd, ev, maxev, tmo, ss);
+}
+
+static int
+epoll_pwait2_check (int epfd, struct epoll_event *ev, int maxev, int tmo,
+                   const sigset_t *ss)
+{
+  time_t s = tmo == -1 ? TYPE_MAXIMUM (time_t) : tmo / 1000;
+  long int ns = tmo == -1 ? 0 : (tmo % 1000) * 1000000;
+  return epoll_pwait2 (epfd, ev, maxev, &(struct timespec) { s, ns }, ss);
+}
+
+static int
+do_test (void)
+{
+  {
+    struct sigaction sa;
+    sa.sa_handler = handler;
+    sa.sa_flags = 0;
+    sigemptyset (&sa.sa_mask);
+    xsigaction (SIGUSR1, &sa, NULL);
+
+    sa.sa_handler = SIG_IGN;
+    xsigaction (SIGCHLD, &sa, NULL);
+  }
+
+  int r = epoll_pwait2 (-1, NULL, 0, NULL, NULL);
+  TEST_COMPARE (r, -1);
+  bool pwait2_supported = errno != ENOSYS;
+
+  test_epoll_basic (epoll_wait_check);
+  test_epoll_basic (epoll_pwait_check);
+  if (pwait2_supported)
+    test_epoll_basic (epoll_pwait2_check);
+
+  test_epoll_large_timeout (epoll_wait_check);
+  test_epoll_large_timeout (epoll_pwait_check);
+  if (pwait2_supported)
+    test_epoll_large_timeout (epoll_pwait2_check);
+
+  return 0;
+}
+
+#include <support/test-driver.c>
index c2f1a8ecc6d04dcfe91c6e9389ae24b464d67995..140e9e8c1ce7dd37dfc883bc2305e4d290215779 100644 (file)
@@ -2523,6 +2523,7 @@ GLIBC_2.34 tss_get F
 GLIBC_2.34 tss_set F
 GLIBC_2.35 __memcmpeq F
 GLIBC_2.35 _dl_find_object F
+GLIBC_2.35 epoll_pwait2 F
 GLIBC_2.4 __confstr_chk F
 GLIBC_2.4 __fgets_chk F
 GLIBC_2.4 __fgets_unlocked_chk F
index 8b43acf1005f17900caea978e1b02154527351fa..04d13ce27e3747f55b100a09be3f3252b01637f9 100644 (file)
@@ -2629,3 +2629,4 @@ GLIBC_2.34 tss_get F
 GLIBC_2.34 tss_set F
 GLIBC_2.35 __memcmpeq F
 GLIBC_2.35 _dl_find_object F
+GLIBC_2.35 epoll_pwait2 F