user.h 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  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/refcount.h>
  7. #include <linux/ratelimit.h>
  8. struct key;
  9. /*
  10. * Some day this will be a full-fledged user tracking system..
  11. */
  12. struct user_struct {
  13. refcount_t __count; /* reference count */
  14. atomic_t processes; /* How many processes does this user have? */
  15. atomic_t sigpending; /* How many pending signals does this user have? */
  16. #ifdef CONFIG_FANOTIFY
  17. atomic_t fanotify_listeners;
  18. #endif
  19. #ifdef CONFIG_EPOLL
  20. atomic_long_t epoll_watches; /* The number of file descriptors currently watched */
  21. #endif
  22. #ifdef CONFIG_POSIX_MQUEUE
  23. /* protected by mq_lock */
  24. unsigned long mq_bytes; /* How many bytes can be allocated to mqueue? */
  25. #endif
  26. unsigned long locked_shm; /* How many pages of mlocked shm ? */
  27. unsigned long unix_inflight; /* How many files in flight in unix sockets */
  28. atomic_long_t pipe_bufs; /* how many pages are allocated in pipe buffers */
  29. #ifdef CONFIG_KEYS
  30. struct key *uid_keyring; /* UID specific keyring */
  31. struct key *session_keyring; /* UID's default session keyring */
  32. #endif
  33. /* Hash table maintenance information */
  34. struct hlist_node uidhash_node;
  35. kuid_t uid;
  36. #if defined(CONFIG_PERF_EVENTS) || defined(CONFIG_BPF_SYSCALL) || \
  37. defined(CONFIG_NET)
  38. atomic_long_t locked_vm;
  39. #endif
  40. /* Miscellaneous per-user rate limit */
  41. struct ratelimit_state ratelimit;
  42. };
  43. extern int uids_sysfs_init(void);
  44. extern struct user_struct *find_user(kuid_t);
  45. extern struct user_struct root_user;
  46. #define INIT_USER (&root_user)
  47. /* per-UID process charging. */
  48. extern struct user_struct * alloc_uid(kuid_t);
  49. static inline struct user_struct *get_uid(struct user_struct *u)
  50. {
  51. refcount_inc(&u->__count);
  52. return u;
  53. }
  54. extern void free_uid(struct user_struct *);
  55. #endif /* _LINUX_SCHED_USER_H */