Debian Codegraph @

src/include/override/sys/pidfd.h

raw
1 /* SPDX-License-Identifier: LGPL-2.1-or-later */
2 #pragma once
3
4 #include <linux/types.h>
5 #include <signal.h>
6 #include <sys/ioctl.h>
7
8 /* Defined since glibc-2.36.
9 * Supported since kernel v5.3 (7615d9e1780e26e0178c93c55b73309a5dc093d7). */
10 int pidfd_open_shim(pid_t pid, unsigned flags);
11 #define pidfd_open pidfd_open_shim
12
13 /* Defined since glibc-2.36.
14 * Supported since kernel v5.1 (3eb39f47934f9d5a3027fe00d906a45fe3a15fad). */
15 int pidfd_send_signal_shim(int fd, int sig, siginfo_t *info, unsigned flags);
16 #define pidfd_send_signal pidfd_send_signal_shim
17
18 /* since glibc-2.41 */
19 #ifndef PIDFS_IOCTL_MAGIC
20 # define PIDFS_IOCTL_MAGIC 0xFF
21
22 # define PIDFD_GET_CGROUP_NAMESPACE _IO(PIDFS_IOCTL_MAGIC, 1)
23 # define PIDFD_GET_IPC_NAMESPACE _IO(PIDFS_IOCTL_MAGIC, 2)
24 # define PIDFD_GET_MNT_NAMESPACE _IO(PIDFS_IOCTL_MAGIC, 3)
25 # define PIDFD_GET_NET_NAMESPACE _IO(PIDFS_IOCTL_MAGIC, 4)
26 # define PIDFD_GET_PID_NAMESPACE _IO(PIDFS_IOCTL_MAGIC, 5)
27 # define PIDFD_GET_PID_FOR_CHILDREN_NAMESPACE _IO(PIDFS_IOCTL_MAGIC, 6)
28 # define PIDFD_GET_TIME_NAMESPACE _IO(PIDFS_IOCTL_MAGIC, 7)
29 # define PIDFD_GET_TIME_FOR_CHILDREN_NAMESPACE _IO(PIDFS_IOCTL_MAGIC, 8)
30 # define PIDFD_GET_USER_NAMESPACE _IO(PIDFS_IOCTL_MAGIC, 9)
31 # define PIDFD_GET_UTS_NAMESPACE _IO(PIDFS_IOCTL_MAGIC, 10)
32 #endif
33
34 /* defined in linux/pidfd.h */
35 #ifndef PIDFD_GET_INFO
36
37 /* Flags for pidfd_info. */
38 #define PIDFD_INFO_PID (1UL << 0) /* Always returned, even if not requested */
39 #define PIDFD_INFO_CREDS (1UL << 1) /* Always returned, even if not requested */
40 #define PIDFD_INFO_CGROUPID (1UL << 2) /* Always returned if available, even if not requested */
41 #define PIDFD_INFO_EXIT (1UL << 3) /* Only returned if requested. */
42 #define PIDFD_INFO_COREDUMP (1UL << 4) /* Only returned if requested. */
43 #define PIDFD_INFO_SUPPORTED_MASK (1UL << 5) /* Want/got supported mask flags */
44 #define PIDFD_INFO_COREDUMP_SIGNAL (1UL << 6) /* Always returned if PIDFD_INFO_COREDUMP is requested. */
45 #define PIDFD_INFO_COREDUMP_CODE (1UL << 7) /* Always returned if PIDFD_INFO_COREDUMP is requested. */
46
47 #define PIDFD_INFO_SIZE_VER0 64 /* sizeof first published struct */
48 #define PIDFD_INFO_SIZE_VER1 72 /* sizeof second published struct */
49 #define PIDFD_INFO_SIZE_VER2 80 /* sizeof third published struct */
50 #define PIDFD_INFO_SIZE_VER3 88 /* sizeof fourth published struct */
51
52 /*
53 * Values for @coredump_mask in pidfd_info.
54 * Only valid if PIDFD_INFO_COREDUMP is set in @mask.
55 *
56 * Note, the @PIDFD_COREDUMP_ROOT flag indicates that the generated
57 * coredump should be treated as sensitive and access should only be
58 * granted to privileged users.
59 */
60 #define PIDFD_COREDUMPED (1U << 0) /* Did crash and... */
61 #define PIDFD_COREDUMP_SKIP (1U << 1) /* coredumping generation was skipped. */
62 #define PIDFD_COREDUMP_USER (1U << 2) /* coredump was done as the user. */
63 #define PIDFD_COREDUMP_ROOT (1U << 3) /* coredump was done as root. */
64
65 struct pidfd_info {
66 /*
67 * This mask is similar to the request_mask in statx(2).
68 *
69 * Userspace indicates what extensions or expensive-to-calculate fields
70 * they want by setting the corresponding bits in mask. The kernel
71 * will ignore bits that it does not know about.
72 *
73 * When filling the structure, the kernel will only set bits
74 * corresponding to the fields that were actually filled by the kernel.
75 * This also includes any future extensions that might be automatically
76 * filled. If the structure size is too small to contain a field
77 * (requested or not), to avoid confusion the mask will not
78 * contain a bit for that field.
79 *
80 * As such, userspace MUST verify that mask contains the
81 * corresponding flags after the ioctl(2) returns to ensure that it is
82 * using valid data.
83 */
84 __u64 mask;
85 /*
86 * The information contained in the following fields might be stale at the
87 * time it is received, as the target process might have exited as soon as
88 * the IOCTL was processed, and there is no way to avoid that. However, it
89 * is guaranteed that if the call was successful, then the information was
90 * correct and referred to the intended process at the time the work was
91 * performed. */
92 __u64 cgroupid;
93 __u32 pid;
94 __u32 tgid;
95 __u32 ppid;
96 __u32 ruid;
97 __u32 rgid;
98 __u32 euid;
99 __u32 egid;
100 __u32 suid;
101 __u32 sgid;
102 __u32 fsuid;
103 __u32 fsgid;
104 __s32 exit_code; /* since kernel v6.15 (7477d7dce48a996ae4e4f0b5f7bd82de7ec9131b) */
105 struct { /* coredump info */
106 __u32 coredump_mask; /* since kernel v6.16 (1d8db6fd698de1f73b1a7d72aea578fdd18d9a87) */
107 __u32 coredump_signal; /* since kernel v6.19 (036375522be8425874e9e0f907c7127e315c7a52) */
108 __u32 coredump_code; /* since kernel v7.1 (701f7f4fbabbf4989ba6fbf033b160dd943221d5) */
109 __u32 coredump_pad; /* since kernel v7.1 (701f7f4fbabbf4989ba6fbf033b160dd943221d5) */
110 };
111 __u64 supported_mask; /* Mask flags that this kernel supports */
112 };
113
114 #define PIDFD_GET_INFO _IOWR(PIDFS_IOCTL_MAGIC, 11, struct pidfd_info)
115 #endif /* PIDFD_GET_INFO */