0001
0002 #ifndef _LINUX_PID_H
0003 #define _LINUX_PID_H
0004
0005 #include <linux/rculist.h>
0006 #include <linux/wait.h>
0007 #include <linux/refcount.h>
0008
0009 enum pid_type
0010 {
0011 PIDTYPE_PID,
0012 PIDTYPE_TGID,
0013 PIDTYPE_PGID,
0014 PIDTYPE_SID,
0015 PIDTYPE_MAX,
0016 };
0017
0018
0019
0020
0021
0022
0023
0024
0025
0026
0027
0028
0029
0030
0031
0032
0033
0034
0035
0036
0037
0038
0039
0040
0041
0042
0043
0044
0045
0046
0047
0048
0049
0050
0051
0052
0053
0054 struct upid {
0055 int nr;
0056 struct pid_namespace *ns;
0057 };
0058
0059 struct pid
0060 {
0061 refcount_t count;
0062 unsigned int level;
0063 spinlock_t lock;
0064
0065 struct hlist_head tasks[PIDTYPE_MAX];
0066 struct hlist_head inodes;
0067
0068 wait_queue_head_t wait_pidfd;
0069 struct rcu_head rcu;
0070 struct upid numbers[1];
0071 };
0072
0073 extern struct pid init_struct_pid;
0074
0075 extern const struct file_operations pidfd_fops;
0076
0077 struct file;
0078
0079 extern struct pid *pidfd_pid(const struct file *file);
0080 struct pid *pidfd_get_pid(unsigned int fd, unsigned int *flags);
0081 struct task_struct *pidfd_get_task(int pidfd, unsigned int *flags);
0082 int pidfd_create(struct pid *pid, unsigned int flags);
0083
0084 static inline struct pid *get_pid(struct pid *pid)
0085 {
0086 if (pid)
0087 refcount_inc(&pid->count);
0088 return pid;
0089 }
0090
0091 extern void put_pid(struct pid *pid);
0092 extern struct task_struct *pid_task(struct pid *pid, enum pid_type);
0093 static inline bool pid_has_task(struct pid *pid, enum pid_type type)
0094 {
0095 return !hlist_empty(&pid->tasks[type]);
0096 }
0097 extern struct task_struct *get_pid_task(struct pid *pid, enum pid_type);
0098
0099 extern struct pid *get_task_pid(struct task_struct *task, enum pid_type type);
0100
0101
0102
0103
0104 extern void attach_pid(struct task_struct *task, enum pid_type);
0105 extern void detach_pid(struct task_struct *task, enum pid_type);
0106 extern void change_pid(struct task_struct *task, enum pid_type,
0107 struct pid *pid);
0108 extern void exchange_tids(struct task_struct *task, struct task_struct *old);
0109 extern void transfer_pid(struct task_struct *old, struct task_struct *new,
0110 enum pid_type);
0111
0112 struct pid_namespace;
0113 extern struct pid_namespace init_pid_ns;
0114
0115 extern int pid_max;
0116 extern int pid_max_min, pid_max_max;
0117
0118
0119
0120
0121
0122
0123
0124
0125
0126
0127 extern struct pid *find_pid_ns(int nr, struct pid_namespace *ns);
0128 extern struct pid *find_vpid(int nr);
0129
0130
0131
0132
0133 extern struct pid *find_get_pid(int nr);
0134 extern struct pid *find_ge_pid(int nr, struct pid_namespace *);
0135
0136 extern struct pid *alloc_pid(struct pid_namespace *ns, pid_t *set_tid,
0137 size_t set_tid_size);
0138 extern void free_pid(struct pid *pid);
0139 extern void disable_pid_allocation(struct pid_namespace *ns);
0140
0141
0142
0143
0144
0145
0146
0147
0148
0149
0150
0151 static inline struct pid_namespace *ns_of_pid(struct pid *pid)
0152 {
0153 struct pid_namespace *ns = NULL;
0154 if (pid)
0155 ns = pid->numbers[pid->level].ns;
0156 return ns;
0157 }
0158
0159
0160
0161
0162
0163
0164
0165 static inline bool is_child_reaper(struct pid *pid)
0166 {
0167 return pid->numbers[pid->level].nr == 1;
0168 }
0169
0170
0171
0172
0173
0174
0175
0176
0177
0178
0179
0180
0181 static inline pid_t pid_nr(struct pid *pid)
0182 {
0183 pid_t nr = 0;
0184 if (pid)
0185 nr = pid->numbers[0].nr;
0186 return nr;
0187 }
0188
0189 pid_t pid_nr_ns(struct pid *pid, struct pid_namespace *ns);
0190 pid_t pid_vnr(struct pid *pid);
0191
0192 #define do_each_pid_task(pid, type, task) \
0193 do { \
0194 if ((pid) != NULL) \
0195 hlist_for_each_entry_rcu((task), \
0196 &(pid)->tasks[type], pid_links[type]) {
0197
0198
0199
0200
0201
0202 #define while_each_pid_task(pid, type, task) \
0203 if (type == PIDTYPE_PID) \
0204 break; \
0205 } \
0206 } while (0)
0207
0208 #define do_each_pid_thread(pid, type, task) \
0209 do_each_pid_task(pid, type, task) { \
0210 struct task_struct *tg___ = task; \
0211 for_each_thread(tg___, task) {
0212
0213 #define while_each_pid_thread(pid, type, task) \
0214 } \
0215 task = tg___; \
0216 } while_each_pid_task(pid, type, task)
0217 #endif