staticint alloc_noexit(unsignedlong nr_pages, int pipefd)
{ int ppid = getppid(); int timeout = 10; /* 10sec timeout to get killed */ unsignedlong i; char *buf;
for (i = 0; i < nr_pages; i++)
*((unsignedlong *)(buf + (i * psize()))) = i;
/* Signal the parent that the child is ready */ if (write(pipefd, "", 1) < 0)
ksft_exit_fail_msg("write: %s\n", strerror(errno));
/* Wait to be killed (when reparenting happens) */ while (getppid() == ppid && timeout > 0) {
sleep(1);
timeout--;
}
munmap(buf, nr_pages * psize());
return (timeout > 0) ? KSFT_PASS : KSFT_FAIL;
}
/* The process_mrelease calls in this test are expected to fail */ staticvoid run_negative_tests(int pidfd)
{ /* Test invalid flags. Expect to fail with EINVAL error code. */ if (!syscall(__NR_process_mrelease, pidfd, (unsignedint)-1) ||
errno != EINVAL) {
ksft_exit_fail_msg("process_mrelease with wrong flags: %s\n", strerror(errno));
} /* *TestreapingwhileprocessisalivewithnopendingSIGKILL. *ExpecttofailwithEINVALerrorcode.
*/ if (!syscall(__NR_process_mrelease, pidfd, 0) || errno != EINVAL)
ksft_exit_fail_msg("process_mrelease on a live process: %s\n", strerror(errno));
}
staticint child_main(int pipefd[], size_t size)
{ int res;
/* Allocate and fault-in memory and wait to be killed */
close(pipefd[0]);
res = alloc_noexit(MB(size) / psize(), pipefd[1]);
close(pipefd[1]); return res;
}
int main(void)
{ int pipefd[2], pidfd; bool success, retry;
size_t size;
pid_t pid; char byte; int res;
ksft_print_header();
ksft_set_plan(1);
/* Test a wrong pidfd */ if (!syscall(__NR_process_mrelease, -1, 0) || errno != EBADF) { if (errno == ENOSYS) {
ksft_test_result_skip("process_mrelease not implemented\n");
ksft_finished();
} else {
ksft_exit_fail_msg("process_mrelease with wrong pidfd: %s",
strerror(errno));
}
}
/* Start the test with 1MB child memory allocation */
size = 1;
retry: /* *Pipeforthechildtosignalwhenit'sdoneallocating *memory
*/ if (pipe(pipefd))
ksft_exit_fail_msg("pipe: %s\n", strerror(errno));
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.