user.h 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. /* SPDX-License-Identifier: GPL-2.0 */
  2. #ifndef _LINUX_SCHED_USER_H
  3. #define _LINUX_SCHED_USER_H
  4. #include <linux/uidgid.h>
  5. #include <linux/atomic.h>
  6. #include <linux/percpu_counter.h>
  7. #include <linux/refcount.h>
  8. #include <linux/ratelimit.h>
  9. #include <linux/android_kabi.h>
  10. /*
  11. * Some day this will be a full-fledged user tracking system..
  12. */
  13. struct user_struct {
  14. refcount_t __count; /* reference count */
  15. #ifdef CONFIG_EPOLL
  16. struct percpu_counter epoll_watches; /* The number of file descriptors currently watched */
  17. #endif
  18. unsigned long unix_inflight; /* How many files in flight in unix sockets */
  19. atomic_long_t pipe_bufs; /* how many pages are allocated in pipe buffers */
  20. /* Hash table maintenance information */
  21. struct hlist_node uidhash_node;
  22. kuid_t uid;
  23. #if defined(CONFIG_PERF_EVENTS) || defined(CONFIG_BPF_SYSCALL) || \
  24. defined(CONFIG_NET) || defined(CONFIG_IO_URING) || \
  25. defined(CONFIG_VFIO_PCI_ZDEV_KVM)
  26. atomic_long_t locked_vm;
  27. #endif
  28. #ifdef CONFIG_WATCH_QUEUE
  29. atomic_t nr_watches; /* The number of watches this user currently has */
  30. #endif
  31. /* Miscellaneous per-user rate limit */
  32. struct ratelimit_state ratelimit;
  33. ANDROID_OEM_DATA_ARRAY(1, 2);
  34. ANDROID_KABI_RESERVE(1);
  35. ANDROID_KABI_RESERVE(2);
  36. };
  37. extern int uids_sysfs_init(void);
  38. extern struct user_struct *find_user(kuid_t);
  39. extern struct user_struct root_user;
  40. #define INIT_USER (&root_user)
  41. /* per-UID process charging. */
  42. extern struct user_struct * alloc_uid(kuid_t);
  43. static inline struct user_struct *get_uid(struct user_struct *u)
  44. {
  45. refcount_inc(&u->__count);
  46. return u;
  47. }
  48. extern void free_uid(struct user_struct *);
  49. #endif /* _LINUX_SCHED_USER_H */