123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217 |
- #ifndef _LINUX_PID_H
- #define _LINUX_PID_H
- #include <linux/rculist.h>
- #include <linux/wait.h>
- #include <linux/refcount.h>
- enum pid_type
- {
- PIDTYPE_PID,
- PIDTYPE_TGID,
- PIDTYPE_PGID,
- PIDTYPE_SID,
- PIDTYPE_MAX,
- };
- struct upid {
- int nr;
- struct pid_namespace *ns;
- };
- struct pid
- {
- refcount_t count;
- unsigned int level;
- spinlock_t lock;
-
- struct hlist_head tasks[PIDTYPE_MAX];
- struct hlist_head inodes;
-
- wait_queue_head_t wait_pidfd;
- struct rcu_head rcu;
- struct upid numbers[1];
- };
- extern struct pid init_struct_pid;
- extern const struct file_operations pidfd_fops;
- struct file;
- extern struct pid *pidfd_pid(const struct file *file);
- struct pid *pidfd_get_pid(unsigned int fd, unsigned int *flags);
- struct task_struct *pidfd_get_task(int pidfd, unsigned int *flags);
- int pidfd_create(struct pid *pid, unsigned int flags);
- static inline struct pid *get_pid(struct pid *pid)
- {
- if (pid)
- refcount_inc(&pid->count);
- return pid;
- }
- extern void put_pid(struct pid *pid);
- extern struct task_struct *pid_task(struct pid *pid, enum pid_type);
- static inline bool pid_has_task(struct pid *pid, enum pid_type type)
- {
- return !hlist_empty(&pid->tasks[type]);
- }
- extern struct task_struct *get_pid_task(struct pid *pid, enum pid_type);
- extern struct pid *get_task_pid(struct task_struct *task, enum pid_type type);
- extern void attach_pid(struct task_struct *task, enum pid_type);
- extern void detach_pid(struct task_struct *task, enum pid_type);
- extern void change_pid(struct task_struct *task, enum pid_type,
- struct pid *pid);
- extern void exchange_tids(struct task_struct *task, struct task_struct *old);
- extern void transfer_pid(struct task_struct *old, struct task_struct *new,
- enum pid_type);
- struct pid_namespace;
- extern struct pid_namespace init_pid_ns;
- extern int pid_max;
- extern int pid_max_min, pid_max_max;
- extern struct pid *find_pid_ns(int nr, struct pid_namespace *ns);
- extern struct pid *find_vpid(int nr);
- extern struct pid *find_get_pid(int nr);
- extern struct pid *find_ge_pid(int nr, struct pid_namespace *);
- extern struct pid *alloc_pid(struct pid_namespace *ns, pid_t *set_tid,
- size_t set_tid_size);
- extern void free_pid(struct pid *pid);
- extern void disable_pid_allocation(struct pid_namespace *ns);
- static inline struct pid_namespace *ns_of_pid(struct pid *pid)
- {
- struct pid_namespace *ns = NULL;
- if (pid)
- ns = pid->numbers[pid->level].ns;
- return ns;
- }
- static inline bool is_child_reaper(struct pid *pid)
- {
- return pid->numbers[pid->level].nr == 1;
- }
- static inline pid_t pid_nr(struct pid *pid)
- {
- pid_t nr = 0;
- if (pid)
- nr = pid->numbers[0].nr;
- return nr;
- }
- pid_t pid_nr_ns(struct pid *pid, struct pid_namespace *ns);
- pid_t pid_vnr(struct pid *pid);
- #define do_each_pid_task(pid, type, task) \
- do { \
- if ((pid) != NULL) \
- hlist_for_each_entry_rcu((task), \
- &(pid)->tasks[type], pid_links[type]) {
-
- #define while_each_pid_task(pid, type, task) \
- if (type == PIDTYPE_PID) \
- break; \
- } \
- } while (0)
- #define do_each_pid_thread(pid, type, task) \
- do_each_pid_task(pid, type, task) { \
- struct task_struct *tg___ = task; \
- for_each_thread(tg___, task) {
- #define while_each_pid_thread(pid, type, task) \
- } \
- task = tg___; \
- } while_each_pid_task(pid, type, task)
- #endif
|