Back to home page

OSCL-LXR

 
 

    


0001 /* SPDX-License-Identifier: GPL-2.0 */
0002 #ifndef _LINUX_PID_NS_H
0003 #define _LINUX_PID_NS_H
0004 
0005 #include <linux/sched.h>
0006 #include <linux/bug.h>
0007 #include <linux/mm.h>
0008 #include <linux/workqueue.h>
0009 #include <linux/threads.h>
0010 #include <linux/nsproxy.h>
0011 #include <linux/ns_common.h>
0012 #include <linux/idr.h>
0013 
0014 /* MAX_PID_NS_LEVEL is needed for limiting size of 'struct pid' */
0015 #define MAX_PID_NS_LEVEL 32
0016 
0017 struct fs_pin;
0018 
0019 struct pid_namespace {
0020     struct idr idr;
0021     struct rcu_head rcu;
0022     unsigned int pid_allocated;
0023     struct task_struct *child_reaper;
0024     struct kmem_cache *pid_cachep;
0025     unsigned int level;
0026     struct pid_namespace *parent;
0027 #ifdef CONFIG_BSD_PROCESS_ACCT
0028     struct fs_pin *bacct;
0029 #endif
0030     struct user_namespace *user_ns;
0031     struct ucounts *ucounts;
0032     int reboot; /* group exit code if this pidns was rebooted */
0033     struct ns_common ns;
0034 } __randomize_layout;
0035 
0036 extern struct pid_namespace init_pid_ns;
0037 
0038 #define PIDNS_ADDING (1U << 31)
0039 
0040 #ifdef CONFIG_PID_NS
0041 static inline struct pid_namespace *get_pid_ns(struct pid_namespace *ns)
0042 {
0043     if (ns != &init_pid_ns)
0044         refcount_inc(&ns->ns.count);
0045     return ns;
0046 }
0047 
0048 extern struct pid_namespace *copy_pid_ns(unsigned long flags,
0049     struct user_namespace *user_ns, struct pid_namespace *ns);
0050 extern void zap_pid_ns_processes(struct pid_namespace *pid_ns);
0051 extern int reboot_pid_ns(struct pid_namespace *pid_ns, int cmd);
0052 extern void put_pid_ns(struct pid_namespace *ns);
0053 
0054 #else /* !CONFIG_PID_NS */
0055 #include <linux/err.h>
0056 
0057 static inline struct pid_namespace *get_pid_ns(struct pid_namespace *ns)
0058 {
0059     return ns;
0060 }
0061 
0062 static inline struct pid_namespace *copy_pid_ns(unsigned long flags,
0063     struct user_namespace *user_ns, struct pid_namespace *ns)
0064 {
0065     if (flags & CLONE_NEWPID)
0066         ns = ERR_PTR(-EINVAL);
0067     return ns;
0068 }
0069 
0070 static inline void put_pid_ns(struct pid_namespace *ns)
0071 {
0072 }
0073 
0074 static inline void zap_pid_ns_processes(struct pid_namespace *ns)
0075 {
0076     BUG();
0077 }
0078 
0079 static inline int reboot_pid_ns(struct pid_namespace *pid_ns, int cmd)
0080 {
0081     return 0;
0082 }
0083 #endif /* CONFIG_PID_NS */
0084 
0085 extern struct pid_namespace *task_active_pid_ns(struct task_struct *tsk);
0086 void pidhash_init(void);
0087 void pid_idr_init(void);
0088 
0089 static inline bool task_is_in_init_pid_ns(struct task_struct *tsk)
0090 {
0091     return task_active_pid_ns(tsk) == &init_pid_ns;
0092 }
0093 
0094 #endif /* _LINUX_PID_NS_H */