1 /* SPDX-License-Identifier: GPL-2.0 */
2 #ifndef _LINUX_PID_NS_H
3 #define _LINUX_PID_NS_H
5 #include <linux/sched.h>
8 #include <linux/workqueue.h>
9 #include <linux/threads.h>
10 #include <linux/nsproxy.h>
11 #include <linux/kref.h>
12 #include <linux/ns_common.h>
19 #define BITS_PER_PAGE (PAGE_SIZE * 8)
20 #define BITS_PER_PAGE_MASK (BITS_PER_PAGE-1)
21 #define PIDMAP_ENTRIES ((PID_MAX_LIMIT+BITS_PER_PAGE-1)/BITS_PER_PAGE)
25 enum { /* definitions for pid_namespace's hide_pid field */
27 HIDEPID_NO_ACCESS
= 1,
28 HIDEPID_INVISIBLE
= 2,
31 struct pid_namespace
{
33 struct pidmap pidmap
[PIDMAP_ENTRIES
];
36 unsigned int nr_hashed
;
37 struct task_struct
*child_reaper
;
38 struct kmem_cache
*pid_cachep
;
40 struct pid_namespace
*parent
;
42 struct vfsmount
*proc_mnt
;
43 struct dentry
*proc_self
;
44 struct dentry
*proc_thread_self
;
46 #ifdef CONFIG_BSD_PROCESS_ACCT
49 struct user_namespace
*user_ns
;
50 struct ucounts
*ucounts
;
51 struct work_struct proc_work
;
54 int reboot
; /* group exit code if this pidns was rebooted */
58 extern struct pid_namespace init_pid_ns
;
60 #define PIDNS_HASH_ADDING (1U << 31)
63 static inline struct pid_namespace
*get_pid_ns(struct pid_namespace
*ns
)
65 if (ns
!= &init_pid_ns
)
70 extern struct pid_namespace
*copy_pid_ns(unsigned long flags
,
71 struct user_namespace
*user_ns
, struct pid_namespace
*ns
);
72 extern void zap_pid_ns_processes(struct pid_namespace
*pid_ns
);
73 extern int reboot_pid_ns(struct pid_namespace
*pid_ns
, int cmd
);
74 extern void put_pid_ns(struct pid_namespace
*ns
);
76 #else /* !CONFIG_PID_NS */
77 #include <linux/err.h>
79 static inline struct pid_namespace
*get_pid_ns(struct pid_namespace
*ns
)
84 static inline struct pid_namespace
*copy_pid_ns(unsigned long flags
,
85 struct user_namespace
*user_ns
, struct pid_namespace
*ns
)
87 if (flags
& CLONE_NEWPID
)
88 ns
= ERR_PTR(-EINVAL
);
92 static inline void put_pid_ns(struct pid_namespace
*ns
)
96 static inline void zap_pid_ns_processes(struct pid_namespace
*ns
)
101 static inline int reboot_pid_ns(struct pid_namespace
*pid_ns
, int cmd
)
105 #endif /* CONFIG_PID_NS */
107 extern struct pid_namespace
*task_active_pid_ns(struct task_struct
*tsk
);
108 void pidhash_init(void);
109 void pidmap_init(void);
111 #endif /* _LINUX_PID_NS_H */