mirror of
https://sourceware.org/git/glibc.git
synced 2024-11-21 12:30:06 +00:00
linux: Add process_mrelease
Added in Linux 5.15 (884a7e5964e06ed93c7771c0d7cf19c09a8946f1), the new syscalls allows a caller to free the memory of a dying target process. Checked on x86_64-linux-gnu. Reviewed-by: Carlos O'Donell <carlos@redhat.com>
This commit is contained in:
parent
d19ee3473d
commit
1002f1af1c
5
NEWS
5
NEWS
@ -24,6 +24,11 @@ Major new features:
|
||||
same functionality as madvise but alters the target process identified
|
||||
by the pidfd.
|
||||
|
||||
* On Linux, the process_mrelease function has been added. It allows a
|
||||
caller to release the memory of a dying process. The release of the
|
||||
memory is carried out in the context of the caller, using the caller's
|
||||
CPU affinity, and priority with CPU usage accounted to the caller.
|
||||
|
||||
Deprecated and removed features, and other changes affecting compatibility:
|
||||
|
||||
* Support for prelink will be removed in the next release; this includes
|
||||
|
@ -129,6 +129,7 @@ tests += tst-clone tst-clone2 tst-clone3 tst-fanotify tst-personality \
|
||||
tst-epoll \
|
||||
tst-getauxval \
|
||||
tst-pidfd \
|
||||
tst-process_mrelease \
|
||||
# tests
|
||||
|
||||
# process_madvise requires CAP_SYS_ADMIN.
|
||||
|
@ -304,6 +304,7 @@ libc {
|
||||
pidfd_getfd;
|
||||
pidfd_send_signal;
|
||||
process_madvise;
|
||||
process_mrelease;
|
||||
}
|
||||
GLIBC_PRIVATE {
|
||||
# functions used in other libraries
|
||||
|
@ -2620,3 +2620,4 @@ 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 process_mrelease F
|
||||
|
@ -2717,6 +2717,7 @@ 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 process_mrelease F
|
||||
GLIBC_2.4 _IO_fprintf F
|
||||
GLIBC_2.4 _IO_printf F
|
||||
GLIBC_2.4 _IO_sprintf F
|
||||
|
@ -2381,3 +2381,4 @@ 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 process_mrelease F
|
||||
|
@ -500,6 +500,7 @@ 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 process_mrelease F
|
||||
GLIBC_2.4 _Exit F
|
||||
GLIBC_2.4 _IO_2_1_stderr_ D 0xa0
|
||||
GLIBC_2.4 _IO_2_1_stdin_ D 0xa0
|
||||
|
@ -497,6 +497,7 @@ 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 process_mrelease F
|
||||
GLIBC_2.4 _Exit F
|
||||
GLIBC_2.4 _IO_2_1_stderr_ D 0xa0
|
||||
GLIBC_2.4 _IO_2_1_stdin_ D 0xa0
|
||||
|
@ -30,4 +30,6 @@ extern __ssize_t process_madvise (int __pid_fd, const struct iovec* __iov,
|
||||
unsigned __flags)
|
||||
__THROW;
|
||||
|
||||
extern int process_mrelease (int pidfd, unsigned int flags) __THROW;
|
||||
|
||||
#endif /* __USE_GNU */
|
||||
|
@ -2656,3 +2656,4 @@ 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 process_mrelease F
|
||||
|
@ -2605,6 +2605,7 @@ 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 process_mrelease F
|
||||
GLIBC_2.4 __confstr_chk F
|
||||
GLIBC_2.4 __fgets_chk F
|
||||
GLIBC_2.4 __fgets_unlocked_chk F
|
||||
|
@ -2789,6 +2789,7 @@ 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 process_mrelease F
|
||||
GLIBC_2.4 __confstr_chk F
|
||||
GLIBC_2.4 __fgets_chk F
|
||||
GLIBC_2.4 __fgets_unlocked_chk F
|
||||
|
@ -2555,6 +2555,7 @@ 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 process_mrelease F
|
||||
GLIBC_2.4 __confstr_chk F
|
||||
GLIBC_2.4 __fgets_chk F
|
||||
GLIBC_2.4 __fgets_unlocked_chk F
|
||||
|
@ -501,6 +501,7 @@ 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 process_mrelease F
|
||||
GLIBC_2.4 _Exit F
|
||||
GLIBC_2.4 _IO_2_1_stderr_ D 0x98
|
||||
GLIBC_2.4 _IO_2_1_stdin_ D 0x98
|
||||
|
@ -2732,6 +2732,7 @@ 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 process_mrelease F
|
||||
GLIBC_2.4 __confstr_chk F
|
||||
GLIBC_2.4 __fgets_chk F
|
||||
GLIBC_2.4 __fgets_unlocked_chk F
|
||||
|
@ -2705,3 +2705,4 @@ 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 process_mrelease F
|
||||
|
@ -2702,3 +2702,4 @@ 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 process_mrelease F
|
||||
|
@ -2697,6 +2697,7 @@ 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 process_mrelease F
|
||||
GLIBC_2.4 __confstr_chk F
|
||||
GLIBC_2.4 __fgets_chk F
|
||||
GLIBC_2.4 __fgets_unlocked_chk F
|
||||
|
@ -2695,6 +2695,7 @@ 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 process_mrelease F
|
||||
GLIBC_2.4 __confstr_chk F
|
||||
GLIBC_2.4 __fgets_chk F
|
||||
GLIBC_2.4 __fgets_unlocked_chk F
|
||||
|
@ -2703,6 +2703,7 @@ 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 process_mrelease F
|
||||
GLIBC_2.4 __confstr_chk F
|
||||
GLIBC_2.4 __fgets_chk F
|
||||
GLIBC_2.4 __fgets_unlocked_chk F
|
||||
|
@ -2606,6 +2606,7 @@ 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 process_mrelease F
|
||||
GLIBC_2.4 __confstr_chk F
|
||||
GLIBC_2.4 __fgets_chk F
|
||||
GLIBC_2.4 __fgets_unlocked_chk F
|
||||
|
@ -2744,3 +2744,4 @@ 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 process_mrelease F
|
||||
|
@ -2127,3 +2127,4 @@ 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 process_mrelease F
|
||||
|
@ -2759,6 +2759,7 @@ 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 process_mrelease F
|
||||
GLIBC_2.4 _IO_fprintf F
|
||||
GLIBC_2.4 _IO_printf F
|
||||
GLIBC_2.4 _IO_sprintf F
|
||||
|
@ -2792,6 +2792,7 @@ 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 process_mrelease F
|
||||
GLIBC_2.4 _IO_fprintf F
|
||||
GLIBC_2.4 _IO_printf F
|
||||
GLIBC_2.4 _IO_sprintf F
|
||||
|
@ -2514,6 +2514,7 @@ 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 process_mrelease F
|
||||
GLIBC_2.4 _IO_fprintf F
|
||||
GLIBC_2.4 _IO_printf F
|
||||
GLIBC_2.4 _IO_sprintf F
|
||||
|
@ -2816,3 +2816,4 @@ 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 process_mrelease F
|
||||
|
@ -2383,3 +2383,4 @@ 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 process_mrelease F
|
||||
|
@ -2583,3 +2583,4 @@ 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 process_mrelease F
|
||||
|
@ -2757,6 +2757,7 @@ 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 process_mrelease F
|
||||
GLIBC_2.4 _IO_fprintf F
|
||||
GLIBC_2.4 _IO_printf F
|
||||
GLIBC_2.4 _IO_sprintf F
|
||||
|
@ -2551,6 +2551,7 @@ 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 process_mrelease F
|
||||
GLIBC_2.4 _IO_fprintf F
|
||||
GLIBC_2.4 _IO_printf F
|
||||
GLIBC_2.4 _IO_sprintf F
|
||||
|
@ -2612,6 +2612,7 @@ 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 process_mrelease F
|
||||
GLIBC_2.4 __confstr_chk F
|
||||
GLIBC_2.4 __fgets_chk F
|
||||
GLIBC_2.4 __fgets_unlocked_chk F
|
||||
|
@ -2609,6 +2609,7 @@ 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 process_mrelease F
|
||||
GLIBC_2.4 __confstr_chk F
|
||||
GLIBC_2.4 __fgets_chk F
|
||||
GLIBC_2.4 __fgets_unlocked_chk F
|
||||
|
@ -2752,6 +2752,7 @@ 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 process_mrelease F
|
||||
GLIBC_2.4 _IO_fprintf F
|
||||
GLIBC_2.4 _IO_printf F
|
||||
GLIBC_2.4 _IO_sprintf F
|
||||
|
@ -2578,6 +2578,7 @@ 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 process_mrelease F
|
||||
GLIBC_2.4 __confstr_chk F
|
||||
GLIBC_2.4 __fgets_chk F
|
||||
GLIBC_2.4 __fgets_unlocked_chk F
|
||||
|
@ -44,6 +44,7 @@ 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
|
||||
process_mrelease EXTRA process_mrelease i:iU process_mrelease
|
||||
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
|
||||
|
86
sysdeps/unix/sysv/linux/tst-process_mrelease.c
Normal file
86
sysdeps/unix/sysv/linux/tst-process_mrelease.c
Normal file
@ -0,0 +1,86 @@
|
||||
/* Basic tests for Linux process_mrelease.
|
||||
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 <stdlib.h>
|
||||
#include <support/check.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>
|
||||
|
||||
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);
|
||||
|
||||
pause ();
|
||||
_exit (0);
|
||||
}
|
||||
|
||||
static int
|
||||
do_test (void)
|
||||
{
|
||||
{
|
||||
int r = process_mrelease (-1, 0);
|
||||
TEST_COMPARE (r, -1);
|
||||
if (errno == ENOSYS)
|
||||
FAIL_UNSUPPORTED ("kernel does not support process_mrelease, "
|
||||
"skipping test");
|
||||
TEST_COMPARE (errno, EBADF);
|
||||
}
|
||||
|
||||
pid_t pid = xfork ();
|
||||
if (pid == 0)
|
||||
subprocess ();
|
||||
|
||||
int pidfd = pidfd_open (pid, 0);
|
||||
TEST_VERIFY (pidfd != -1);
|
||||
|
||||
/* The syscall only succeedes if the target process is exiting and there
|
||||
is no guarantee that calling if after pidfd_send_signal will not error
|
||||
(ince the process might have already been reaped by the OS). So just
|
||||
check if it does fail when the process is stll running. */
|
||||
TEST_COMPARE (process_mrelease (pidfd, 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>
|
@ -2529,6 +2529,7 @@ 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 process_mrelease F
|
||||
GLIBC_2.4 __confstr_chk F
|
||||
GLIBC_2.4 __fgets_chk F
|
||||
GLIBC_2.4 __fgets_unlocked_chk F
|
||||
|
@ -2635,3 +2635,4 @@ 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 process_mrelease F
|
||||
|
Loading…
Reference in New Issue
Block a user