pid_namespace.h 2.2 KB

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