pid_namespace.h 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  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. #endif
  27. #ifdef CONFIG_BSD_PROCESS_ACCT
  28. struct bsd_acct_struct *bacct;
  29. #endif
  30. struct user_namespace *user_ns;
  31. struct work_struct proc_work;
  32. kgid_t pid_gid;
  33. int hide_pid;
  34. int reboot; /* group exit code if this pidns was rebooted */
  35. unsigned int proc_inum;
  36. };
  37. extern struct pid_namespace init_pid_ns;
  38. #define PIDNS_HASH_ADDING (1U << 31)
  39. #ifdef CONFIG_PID_NS
  40. static inline struct pid_namespace *get_pid_ns(struct pid_namespace *ns)
  41. {
  42. if (ns != &init_pid_ns)
  43. kref_get(&ns->kref);
  44. return ns;
  45. }
  46. extern struct pid_namespace *copy_pid_ns(unsigned long flags,
  47. struct user_namespace *user_ns, struct pid_namespace *ns);
  48. extern void zap_pid_ns_processes(struct pid_namespace *pid_ns);
  49. extern int reboot_pid_ns(struct pid_namespace *pid_ns, int cmd);
  50. extern void put_pid_ns(struct pid_namespace *ns);
  51. #else /* !CONFIG_PID_NS */
  52. #include <linux/err.h>
  53. static inline struct pid_namespace *get_pid_ns(struct pid_namespace *ns)
  54. {
  55. return ns;
  56. }
  57. static inline struct pid_namespace *copy_pid_ns(unsigned long flags,
  58. struct user_namespace *user_ns, struct pid_namespace *ns)
  59. {
  60. if (flags & CLONE_NEWPID)
  61. ns = ERR_PTR(-EINVAL);
  62. return ns;
  63. }
  64. static inline void put_pid_ns(struct pid_namespace *ns)
  65. {
  66. }
  67. static inline void zap_pid_ns_processes(struct pid_namespace *ns)
  68. {
  69. BUG();
  70. }
  71. static inline int reboot_pid_ns(struct pid_namespace *pid_ns, int cmd)
  72. {
  73. return 0;
  74. }
  75. #endif /* CONFIG_PID_NS */
  76. extern struct pid_namespace *task_active_pid_ns(struct task_struct *tsk);
  77. void pidhash_init(void);
  78. void pidmap_init(void);
  79. #endif /* _LINUX_PID_NS_H */