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. #include <linux/err.h>
  7. #define UIDHASH_BITS (CONFIG_BASE_SMALL ? 3 : 8)
  8. #define UIDHASH_SZ (1 << UIDHASH_BITS)
  9. struct user_namespace {
  10. struct kref kref;
  11. struct hlist_head uidhash_table[UIDHASH_SZ];
  12. struct user_struct *creator;
  13. struct work_struct destroyer;
  14. };
  15. extern struct user_namespace init_user_ns;
  16. #ifdef CONFIG_USER_NS
  17. static inline struct user_namespace *get_user_ns(struct user_namespace *ns)
  18. {
  19. if (ns)
  20. kref_get(&ns->kref);
  21. return ns;
  22. }
  23. extern int create_user_ns(struct cred *new);
  24. extern void free_user_ns(struct kref *kref);
  25. static inline void put_user_ns(struct user_namespace *ns)
  26. {
  27. if (ns)
  28. kref_put(&ns->kref, free_user_ns);
  29. }
  30. #else
  31. static inline struct user_namespace *get_user_ns(struct user_namespace *ns)
  32. {
  33. return &init_user_ns;
  34. }
  35. static inline int create_user_ns(struct cred *new)
  36. {
  37. return -EINVAL;
  38. }
  39. static inline void put_user_ns(struct user_namespace *ns)
  40. {
  41. }
  42. #endif
  43. #endif /* _LINUX_USER_H */