pid_namespace.h 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  1. /* SPDX-License-Identifier: GPL-2.0 */
  2. #ifndef _LINUX_PID_NS_H
  3. #define _LINUX_PID_NS_H
  4. #include <linux/sched.h>
  5. #include <linux/bug.h>
  6. #include <linux/mm.h>
  7. #include <linux/workqueue.h>
  8. #include <linux/threads.h>
  9. #include <linux/nsproxy.h>
  10. #include <linux/kref.h>
  11. #include <linux/ns_common.h>
  12. #include <linux/idr.h>
  13. /* MAX_PID_NS_LEVEL is needed for limiting size of 'struct pid' */
  14. #define MAX_PID_NS_LEVEL 32
  15. struct fs_pin;
  16. struct pid_namespace {
  17. struct kref kref;
  18. struct idr idr;
  19. struct rcu_head rcu;
  20. unsigned int pid_allocated;
  21. struct task_struct *child_reaper;
  22. struct kmem_cache *pid_cachep;
  23. unsigned int level;
  24. struct pid_namespace *parent;
  25. #ifdef CONFIG_BSD_PROCESS_ACCT
  26. struct fs_pin *bacct;
  27. #endif
  28. struct user_namespace *user_ns;
  29. struct ucounts *ucounts;
  30. int reboot; /* group exit code if this pidns was rebooted */
  31. struct ns_common ns;
  32. } __randomize_layout;
  33. extern struct pid_namespace init_pid_ns;
  34. #define PIDNS_ADDING (1U << 31)
  35. #ifdef CONFIG_PID_NS
  36. static inline struct pid_namespace *get_pid_ns(struct pid_namespace *ns)
  37. {
  38. if (ns != &init_pid_ns)
  39. kref_get(&ns->kref);
  40. return ns;
  41. }
  42. extern struct pid_namespace *copy_pid_ns(unsigned long flags,
  43. struct user_namespace *user_ns, struct pid_namespace *ns);
  44. extern void zap_pid_ns_processes(struct pid_namespace *pid_ns);
  45. extern int reboot_pid_ns(struct pid_namespace *pid_ns, int cmd);
  46. extern void put_pid_ns(struct pid_namespace *ns);
  47. #else /* !CONFIG_PID_NS */
  48. #include <linux/err.h>
  49. static inline struct pid_namespace *get_pid_ns(struct pid_namespace *ns)
  50. {
  51. return ns;
  52. }
  53. static inline struct pid_namespace *copy_pid_ns(unsigned long flags,
  54. struct user_namespace *user_ns, struct pid_namespace *ns)
  55. {
  56. if (flags & CLONE_NEWPID)
  57. ns = ERR_PTR(-EINVAL);
  58. return ns;
  59. }
  60. static inline void put_pid_ns(struct pid_namespace *ns)
  61. {
  62. }
  63. static inline void zap_pid_ns_processes(struct pid_namespace *ns)
  64. {
  65. BUG();
  66. }
  67. static inline int reboot_pid_ns(struct pid_namespace *pid_ns, int cmd)
  68. {
  69. return 0;
  70. }
  71. #endif /* CONFIG_PID_NS */
  72. extern struct pid_namespace *task_active_pid_ns(struct task_struct *tsk);
  73. void pidhash_init(void);
  74. void pid_idr_init(void);
  75. #endif /* _LINUX_PID_NS_H */