pid_namespace.h 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  1. #ifndef _LINUX_PID_NS_H
  2. #define _LINUX_PID_NS_H
  3. #include <linux/sched.h>
  4. #include <linux/mm.h>
  5. #include <linux/threads.h>
  6. #include <linux/nsproxy.h>
  7. #include <linux/kref.h>
  8. struct pidmap {
  9. atomic_t nr_free;
  10. void *page;
  11. };
  12. #define PIDMAP_ENTRIES ((PID_MAX_LIMIT + 8*PAGE_SIZE - 1)/PAGE_SIZE/8)
  13. struct pid_namespace {
  14. struct kref kref;
  15. struct pidmap pidmap[PIDMAP_ENTRIES];
  16. int last_pid;
  17. struct task_struct *child_reaper;
  18. struct kmem_cache *pid_cachep;
  19. int level;
  20. struct pid_namespace *parent;
  21. #ifdef CONFIG_PROC_FS
  22. struct vfsmount *proc_mnt;
  23. #endif
  24. };
  25. extern struct pid_namespace init_pid_ns;
  26. #ifdef CONFIG_PID_NS
  27. static inline struct pid_namespace *get_pid_ns(struct pid_namespace *ns)
  28. {
  29. if (ns != &init_pid_ns)
  30. kref_get(&ns->kref);
  31. return ns;
  32. }
  33. extern struct pid_namespace *copy_pid_ns(unsigned long flags, struct pid_namespace *ns);
  34. extern void free_pid_ns(struct kref *kref);
  35. extern void zap_pid_ns_processes(struct pid_namespace *pid_ns);
  36. static inline void put_pid_ns(struct pid_namespace *ns)
  37. {
  38. if (ns != &init_pid_ns)
  39. kref_put(&ns->kref, free_pid_ns);
  40. }
  41. #else /* !CONFIG_PID_NS */
  42. #include <linux/err.h>
  43. static inline struct pid_namespace *get_pid_ns(struct pid_namespace *ns)
  44. {
  45. return ns;
  46. }
  47. static inline struct pid_namespace *
  48. copy_pid_ns(unsigned long flags, struct pid_namespace *ns)
  49. {
  50. if (flags & CLONE_NEWPID)
  51. ns = ERR_PTR(-EINVAL);
  52. return ns;
  53. }
  54. static inline void put_pid_ns(struct pid_namespace *ns)
  55. {
  56. }
  57. static inline void zap_pid_ns_processes(struct pid_namespace *ns)
  58. {
  59. BUG();
  60. }
  61. #endif /* CONFIG_PID_NS */
  62. static inline struct pid_namespace *task_active_pid_ns(struct task_struct *tsk)
  63. {
  64. return tsk->nsproxy->pid_ns;
  65. }
  66. static inline struct task_struct *task_child_reaper(struct task_struct *tsk)
  67. {
  68. BUG_ON(tsk != current);
  69. return tsk->nsproxy->pid_ns->child_reaper;
  70. }
  71. #endif /* _LINUX_PID_NS_H */