pid_namespace.h 2.2 KB

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