user_namespace.h 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. #ifndef _LINUX_USER_NAMESPACE_H
  2. #define _LINUX_USER_NAMESPACE_H
  3. #include <linux/kref.h>
  4. #include <linux/nsproxy.h>
  5. #include <linux/sched.h>
  6. #define UIDHASH_BITS (CONFIG_BASE_SMALL ? 3 : 8)
  7. #define UIDHASH_SZ (1 << UIDHASH_BITS)
  8. struct user_namespace {
  9. struct kref kref;
  10. struct list_head uidhash_table[UIDHASH_SZ];
  11. struct user_struct *root_user;
  12. };
  13. extern struct user_namespace init_user_ns;
  14. #ifdef CONFIG_USER_NS
  15. static inline struct user_namespace *get_user_ns(struct user_namespace *ns)
  16. {
  17. if (ns)
  18. kref_get(&ns->kref);
  19. return ns;
  20. }
  21. extern struct user_namespace *copy_user_ns(int flags,
  22. struct user_namespace *old_ns);
  23. extern void free_user_ns(struct kref *kref);
  24. static inline void put_user_ns(struct user_namespace *ns)
  25. {
  26. if (ns)
  27. kref_put(&ns->kref, free_user_ns);
  28. }
  29. #else
  30. static inline struct user_namespace *get_user_ns(struct user_namespace *ns)
  31. {
  32. return &init_user_ns;
  33. }
  34. static inline struct user_namespace *copy_user_ns(int flags,
  35. struct user_namespace *old_ns)
  36. {
  37. return NULL;
  38. }
  39. static inline void put_user_ns(struct user_namespace *ns)
  40. {
  41. }
  42. #endif
  43. #endif /* _LINUX_USER_H */