xref: /linux-6.15/include/linux/pid_namespace.h (revision 021ada7d)
1 #ifndef _LINUX_PID_NS_H
2 #define _LINUX_PID_NS_H
3 
4 #include <linux/sched.h>
5 #include <linux/bug.h>
6 #include <linux/mm.h>
7 #include <linux/threads.h>
8 #include <linux/nsproxy.h>
9 #include <linux/kref.h>
10 
11 struct pidmap {
12        atomic_t nr_free;
13        void *page;
14 };
15 
16 #define PIDMAP_ENTRIES         ((PID_MAX_LIMIT + 8*PAGE_SIZE - 1)/PAGE_SIZE/8)
17 
18 struct bsd_acct_struct;
19 
20 struct pid_namespace {
21 	struct kref kref;
22 	struct pidmap pidmap[PIDMAP_ENTRIES];
23 	int last_pid;
24 	unsigned int nr_hashed;
25 	struct task_struct *child_reaper;
26 	struct kmem_cache *pid_cachep;
27 	unsigned int level;
28 	struct pid_namespace *parent;
29 #ifdef CONFIG_PROC_FS
30 	struct vfsmount *proc_mnt;
31 	struct dentry *proc_self;
32 #endif
33 #ifdef CONFIG_BSD_PROCESS_ACCT
34 	struct bsd_acct_struct *bacct;
35 #endif
36 	struct user_namespace *user_ns;
37 	struct work_struct proc_work;
38 	kgid_t pid_gid;
39 	int hide_pid;
40 	int reboot;	/* group exit code if this pidns was rebooted */
41 	unsigned int proc_inum;
42 };
43 
44 extern struct pid_namespace init_pid_ns;
45 
46 #define PIDNS_HASH_ADDING (1U << 31)
47 
48 #ifdef CONFIG_PID_NS
49 static inline struct pid_namespace *get_pid_ns(struct pid_namespace *ns)
50 {
51 	if (ns != &init_pid_ns)
52 		kref_get(&ns->kref);
53 	return ns;
54 }
55 
56 extern struct pid_namespace *copy_pid_ns(unsigned long flags,
57 	struct user_namespace *user_ns, struct pid_namespace *ns);
58 extern void zap_pid_ns_processes(struct pid_namespace *pid_ns);
59 extern int reboot_pid_ns(struct pid_namespace *pid_ns, int cmd);
60 extern void put_pid_ns(struct pid_namespace *ns);
61 
62 #else /* !CONFIG_PID_NS */
63 #include <linux/err.h>
64 
65 static inline struct pid_namespace *get_pid_ns(struct pid_namespace *ns)
66 {
67 	return ns;
68 }
69 
70 static inline struct pid_namespace *copy_pid_ns(unsigned long flags,
71 	struct user_namespace *user_ns, struct pid_namespace *ns)
72 {
73 	if (flags & CLONE_NEWPID)
74 		ns = ERR_PTR(-EINVAL);
75 	return ns;
76 }
77 
78 static inline void put_pid_ns(struct pid_namespace *ns)
79 {
80 }
81 
82 static inline void zap_pid_ns_processes(struct pid_namespace *ns)
83 {
84 	BUG();
85 }
86 
87 static inline int reboot_pid_ns(struct pid_namespace *pid_ns, int cmd)
88 {
89 	return 0;
90 }
91 #endif /* CONFIG_PID_NS */
92 
93 extern struct pid_namespace *task_active_pid_ns(struct task_struct *tsk);
94 void pidhash_init(void);
95 void pidmap_init(void);
96 
97 #endif /* _LINUX_PID_NS_H */
98