pid_namespace.h 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  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/pid.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 pid_namespace {
  15. struct kref kref;
  16. struct pidmap pidmap[PIDMAP_ENTRIES];
  17. int last_pid;
  18. struct task_struct *child_reaper;
  19. struct kmem_cache *pid_cachep;
  20. int level;
  21. struct pid_namespace *parent;
  22. };
  23. extern struct pid_namespace init_pid_ns;
  24. static inline struct pid_namespace *get_pid_ns(struct pid_namespace *ns)
  25. {
  26. kref_get(&ns->kref);
  27. return ns;
  28. }
  29. extern struct pid_namespace *copy_pid_ns(unsigned long flags, struct pid_namespace *ns);
  30. extern void free_pid_ns(struct kref *kref);
  31. static inline void put_pid_ns(struct pid_namespace *ns)
  32. {
  33. kref_put(&ns->kref, free_pid_ns);
  34. }
  35. static inline struct pid_namespace *task_active_pid_ns(struct task_struct *tsk)
  36. {
  37. return tsk->nsproxy->pid_ns;
  38. }
  39. static inline struct task_struct *task_child_reaper(struct task_struct *tsk)
  40. {
  41. return init_pid_ns.child_reaper;
  42. }
  43. #endif /* _LINUX_PID_NS_H */