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
--- /dev/null
+/* 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
/* 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 */
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 \
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
pidfd_open;
pidfd_getfd;
pidfd_send_signal;
+ process_madvise;
}
GLIBC_PRIVATE {
# functions used in other libraries
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.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
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.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
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
--- /dev/null
+/* 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 */
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.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
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
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
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
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
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.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.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
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
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
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
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.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.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
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
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
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.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.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.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
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
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
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
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
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
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
--- /dev/null
+/* 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>
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
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