]> git.ipfire.org Git - thirdparty/glibc.git/commitdiff
linux: Add process_madvise
authorAdhemerval Zanella <adhemerval.zanella@linaro.org>
Wed, 26 Jan 2022 19:05:31 +0000 (16:05 -0300)
committerAdhemerval Zanella <adhemerval.zanella@linaro.org>
Thu, 2 Jun 2022 18:43:28 +0000 (15:43 -0300)
It was added on Linux 5.10 (ecb8ac8b1f146915aa6b96449b66dd48984caacc)
with the same functionality as madvise but using a pidfd of the target
process.

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

Reviewed-by: Carlos O'Donell <carlos@redhat.com>
42 files changed:
NEWS
bits/mman_ext.h [new file with mode: 0644]
misc/sys/mman.h
posix/Makefile
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/bits/mman_ext.h [new file with mode: 0644]
sysdeps/unix/sysv/linux/csky/libc.abilist
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/syscalls.list
sysdeps/unix/sysv/linux/tst-process_madvise.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 ad0c08d8ca80d19bcfae579d5f29a3fbae1d7797..5032f5fce552cf77282a50cdbf3a59c01a1b2b6d 100644 (file)
--- a/NEWS
+++ b/NEWS
@@ -20,6 +20,10 @@ Major new features:
   have been added.  The pidfd functionality provides access to a process
   while avoiding the issue of PID reuse on tranditional Unix systems.
 
+* On Linux, the process_madvise function has been added. It has the
+  same functionality as madvise but alters the target process identified
+  by the pidfd.
+
 Deprecated and removed features, and other changes affecting compatibility:
 
 * Support for prelink will be removed in the next release; this includes
diff --git a/bits/mman_ext.h b/bits/mman_ext.h
new file mode 100644 (file)
index 0000000..3ac42ab
--- /dev/null
@@ -0,0 +1,21 @@
+/* System-specific extensions of <sys/mman.h>, generic version.
+   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/>.  */
+
+#ifndef _SYS_MMAN_H
+# error "Never include <bits/mman_ext.h> directly; use <sys/mman.h> instead."
+#endif
index 311d44cfb16dc67a4c3baa71d4278a5cf30458ad..02896a0accb0f554e64f2cbb095532179fa52fbb 100644 (file)
@@ -146,6 +146,9 @@ extern int shm_open (const char *__name, int __oflag, mode_t __mode);
 /* Remove shared memory segment.  */
 extern int shm_unlink (const char *__name);
 
+/* System-specific extensions.  */
+#include <bits/mman_ext.h>
+
 __END_DECLS
 
 #endif /* sys/mman.h */
index cfebb8ef06a2d1ee2811f8ca17ea4d518db8a5fa..d1df7c27cbc0b5e6ad2bc4af0c572ceee1094bd3 100644 (file)
@@ -32,7 +32,7 @@ headers       := sys/utsname.h sys/times.h sys/wait.h sys/types.h unistd.h          \
           bits/waitflags.h bits/waitstatus.h sys/unistd.h sched.h            \
           bits/sched.h bits/cpu-set.h re_comp.h wait.h bits/environments.h   \
           cpio.h spawn.h bits/unistd.h bits/types/struct_sched_param.h       \
-          bits/unistd_ext.h bits/types/idtype_t.h
+          bits/unistd_ext.h bits/types/idtype_t.h bits/mman_ext.h
 
 routines :=                                                                  \
        uname                                                                 \
index 98b2324a213aa92df80991093baae898de8732ec..627506daad34760244fdaef696f8c0371a66fe96 100644 (file)
@@ -131,6 +131,11 @@ tests += tst-clone tst-clone2 tst-clone3 tst-fanotify tst-personality \
   tst-pidfd \
   # tests
 
+# process_madvise requires CAP_SYS_ADMIN.
+xtests += \
+  tst-process_madvise \
+  # xtests
+
 # For +depfiles in Makerules.
 extra-test-objs += tst-sysconf-iov_max-uapi.o
 
index 694c64a5bc4f80f09c96861462c037c5ff6b359d..c13a3c4fe786309a8e4d9648ec4412d62034b258 100644 (file)
@@ -303,6 +303,7 @@ libc {
     pidfd_open;
     pidfd_getfd;
     pidfd_send_signal;
+    process_madvise;
   }
   GLIBC_PRIVATE {
     # functions used in other libraries
index 760212963173d629f49a8e7632d1cafaa30f0e40..4d8e64ce04c18c61551477cae937e05b56f1848c 100644 (file)
@@ -2619,3 +2619,4 @@ GLIBC_2.35 posix_spawn_file_actions_addtcsetpgrp_np F
 GLIBC_2.36 pidfd_getfd F
 GLIBC_2.36 pidfd_open F
 GLIBC_2.36 pidfd_send_signal F
+GLIBC_2.36 process_madvise F
index 5b39d6023cee3ad999bd872e5039a2619881b410..36f31292570c34a764f34ce5a49d68c4c28a4c12 100644 (file)
@@ -2716,6 +2716,7 @@ GLIBC_2.35 posix_spawn_file_actions_addtcsetpgrp_np F
 GLIBC_2.36 pidfd_getfd F
 GLIBC_2.36 pidfd_open F
 GLIBC_2.36 pidfd_send_signal F
+GLIBC_2.36 process_madvise F
 GLIBC_2.4 _IO_fprintf F
 GLIBC_2.4 _IO_printf F
 GLIBC_2.4 _IO_sprintf F
index e413302f2eec1e04b2f63375f1a22efda90b5f55..2a1e346d4b69f269b43e7c157168aa47d501ccb1 100644 (file)
@@ -2380,3 +2380,4 @@ GLIBC_2.35 posix_spawn_file_actions_addtcsetpgrp_np F
 GLIBC_2.36 pidfd_getfd F
 GLIBC_2.36 pidfd_open F
 GLIBC_2.36 pidfd_send_signal F
+GLIBC_2.36 process_madvise F
index ade1b93d136f26cf0d3936d6df49a543a388fef3..25de8a018c1dc7d0ca1eee56556faed8d67dd4a2 100644 (file)
@@ -499,6 +499,7 @@ GLIBC_2.35 posix_spawn_file_actions_addtcsetpgrp_np F
 GLIBC_2.36 pidfd_getfd F
 GLIBC_2.36 pidfd_open F
 GLIBC_2.36 pidfd_send_signal F
+GLIBC_2.36 process_madvise 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 10e91537fae106c314860f54123fbddcd1c21078..e9cf9b15936896caece16a4dd993b760e188b7a7 100644 (file)
@@ -496,6 +496,7 @@ GLIBC_2.35 posix_spawn_file_actions_addtcsetpgrp_np F
 GLIBC_2.36 pidfd_getfd F
 GLIBC_2.36 pidfd_open F
 GLIBC_2.36 pidfd_send_signal F
+GLIBC_2.36 process_madvise F
 GLIBC_2.4 _Exit F
 GLIBC_2.4 _IO_2_1_stderr_ D 0xa0
 GLIBC_2.4 _IO_2_1_stdin_ D 0xa0
diff --git a/sysdeps/unix/sysv/linux/bits/mman_ext.h b/sysdeps/unix/sysv/linux/bits/mman_ext.h
new file mode 100644 (file)
index 0000000..20960e7
--- /dev/null
@@ -0,0 +1,33 @@
+/* System-specific extensions of <sys/mman.h>, Linux version.
+   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/>.  */
+
+#ifndef _SYS_MMAN_H
+# error "Never include <bits/mman_ext.h> directly; use <sys/mman.h> instead."
+#endif
+
+#ifdef __USE_GNU
+#include <bits/types/struct_iovec.h>
+
+/*
+ */
+extern __ssize_t process_madvise (int __pid_fd, const struct iovec* __iov,
+                                 size_t __count, int __advice,
+                                 unsigned __flags)
+  __THROW;
+
+#endif /* __USE_GNU  */
index 22618c7aaa990a0f7aef726db2ba5e29793d24bc..66c2f28c43823fce1e24a49e511d5770c0420609 100644 (file)
@@ -2655,3 +2655,4 @@ GLIBC_2.35 posix_spawn_file_actions_addtcsetpgrp_np F
 GLIBC_2.36 pidfd_getfd F
 GLIBC_2.36 pidfd_open F
 GLIBC_2.36 pidfd_send_signal F
+GLIBC_2.36 process_madvise F
index e2aea90c74ce5dcc3bb5bf8efdcbb5f5f8be78f7..527880dc068d2922cdb7f103b61d49c28b80416d 100644 (file)
@@ -2604,6 +2604,7 @@ GLIBC_2.35 posix_spawn_file_actions_addtcsetpgrp_np F
 GLIBC_2.36 pidfd_getfd F
 GLIBC_2.36 pidfd_open F
 GLIBC_2.36 pidfd_send_signal F
+GLIBC_2.36 process_madvise F
 GLIBC_2.4 __confstr_chk F
 GLIBC_2.4 __fgets_chk F
 GLIBC_2.4 __fgets_unlocked_chk F
index 29ecca26bb95787f1056e496b26a6f1791d88501..1497b8a2c365c0df26b279f3afcc4ccc92b74c5e 100644 (file)
@@ -2788,6 +2788,7 @@ GLIBC_2.35 posix_spawn_file_actions_addtcsetpgrp_np F
 GLIBC_2.36 pidfd_getfd F
 GLIBC_2.36 pidfd_open F
 GLIBC_2.36 pidfd_send_signal F
+GLIBC_2.36 process_madvise F
 GLIBC_2.4 __confstr_chk F
 GLIBC_2.4 __fgets_chk F
 GLIBC_2.4 __fgets_unlocked_chk F
index 69a2ca2391c85bfe5953bb52821ad4984d69c5fe..abe351d0b491016ad013e85390be9566d944e6fd 100644 (file)
@@ -2554,6 +2554,7 @@ GLIBC_2.35 posix_spawn_file_actions_addtcsetpgrp_np F
 GLIBC_2.36 pidfd_getfd F
 GLIBC_2.36 pidfd_open F
 GLIBC_2.36 pidfd_send_signal F
+GLIBC_2.36 process_madvise F
 GLIBC_2.4 __confstr_chk F
 GLIBC_2.4 __fgets_chk F
 GLIBC_2.4 __fgets_unlocked_chk F
index 23cc4ddd8a10e219437ec63aa5bf359c0f920081..130f7a6b047eb7ac39d3d5e8cbad16460119a675 100644 (file)
@@ -500,6 +500,7 @@ GLIBC_2.35 posix_spawn_file_actions_addtcsetpgrp_np F
 GLIBC_2.36 pidfd_getfd F
 GLIBC_2.36 pidfd_open F
 GLIBC_2.36 pidfd_send_signal F
+GLIBC_2.36 process_madvise 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 2d1d8a3d0cefe507f03c51a5c2c8531a098c7553..cf59edb38363dae6ac23c05d349ac5d5177d080b 100644 (file)
@@ -2731,6 +2731,7 @@ GLIBC_2.35 posix_spawn_file_actions_addtcsetpgrp_np F
 GLIBC_2.36 pidfd_getfd F
 GLIBC_2.36 pidfd_open F
 GLIBC_2.36 pidfd_send_signal F
+GLIBC_2.36 process_madvise F
 GLIBC_2.4 __confstr_chk F
 GLIBC_2.4 __fgets_chk F
 GLIBC_2.4 __fgets_unlocked_chk F
index 7b6e88bdb97e451e95c5f92abc6b1b318254a161..f1b927d63d42cbccf1ff9e30db48f7928336a2bf 100644 (file)
@@ -2704,3 +2704,4 @@ GLIBC_2.35 posix_spawn_file_actions_addtcsetpgrp_np F
 GLIBC_2.36 pidfd_getfd F
 GLIBC_2.36 pidfd_open F
 GLIBC_2.36 pidfd_send_signal F
+GLIBC_2.36 process_madvise F
index 155c97479065a777c6bc3284ab2265851fd33957..9bb7c76f94197cb81f3b168d3472fca29352f088 100644 (file)
@@ -2701,3 +2701,4 @@ GLIBC_2.35 posix_spawn_file_actions_addtcsetpgrp_np F
 GLIBC_2.36 pidfd_getfd F
 GLIBC_2.36 pidfd_open F
 GLIBC_2.36 pidfd_send_signal F
+GLIBC_2.36 process_madvise F
index 7a811120ea74732c6dd184f104060ea1a0c1613b..03e7820eeaf718ac5e74f724aa5a9a900eb1b347 100644 (file)
@@ -2696,6 +2696,7 @@ GLIBC_2.35 posix_spawn_file_actions_addtcsetpgrp_np F
 GLIBC_2.36 pidfd_getfd F
 GLIBC_2.36 pidfd_open F
 GLIBC_2.36 pidfd_send_signal F
+GLIBC_2.36 process_madvise F
 GLIBC_2.4 __confstr_chk F
 GLIBC_2.4 __fgets_chk F
 GLIBC_2.4 __fgets_unlocked_chk F
index 7d28dca5c190718cda4b9bf958998b4e8d7f05dc..3d70dc114090d05b924d09daa27bcf3844a6000b 100644 (file)
@@ -2694,6 +2694,7 @@ GLIBC_2.35 posix_spawn_file_actions_addtcsetpgrp_np F
 GLIBC_2.36 pidfd_getfd F
 GLIBC_2.36 pidfd_open F
 GLIBC_2.36 pidfd_send_signal F
+GLIBC_2.36 process_madvise F
 GLIBC_2.4 __confstr_chk F
 GLIBC_2.4 __fgets_chk F
 GLIBC_2.4 __fgets_unlocked_chk F
index 41790f0d63ff1b15f93554dfb4b24268921df7ab..5498e2ee3080e8a736f793f737875271e0ef4093 100644 (file)
@@ -2702,6 +2702,7 @@ GLIBC_2.35 posix_spawn_file_actions_addtcsetpgrp_np F
 GLIBC_2.36 pidfd_getfd F
 GLIBC_2.36 pidfd_open F
 GLIBC_2.36 pidfd_send_signal F
+GLIBC_2.36 process_madvise F
 GLIBC_2.4 __confstr_chk F
 GLIBC_2.4 __fgets_chk F
 GLIBC_2.4 __fgets_unlocked_chk F
index 9c15006c123264a436633104b29a9221e8b8b8c6..dbebed5d362358d7d6fa7dcf305069c876ef12b1 100644 (file)
@@ -2605,6 +2605,7 @@ GLIBC_2.35 posix_spawn_file_actions_addtcsetpgrp_np F
 GLIBC_2.36 pidfd_getfd F
 GLIBC_2.36 pidfd_open F
 GLIBC_2.36 pidfd_send_signal F
+GLIBC_2.36 process_madvise F
 GLIBC_2.4 __confstr_chk F
 GLIBC_2.4 __fgets_chk F
 GLIBC_2.4 __fgets_unlocked_chk F
index 27c0498b602aba1c5f3d4ba9cb76afd9219aaf2b..a0bfa86068eb6ca27c9ab5f24c389a0e8147ff5d 100644 (file)
@@ -2743,3 +2743,4 @@ GLIBC_2.35 posix_spawn_file_actions_addtcsetpgrp_np F
 GLIBC_2.36 pidfd_getfd F
 GLIBC_2.36 pidfd_open F
 GLIBC_2.36 pidfd_send_signal F
+GLIBC_2.36 process_madvise F
index e500d4756f5fe46a63e72ec20a8ff56a8bcdcee8..7d09a03d0e1a8c9ae0114e6ee332b3c78005268c 100644 (file)
@@ -2126,3 +2126,4 @@ GLIBC_2.35 wscanf F
 GLIBC_2.36 pidfd_getfd F
 GLIBC_2.36 pidfd_open F
 GLIBC_2.36 pidfd_send_signal F
+GLIBC_2.36 process_madvise F
index adb21db204a36d598c9af17871e5a433573ad79f..db8fc28e751e473e5991157b9bf32476bdef425f 100644 (file)
@@ -2758,6 +2758,7 @@ GLIBC_2.35 posix_spawn_file_actions_addtcsetpgrp_np F
 GLIBC_2.36 pidfd_getfd F
 GLIBC_2.36 pidfd_open F
 GLIBC_2.36 pidfd_send_signal F
+GLIBC_2.36 process_madvise F
 GLIBC_2.4 _IO_fprintf F
 GLIBC_2.4 _IO_printf F
 GLIBC_2.4 _IO_sprintf F
index 28a08c4afb2c63889cfbdfca7fd784ac3b48debe..e6cbb83b26a608ceaaf65e20316d59fd58fbeebf 100644 (file)
@@ -2791,6 +2791,7 @@ GLIBC_2.35 posix_spawn_file_actions_addtcsetpgrp_np F
 GLIBC_2.36 pidfd_getfd F
 GLIBC_2.36 pidfd_open F
 GLIBC_2.36 pidfd_send_signal F
+GLIBC_2.36 process_madvise F
 GLIBC_2.4 _IO_fprintf F
 GLIBC_2.4 _IO_printf F
 GLIBC_2.4 _IO_sprintf F
index 98c5f3e61ca4e06e4be85726e6d778b392b603d1..162241fc68a63b06a03d9d61482d9af79fde16a4 100644 (file)
@@ -2513,6 +2513,7 @@ GLIBC_2.35 posix_spawn_file_actions_addtcsetpgrp_np F
 GLIBC_2.36 pidfd_getfd F
 GLIBC_2.36 pidfd_open F
 GLIBC_2.36 pidfd_send_signal F
+GLIBC_2.36 process_madvise F
 GLIBC_2.4 _IO_fprintf F
 GLIBC_2.4 _IO_printf F
 GLIBC_2.4 _IO_sprintf F
index 31e5aa90cdda88b9117b55a557eb288a5939b432..2845ee20152541b67d11f645f23bc9f7991b2569 100644 (file)
@@ -2815,3 +2815,4 @@ GLIBC_2.35 posix_spawn_file_actions_addtcsetpgrp_np F
 GLIBC_2.36 pidfd_getfd F
 GLIBC_2.36 pidfd_open F
 GLIBC_2.36 pidfd_send_signal F
+GLIBC_2.36 process_madvise F
index 87d90bf6684cc8b140d99a9b17efee1f39609d30..277f6fbe9523aff0c936724db95cf1adadc6ce0f 100644 (file)
@@ -2382,3 +2382,4 @@ GLIBC_2.35 posix_spawn_file_actions_addtcsetpgrp_np F
 GLIBC_2.36 pidfd_getfd F
 GLIBC_2.36 pidfd_open F
 GLIBC_2.36 pidfd_send_signal F
+GLIBC_2.36 process_madvise F
index b4a8f56aa24642d943c7c32b37bfe2daf39107a0..6f2a4d4504019c5d7d25ff2076aadcf50923a141 100644 (file)
@@ -2582,3 +2582,4 @@ GLIBC_2.35 posix_spawn_file_actions_addtcsetpgrp_np F
 GLIBC_2.36 pidfd_getfd F
 GLIBC_2.36 pidfd_open F
 GLIBC_2.36 pidfd_send_signal F
+GLIBC_2.36 process_madvise F
index e4a58cc1451ddba47aae2437734b27afbcad9ec3..bfb317488daf5516582467d4c88ec0cbfd2c6bde 100644 (file)
@@ -2756,6 +2756,7 @@ GLIBC_2.35 posix_spawn_file_actions_addtcsetpgrp_np F
 GLIBC_2.36 pidfd_getfd F
 GLIBC_2.36 pidfd_open F
 GLIBC_2.36 pidfd_send_signal F
+GLIBC_2.36 process_madvise F
 GLIBC_2.4 _IO_fprintf F
 GLIBC_2.4 _IO_printf F
 GLIBC_2.4 _IO_sprintf F
index ef0f0c3fa177645cf3db3958304a718e8e9a8a6d..beef51697942dbcae2ad9aeffa116f2dd1628829 100644 (file)
@@ -2550,6 +2550,7 @@ GLIBC_2.35 posix_spawn_file_actions_addtcsetpgrp_np F
 GLIBC_2.36 pidfd_getfd F
 GLIBC_2.36 pidfd_open F
 GLIBC_2.36 pidfd_send_signal F
+GLIBC_2.36 process_madvise F
 GLIBC_2.4 _IO_fprintf F
 GLIBC_2.4 _IO_printf F
 GLIBC_2.4 _IO_sprintf F
index 603d50668f20f6d10f91a56ee3efcd96eed6be7e..c326c9320a624c8c05eecc1fe3348cb9a6fd4ed4 100644 (file)
@@ -2611,6 +2611,7 @@ GLIBC_2.35 posix_spawn_file_actions_addtcsetpgrp_np F
 GLIBC_2.36 pidfd_getfd F
 GLIBC_2.36 pidfd_open F
 GLIBC_2.36 pidfd_send_signal F
+GLIBC_2.36 process_madvise F
 GLIBC_2.4 __confstr_chk F
 GLIBC_2.4 __fgets_chk F
 GLIBC_2.4 __fgets_unlocked_chk F
index 078cdf05a714beebefa21af7abe9461c682764bb..704f489a8eb559cde72607e33c6c9fd2925f8e15 100644 (file)
@@ -2608,6 +2608,7 @@ GLIBC_2.35 posix_spawn_file_actions_addtcsetpgrp_np F
 GLIBC_2.36 pidfd_getfd F
 GLIBC_2.36 pidfd_open F
 GLIBC_2.36 pidfd_send_signal F
+GLIBC_2.36 process_madvise F
 GLIBC_2.4 __confstr_chk F
 GLIBC_2.4 __fgets_chk F
 GLIBC_2.4 __fgets_unlocked_chk F
index 735505ac516ec89d2e142c8d00288e34779c4ad1..b9e8a341536b115f3e441d81dc1c2f581235fc9f 100644 (file)
@@ -2751,6 +2751,7 @@ GLIBC_2.35 posix_spawn_file_actions_addtcsetpgrp_np F
 GLIBC_2.36 pidfd_getfd F
 GLIBC_2.36 pidfd_open F
 GLIBC_2.36 pidfd_send_signal F
+GLIBC_2.36 process_madvise F
 GLIBC_2.4 _IO_fprintf F
 GLIBC_2.4 _IO_printf F
 GLIBC_2.4 _IO_sprintf F
index 48df7952cdf1390f46e9e3134a590c4f0ff81351..e921a8dd76a032e406dd014f4428cf64df3ecf1b 100644 (file)
@@ -2577,6 +2577,7 @@ GLIBC_2.35 posix_spawn_file_actions_addtcsetpgrp_np F
 GLIBC_2.36 pidfd_getfd F
 GLIBC_2.36 pidfd_open F
 GLIBC_2.36 pidfd_send_signal F
+GLIBC_2.36 process_madvise F
 GLIBC_2.4 __confstr_chk F
 GLIBC_2.4 __fgets_chk F
 GLIBC_2.4 __fgets_unlocked_chk F
index d9653bb433ce64c99faad0b9ab37ca43cb888eb7..2d664ea3f5feb3b9cde04e3d876d522bdeaa4eb4 100644 (file)
@@ -43,6 +43,7 @@ pidfd_open    EXTRA   pidfd_open      i:iU    pidfd_open
 pidfd_getfd    EXTRA   pidfd_getfd     i:iiU   pidfd_getfd
 pivot_root     EXTRA   pivot_root      i:ss    pivot_root
 pidfd_send_signal      EXTRA   pidfd_send_signal       i:iiPU  pidfd_send_signal
+process_madvise EXTRA   process_madvise i:iPniU process_madvise
 query_module   EXTRA   query_module    i:sipip __compat_query_module   query_module@GLIBC_2.0:GLIBC_2.23
 quotactl       EXTRA   quotactl        i:isip  quotactl
 remap_file_pages -     remap_file_pages i:pUiUi        __remap_file_pages remap_file_pages
diff --git a/sysdeps/unix/sysv/linux/tst-process_madvise.c b/sysdeps/unix/sysv/linux/tst-process_madvise.c
new file mode 100644 (file)
index 0000000..a674e80
--- /dev/null
@@ -0,0 +1,141 @@
+/* Basic tests for Linux process_madvise.
+   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 <array_length.h>
+#include <errno.h>
+#include <limits.h>
+#include <stdlib.h>
+#include <support/check.h>
+#include <support/process_state.h>
+#include <support/support.h>
+#include <support/xsocket.h>
+#include <support/xunistd.h>
+#include <sys/mman.h>
+#include <sys/pidfd.h>
+#include <sys/wait.h>
+
+/* The pair of sockets used for coordination.  The subprocess uses
+   sockets[1].  */
+static int sockets[2];
+
+static long int page_size;
+
+static void
+exit_subprocess (int dummy)
+{
+  exit (EXIT_FAILURE);
+}
+
+static void
+subprocess (void)
+{
+  /* In case something goes wrong with parent before pidfd_send_signal.  */
+  support_create_timer (5, 0, false, exit_subprocess);
+
+  void *p1 = xmmap (NULL, page_size * 2, PROT_READ | PROT_WRITE,
+                   MAP_PRIVATE | MAP_ANONYMOUS, -1);
+
+  void *p2 = xmmap (NULL, page_size, PROT_READ | PROT_WRITE,
+                   MAP_PRIVATE | MAP_ANONYMOUS, -1);
+  xmunmap(p2, page_size);
+
+  xsendto (sockets[1], &(struct iovec) { p1, page_size * 2 },
+          sizeof (struct iovec), 0, NULL, 0);
+
+  xsendto (sockets[1], &(struct iovec) { p2, page_size },
+          sizeof (struct iovec), 0, NULL, 0);
+
+  pause ();
+
+  _exit (0);
+}
+
+static int
+do_test (void)
+{
+  page_size = sysconf (_SC_PAGE_SIZE);
+
+  {
+    int r = pidfd_open (-1, 0);
+    TEST_COMPARE (r, -1);
+    if (errno == ENOSYS)
+      FAIL_UNSUPPORTED ("kernel does not support pidfd_open, skipping test");
+
+    TEST_COMPARE (errno, EINVAL);
+  }
+
+  TEST_COMPARE (socketpair (AF_UNIX, SOCK_STREAM, 0, sockets), 0);
+
+  pid_t pid = xfork ();
+  if (pid == 0)
+    {
+      xclose (sockets[0]);
+      subprocess ();
+    }
+  xclose (sockets[1]);
+
+  int pidfd = pidfd_open (pid, 0);
+  TEST_VERIFY (pidfd != -1);
+
+  /* The target process is going to send us two iovec's.  The first one points
+     to a valid mapping, the other points to a previously valid mapping which
+     has now been unmapped.  */
+  {
+    struct iovec iv;
+    xrecvfrom (sockets[0], &iv, sizeof (iv), 0, NULL, 0);
+
+    /* We expect this to succeed in the target process because the mapping
+       is valid.  */
+    TEST_COMPARE (process_madvise (pidfd, &iv, 1, MADV_COLD, 0),
+                 2 * page_size);
+  }
+
+  {
+    struct iovec iv;
+    xrecvfrom (sockets[0], &iv, sizeof (iv), 0, NULL, 0);
+
+    /* We expect this to fail in the target process because the second iovec
+       points to an unmapped region.  The target process arranges for this to
+       be the case.  */
+    TEST_COMPARE (process_madvise (pidfd, &iv, 1, MADV_COLD, 0), -1);
+    TEST_COMPARE (errno, ENOMEM);
+  }
+
+  {
+    struct iovec iv[IOV_MAX + 1];
+    TEST_COMPARE (process_madvise (pidfd, iv, array_length (iv), MADV_COLD,
+                                  0), -1);
+    TEST_COMPARE (errno, EINVAL);
+  }
+
+  TEST_COMPARE (pidfd_send_signal (pidfd, SIGKILL, NULL, 0), 0);
+  {
+    siginfo_t info;
+    int r = waitid (P_PIDFD, pidfd, &info, WEXITED);
+    TEST_COMPARE (r, 0);
+    TEST_COMPARE (info.si_status, SIGKILL);
+    TEST_COMPARE (info.si_code, CLD_KILLED);
+  }
+
+  TEST_COMPARE (pidfd_send_signal (pidfd, SIGKILL, NULL, 0), -1);
+  TEST_COMPARE (errno, ESRCH);
+
+  return 0;
+}
+
+#include <support/test-driver.c>
index 1629fb77621a28468ee65b1c09940b38c91c3f54..8948dc2705f8519bc4d8e869fc162c9e867a1080 100644 (file)
@@ -2528,6 +2528,7 @@ GLIBC_2.35 posix_spawn_file_actions_addtcsetpgrp_np F
 GLIBC_2.36 pidfd_getfd F
 GLIBC_2.36 pidfd_open F
 GLIBC_2.36 pidfd_send_signal F
+GLIBC_2.36 process_madvise F
 GLIBC_2.4 __confstr_chk F
 GLIBC_2.4 __fgets_chk F
 GLIBC_2.4 __fgets_unlocked_chk F
index ee9674ff75df49cf2450147328d80ec618849277..0988804f243fd42a43489832c0718ff994c3a59a 100644 (file)
@@ -2634,3 +2634,4 @@ GLIBC_2.35 posix_spawn_file_actions_addtcsetpgrp_np F
 GLIBC_2.36 pidfd_getfd F
 GLIBC_2.36 pidfd_open F
 GLIBC_2.36 pidfd_send_signal F
+GLIBC_2.36 process_madvise F