pid_namespace.h 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  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. 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. };
  36. extern struct pid_namespace init_pid_ns;
  37. #ifdef CONFIG_PID_NS
  38. static inline struct pid_namespace *get_pid_ns(struct pid_namespace *ns)
  39. {
  40. if (ns != &init_pid_ns)
  41. kref_get(&ns->kref);
  42. return ns;
  43. }
  44. extern struct pid_namespace *copy_pid_ns(unsigned long flags,
  45. struct user_namespace *user_ns, struct pid_namespace *ns);
  46. extern void zap_pid_ns_processes(struct pid_namespace *pid_ns);
  47. extern int reboot_pid_ns(struct pid_namespace *pid_ns, int cmd);
  48. extern void put_pid_ns(struct pid_namespace *ns);
  49. #else /* !CONFIG_PID_NS */
  50. #include <linux/err.h>
  51. static inline struct pid_namespace *get_pid_ns(struct pid_namespace *ns)
  52. {
  53. return ns;
  54. }
  55. static inline struct pid_namespace *copy_pid_ns(unsigned long flags,
  56. struct user_namespace *user_ns, struct pid_namespace *ns)
  57. {
  58. if (flags & CLONE_NEWPID)
  59. ns = ERR_PTR(-EINVAL);
  60. return ns;
  61. }
  62. static inline void put_pid_ns(struct pid_namespace *ns)
  63. {
  64. }
  65. static inline void zap_pid_ns_processes(struct pid_namespace *ns)
  66. {
  67. BUG();
  68. }
  69. static inline int reboot_pid_ns(struct pid_namespace *pid_ns, int cmd)
  70. {
  71. return 0;
  72. }
  73. #endif /* CONFIG_PID_NS */
  74. extern struct pid_namespace *task_active_pid_ns(struct task_struct *tsk);
  75. void pidhash_init(void);
  76. void pidmap_init(void);
  77. #endif /* _LINUX_PID_NS_H */