pid_namespace.h 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  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. static inline void put_pid_ns(struct pid_namespace *ns)
  36. {
  37. if (ns != &init_pid_ns)
  38. kref_put(&ns->kref, free_pid_ns);
  39. }
  40. #else /* !CONFIG_PID_NS */
  41. #include <linux/err.h>
  42. static inline struct pid_namespace *get_pid_ns(struct pid_namespace *ns)
  43. {
  44. return ns;
  45. }
  46. static inline struct pid_namespace *
  47. copy_pid_ns(unsigned long flags, struct pid_namespace *ns)
  48. {
  49. if (flags & CLONE_NEWPID)
  50. ns = ERR_PTR(-EINVAL);
  51. return ns;
  52. }
  53. static inline void put_pid_ns(struct pid_namespace *ns)
  54. {
  55. }
  56. #endif /* CONFIG_PID_NS */
  57. static inline struct pid_namespace *task_active_pid_ns(struct task_struct *tsk)
  58. {
  59. return tsk->nsproxy->pid_ns;
  60. }
  61. static inline struct task_struct *task_child_reaper(struct task_struct *tsk)
  62. {
  63. BUG_ON(tsk != current);
  64. return tsk->nsproxy->pid_ns->child_reaper;
  65. }
  66. #endif /* _LINUX_PID_NS_H */