1 /* SPDX-License-Identifier: GPL-2.0 */
15 #include <sys/mount.h>
16 #include <sys/types.h>
19 #include "../kselftest.h"
26 #define CLONE_NEWTIME 0x00000080
30 #define CLONE_PIDFD 0x00001000
33 #ifndef __NR_pidfd_open
34 #define __NR_pidfd_open -1
37 #ifndef __NR_pidfd_send_signal
38 #define __NR_pidfd_send_signal -1
42 #define __NR_clone3 -1
45 #ifndef __NR_pidfd_getfd
46 #define __NR_pidfd_getfd -1
49 #ifndef PIDFD_NONBLOCK
50 #define PIDFD_NONBLOCK O_NONBLOCK
54 * The kernel reserves 300 pids via RESERVED_PIDS in kernel/pid.c
55 * That means, when it wraps around any pid < 300 will be skipped.
56 * So we need to use a pid > 300 in order to test recycling.
58 #define PID_RECYCLE 1000
61 * Define a few custom error codes for the child process to clearly indicate
62 * what is happening. This way we can tell the difference between a system
63 * error, a test error, etc.
71 static inline int wait_for_pid(pid_t pid)
76 ret = waitpid(pid, &status, 0);
81 ksft_print_msg("waitpid returned -1, errno=%d\n", errno);
85 if (!WIFEXITED(status)) {
87 "waitpid !WIFEXITED, WIFSIGNALED=%d, WTERMSIG=%d\n",
88 WIFSIGNALED(status), WTERMSIG(status));
92 ret = WEXITSTATUS(status);
96 static inline int sys_pidfd_open(pid_t pid, unsigned int flags)
98 return syscall(__NR_pidfd_open, pid, flags);
101 static inline int sys_pidfd_send_signal(int pidfd, int sig, siginfo_t *info,
104 return syscall(__NR_pidfd_send_signal, pidfd, sig, info, flags);
107 static inline int sys_pidfd_getfd(int pidfd, int fd, int flags)
109 return syscall(__NR_pidfd_getfd, pidfd, fd, flags);
112 static inline int sys_memfd_create(const char *name, unsigned int flags)
114 return syscall(__NR_memfd_create, name, flags);
117 #endif /* __PIDFD_H */