tools/testing/selftests/pidfd/pidfd.h
Source file repositories/reference/linux-study-clean/tools/testing/selftests/pidfd/pidfd.h
File Facts
- System
- Linux kernel
- Corpus path
tools/testing/selftests/pidfd/pidfd.h- Extension
.h- Size
- 6988 bytes
- Lines
- 316
- Domain
- Support Tooling And Documentation
- Bucket
- tools
- Inferred role
- Support Tooling And Documentation: implementation source
- Status
- source implementation candidate
Why This File Exists
Repository support layer: documentation, build tooling, samples, user-space helper tools, generated initramfs support, licenses, and validation utilities.
- Repository support layer: documentation, build tooling, samples, user-space helper tools, generated initramfs support, licenses, and validation utilities.
- Touches IRQ or DMA behavior; this matters for the representative real-device path.
- Defines or uses C structs; map object ownership, embedded links, reference counts, and lock ownership.
Dependency Surface
errno.hfcntl.hsched.hsignal.hstdio.hstdlib.hstring.hsyscall.hsys/ioctl.hsys/types.hsys/wait.hkselftest.h../clone3/clone3_selftests.h
Detected Declarations
struct pidfd_infofunction sys_waitidfunction wait_for_pidfunction sys_pidfd_openfunction sys_pidfd_send_signalfunction sys_pidfd_getfdfunction sys_memfd_createfunction create_childfunction read_nointrfunction write_nointrfunction sys_execveat
Annotated Snippet
struct pidfd_info {
__u64 mask;
__u64 cgroupid;
__u32 pid;
__u32 tgid;
__u32 ppid;
__u32 ruid;
__u32 rgid;
__u32 euid;
__u32 egid;
__u32 suid;
__u32 sgid;
__u32 fsuid;
__u32 fsgid;
__s32 exit_code;
struct {
__u32 coredump_mask;
__u32 coredump_signal;
__u32 coredump_code;
};
__u64 supported_mask;
};
/*
* The kernel reserves 300 pids via RESERVED_PIDS in kernel/pid.c
* That means, when it wraps around any pid < 300 will be skipped.
* So we need to use a pid > 300 in order to test recycling.
*/
#define PID_RECYCLE 1000
/*
* Define a few custom error codes for the child process to clearly indicate
* what is happening. This way we can tell the difference between a system
* error, a test error, etc.
*/
#define PIDFD_PASS 0
#define PIDFD_FAIL 1
#define PIDFD_ERROR 2
#define PIDFD_SKIP 3
#define PIDFD_XFAIL 4
static inline int sys_waitid(int which, pid_t pid, siginfo_t *info, int options)
{
return syscall(__NR_waitid, which, pid, info, options, NULL);
}
static inline int wait_for_pid(pid_t pid)
{
int status, ret;
again:
ret = waitpid(pid, &status, 0);
if (ret == -1) {
if (errno == EINTR)
goto again;
ksft_print_msg("waitpid returned -1, errno=%d\n", errno);
return -1;
}
if (!WIFEXITED(status)) {
ksft_print_msg(
"waitpid !WIFEXITED, WIFSIGNALED=%d, WTERMSIG=%d\n",
WIFSIGNALED(status), WTERMSIG(status));
return -1;
}
ret = WEXITSTATUS(status);
return ret;
}
static inline int sys_pidfd_open(pid_t pid, unsigned int flags)
{
return syscall(__NR_pidfd_open, pid, flags);
}
static inline int sys_pidfd_send_signal(int pidfd, int sig, siginfo_t *info,
unsigned int flags)
{
return syscall(__NR_pidfd_send_signal, pidfd, sig, info, flags);
}
static inline int sys_pidfd_getfd(int pidfd, int fd, int flags)
{
return syscall(__NR_pidfd_getfd, pidfd, fd, flags);
}
static inline int sys_memfd_create(const char *name, unsigned int flags)
{
return syscall(__NR_memfd_create, name, flags);
Annotation
- Immediate include surface: `errno.h`, `fcntl.h`, `sched.h`, `signal.h`, `stdio.h`, `stdlib.h`, `string.h`, `syscall.h`.
- Detected declarations: `struct pidfd_info`, `function sys_waitid`, `function wait_for_pid`, `function sys_pidfd_open`, `function sys_pidfd_send_signal`, `function sys_pidfd_getfd`, `function sys_memfd_create`, `function create_child`, `function read_nointr`, `function write_nointr`.
- Atlas domain: Support Tooling And Documentation / tools.
- Implementation status: source implementation candidate.
- IRQ or DMA behavior appears here, which is relevant to the selected PCIe/NVMe device path.
Implementation Notes
- This generated page is the file-by-file coverage layer; curated subsystem chapters should link here when they synthesize a multi-file control flow.
- Core OS pages should be promoted from atlas-only to deep-reviewed when they explain data structures, invariants, locking, lifecycle, and C implementation snippets.
- Driver-family pages are intentionally pattern-oriented unless they are part of the selected PCIe/NVMe representative device path.