diff options
author | Adhemerval Zanella <adhemerval.zanella@linaro.org> | 2022-01-26 16:05:31 -0300 |
---|---|---|
committer | Adhemerval Zanella <adhemerval.zanella@linaro.org> | 2022-06-02 15:43:28 -0300 |
commit | d19ee3473d68ca0e794f3a8b7677a0983ae1342e (patch) | |
tree | 54f061e127a813931ddbb30c328978eb26a7b3ef /sysdeps/unix/sysv | |
parent | 7d3e91ba194cc4b5fe1c9017f3bd77533c123b97 (diff) | |
download | glibc-d19ee3473d68ca0e794f3a8b7677a0983ae1342e.zip glibc-d19ee3473d68ca0e794f3a8b7677a0983ae1342e.tar.gz glibc-d19ee3473d68ca0e794f3a8b7677a0983ae1342e.tar.bz2 |
linux: Add process_madvise
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>
Diffstat (limited to 'sysdeps/unix/sysv')
38 files changed, 214 insertions, 0 deletions
diff --git a/sysdeps/unix/sysv/linux/Makefile b/sysdeps/unix/sysv/linux/Makefile index 98b2324..627506d 100644 --- a/sysdeps/unix/sysv/linux/Makefile +++ b/sysdeps/unix/sysv/linux/Makefile @@ -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 diff --git a/sysdeps/unix/sysv/linux/Versions b/sysdeps/unix/sysv/linux/Versions index 694c64a..c13a3c4 100644 --- a/sysdeps/unix/sysv/linux/Versions +++ b/sysdeps/unix/sysv/linux/Versions @@ -303,6 +303,7 @@ libc { pidfd_open; pidfd_getfd; pidfd_send_signal; + process_madvise; } GLIBC_PRIVATE { # functions used in other libraries diff --git a/sysdeps/unix/sysv/linux/aarch64/libc.abilist b/sysdeps/unix/sysv/linux/aarch64/libc.abilist index 7602129..4d8e64c 100644 --- a/sysdeps/unix/sysv/linux/aarch64/libc.abilist +++ b/sysdeps/unix/sysv/linux/aarch64/libc.abilist @@ -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 diff --git a/sysdeps/unix/sysv/linux/alpha/libc.abilist b/sysdeps/unix/sysv/linux/alpha/libc.abilist index 5b39d60..36f3129 100644 --- a/sysdeps/unix/sysv/linux/alpha/libc.abilist +++ b/sysdeps/unix/sysv/linux/alpha/libc.abilist @@ -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 diff --git a/sysdeps/unix/sysv/linux/arc/libc.abilist b/sysdeps/unix/sysv/linux/arc/libc.abilist index e413302..2a1e346 100644 --- a/sysdeps/unix/sysv/linux/arc/libc.abilist +++ b/sysdeps/unix/sysv/linux/arc/libc.abilist @@ -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 diff --git a/sysdeps/unix/sysv/linux/arm/be/libc.abilist b/sysdeps/unix/sysv/linux/arm/be/libc.abilist index ade1b93..25de8a0 100644 --- a/sysdeps/unix/sysv/linux/arm/be/libc.abilist +++ b/sysdeps/unix/sysv/linux/arm/be/libc.abilist @@ -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 diff --git a/sysdeps/unix/sysv/linux/arm/le/libc.abilist b/sysdeps/unix/sysv/linux/arm/le/libc.abilist index 10e9153..e9cf9b1 100644 --- a/sysdeps/unix/sysv/linux/arm/le/libc.abilist +++ b/sysdeps/unix/sysv/linux/arm/le/libc.abilist @@ -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 index 0000000..20960e7 --- /dev/null +++ b/sysdeps/unix/sysv/linux/bits/mman_ext.h @@ -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 */ diff --git a/sysdeps/unix/sysv/linux/csky/libc.abilist b/sysdeps/unix/sysv/linux/csky/libc.abilist index 22618c7..66c2f28 100644 --- a/sysdeps/unix/sysv/linux/csky/libc.abilist +++ b/sysdeps/unix/sysv/linux/csky/libc.abilist @@ -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 diff --git a/sysdeps/unix/sysv/linux/hppa/libc.abilist b/sysdeps/unix/sysv/linux/hppa/libc.abilist index e2aea90..527880d 100644 --- a/sysdeps/unix/sysv/linux/hppa/libc.abilist +++ b/sysdeps/unix/sysv/linux/hppa/libc.abilist @@ -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 diff --git a/sysdeps/unix/sysv/linux/i386/libc.abilist b/sysdeps/unix/sysv/linux/i386/libc.abilist index 29ecca2..1497b8a 100644 --- a/sysdeps/unix/sysv/linux/i386/libc.abilist +++ b/sysdeps/unix/sysv/linux/i386/libc.abilist @@ -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 diff --git a/sysdeps/unix/sysv/linux/ia64/libc.abilist b/sysdeps/unix/sysv/linux/ia64/libc.abilist index 69a2ca2..abe351d 100644 --- a/sysdeps/unix/sysv/linux/ia64/libc.abilist +++ b/sysdeps/unix/sysv/linux/ia64/libc.abilist @@ -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 diff --git a/sysdeps/unix/sysv/linux/m68k/coldfire/libc.abilist b/sysdeps/unix/sysv/linux/m68k/coldfire/libc.abilist index 23cc4dd..130f7a6 100644 --- a/sysdeps/unix/sysv/linux/m68k/coldfire/libc.abilist +++ b/sysdeps/unix/sysv/linux/m68k/coldfire/libc.abilist @@ -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 diff --git a/sysdeps/unix/sysv/linux/m68k/m680x0/libc.abilist b/sysdeps/unix/sysv/linux/m68k/m680x0/libc.abilist index 2d1d8a3..cf59edb 100644 --- a/sysdeps/unix/sysv/linux/m68k/m680x0/libc.abilist +++ b/sysdeps/unix/sysv/linux/m68k/m680x0/libc.abilist @@ -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 diff --git a/sysdeps/unix/sysv/linux/microblaze/be/libc.abilist b/sysdeps/unix/sysv/linux/microblaze/be/libc.abilist index 7b6e88b..f1b927d 100644 --- a/sysdeps/unix/sysv/linux/microblaze/be/libc.abilist +++ b/sysdeps/unix/sysv/linux/microblaze/be/libc.abilist @@ -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 diff --git a/sysdeps/unix/sysv/linux/microblaze/le/libc.abilist b/sysdeps/unix/sysv/linux/microblaze/le/libc.abilist index 155c974..9bb7c76 100644 --- a/sysdeps/unix/sysv/linux/microblaze/le/libc.abilist +++ b/sysdeps/unix/sysv/linux/microblaze/le/libc.abilist @@ -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 diff --git a/sysdeps/unix/sysv/linux/mips/mips32/fpu/libc.abilist b/sysdeps/unix/sysv/linux/mips/mips32/fpu/libc.abilist index 7a81112..03e7820 100644 --- a/sysdeps/unix/sysv/linux/mips/mips32/fpu/libc.abilist +++ b/sysdeps/unix/sysv/linux/mips/mips32/fpu/libc.abilist @@ -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 diff --git a/sysdeps/unix/sysv/linux/mips/mips32/nofpu/libc.abilist b/sysdeps/unix/sysv/linux/mips/mips32/nofpu/libc.abilist index 7d28dca..3d70dc1 100644 --- a/sysdeps/unix/sysv/linux/mips/mips32/nofpu/libc.abilist +++ b/sysdeps/unix/sysv/linux/mips/mips32/nofpu/libc.abilist @@ -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 diff --git a/sysdeps/unix/sysv/linux/mips/mips64/n32/libc.abilist b/sysdeps/unix/sysv/linux/mips/mips64/n32/libc.abilist index 41790f0..5498e2e 100644 --- a/sysdeps/unix/sysv/linux/mips/mips64/n32/libc.abilist +++ b/sysdeps/unix/sysv/linux/mips/mips64/n32/libc.abilist @@ -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 diff --git a/sysdeps/unix/sysv/linux/mips/mips64/n64/libc.abilist b/sysdeps/unix/sysv/linux/mips/mips64/n64/libc.abilist index 9c15006..dbebed5 100644 --- a/sysdeps/unix/sysv/linux/mips/mips64/n64/libc.abilist +++ b/sysdeps/unix/sysv/linux/mips/mips64/n64/libc.abilist @@ -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 diff --git a/sysdeps/unix/sysv/linux/nios2/libc.abilist b/sysdeps/unix/sysv/linux/nios2/libc.abilist index 27c0498..a0bfa86 100644 --- a/sysdeps/unix/sysv/linux/nios2/libc.abilist +++ b/sysdeps/unix/sysv/linux/nios2/libc.abilist @@ -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 diff --git a/sysdeps/unix/sysv/linux/or1k/libc.abilist b/sysdeps/unix/sysv/linux/or1k/libc.abilist index e500d47..7d09a03 100644 --- a/sysdeps/unix/sysv/linux/or1k/libc.abilist +++ b/sysdeps/unix/sysv/linux/or1k/libc.abilist @@ -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 diff --git a/sysdeps/unix/sysv/linux/powerpc/powerpc32/fpu/libc.abilist b/sysdeps/unix/sysv/linux/powerpc/powerpc32/fpu/libc.abilist index adb21db..db8fc28 100644 --- a/sysdeps/unix/sysv/linux/powerpc/powerpc32/fpu/libc.abilist +++ b/sysdeps/unix/sysv/linux/powerpc/powerpc32/fpu/libc.abilist @@ -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 diff --git a/sysdeps/unix/sysv/linux/powerpc/powerpc32/nofpu/libc.abilist b/sysdeps/unix/sysv/linux/powerpc/powerpc32/nofpu/libc.abilist index 28a08c4..e6cbb83 100644 --- a/sysdeps/unix/sysv/linux/powerpc/powerpc32/nofpu/libc.abilist +++ b/sysdeps/unix/sysv/linux/powerpc/powerpc32/nofpu/libc.abilist @@ -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 diff --git a/sysdeps/unix/sysv/linux/powerpc/powerpc64/be/libc.abilist b/sysdeps/unix/sysv/linux/powerpc/powerpc64/be/libc.abilist index 98c5f3e..162241f 100644 --- a/sysdeps/unix/sysv/linux/powerpc/powerpc64/be/libc.abilist +++ b/sysdeps/unix/sysv/linux/powerpc/powerpc64/be/libc.abilist @@ -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 diff --git a/sysdeps/unix/sysv/linux/powerpc/powerpc64/le/libc.abilist b/sysdeps/unix/sysv/linux/powerpc/powerpc64/le/libc.abilist index 31e5aa9..2845ee2 100644 --- a/sysdeps/unix/sysv/linux/powerpc/powerpc64/le/libc.abilist +++ b/sysdeps/unix/sysv/linux/powerpc/powerpc64/le/libc.abilist @@ -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 diff --git a/sysdeps/unix/sysv/linux/riscv/rv32/libc.abilist b/sysdeps/unix/sysv/linux/riscv/rv32/libc.abilist index 87d90bf..277f6fb 100644 --- a/sysdeps/unix/sysv/linux/riscv/rv32/libc.abilist +++ b/sysdeps/unix/sysv/linux/riscv/rv32/libc.abilist @@ -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 diff --git a/sysdeps/unix/sysv/linux/riscv/rv64/libc.abilist b/sysdeps/unix/sysv/linux/riscv/rv64/libc.abilist index b4a8f56..6f2a4d4 100644 --- a/sysdeps/unix/sysv/linux/riscv/rv64/libc.abilist +++ b/sysdeps/unix/sysv/linux/riscv/rv64/libc.abilist @@ -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 diff --git a/sysdeps/unix/sysv/linux/s390/s390-32/libc.abilist b/sysdeps/unix/sysv/linux/s390/s390-32/libc.abilist index e4a58cc..bfb3174 100644 --- a/sysdeps/unix/sysv/linux/s390/s390-32/libc.abilist +++ b/sysdeps/unix/sysv/linux/s390/s390-32/libc.abilist @@ -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 diff --git a/sysdeps/unix/sysv/linux/s390/s390-64/libc.abilist b/sysdeps/unix/sysv/linux/s390/s390-64/libc.abilist index ef0f0c3..beef516 100644 --- a/sysdeps/unix/sysv/linux/s390/s390-64/libc.abilist +++ b/sysdeps/unix/sysv/linux/s390/s390-64/libc.abilist @@ -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 diff --git a/sysdeps/unix/sysv/linux/sh/be/libc.abilist b/sysdeps/unix/sysv/linux/sh/be/libc.abilist index 603d506..c326c93 100644 --- a/sysdeps/unix/sysv/linux/sh/be/libc.abilist +++ b/sysdeps/unix/sysv/linux/sh/be/libc.abilist @@ -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 diff --git a/sysdeps/unix/sysv/linux/sh/le/libc.abilist b/sysdeps/unix/sysv/linux/sh/le/libc.abilist index 078cdf0..704f489 100644 --- a/sysdeps/unix/sysv/linux/sh/le/libc.abilist +++ b/sysdeps/unix/sysv/linux/sh/le/libc.abilist @@ -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 diff --git a/sysdeps/unix/sysv/linux/sparc/sparc32/libc.abilist b/sysdeps/unix/sysv/linux/sparc/sparc32/libc.abilist index 735505a..b9e8a34 100644 --- a/sysdeps/unix/sysv/linux/sparc/sparc32/libc.abilist +++ b/sysdeps/unix/sysv/linux/sparc/sparc32/libc.abilist @@ -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 diff --git a/sysdeps/unix/sysv/linux/sparc/sparc64/libc.abilist b/sysdeps/unix/sysv/linux/sparc/sparc64/libc.abilist index 48df795..e921a8d 100644 --- a/sysdeps/unix/sysv/linux/sparc/sparc64/libc.abilist +++ b/sysdeps/unix/sysv/linux/sparc/sparc64/libc.abilist @@ -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 diff --git a/sysdeps/unix/sysv/linux/syscalls.list b/sysdeps/unix/sysv/linux/syscalls.list index d9653bb..2d664ea 100644 --- a/sysdeps/unix/sysv/linux/syscalls.list +++ b/sysdeps/unix/sysv/linux/syscalls.list @@ -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 index 0000000..a674e80 --- /dev/null +++ b/sysdeps/unix/sysv/linux/tst-process_madvise.c @@ -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> diff --git a/sysdeps/unix/sysv/linux/x86_64/64/libc.abilist b/sysdeps/unix/sysv/linux/x86_64/64/libc.abilist index 1629fb7..8948dc2 100644 --- a/sysdeps/unix/sysv/linux/x86_64/64/libc.abilist +++ b/sysdeps/unix/sysv/linux/x86_64/64/libc.abilist @@ -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 diff --git a/sysdeps/unix/sysv/linux/x86_64/x32/libc.abilist b/sysdeps/unix/sysv/linux/x86_64/x32/libc.abilist index ee9674f..0988804 100644 --- a/sysdeps/unix/sysv/linux/x86_64/x32/libc.abilist +++ b/sysdeps/unix/sysv/linux/x86_64/x32/libc.abilist @@ -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 |