xref: /OK3568_Linux_fs/kernel/include/linux/sched/user.h (revision 4882a59341e53eb6f0b4789bf948001014eff981)
1 /* SPDX-License-Identifier: GPL-2.0 */
2 #ifndef _LINUX_SCHED_USER_H
3 #define _LINUX_SCHED_USER_H
4 
5 #include <linux/uidgid.h>
6 #include <linux/atomic.h>
7 #include <linux/refcount.h>
8 #include <linux/ratelimit.h>
9 #include <linux/android_kabi.h>
10 
11 /*
12  * Some day this will be a full-fledged user tracking system..
13  */
14 struct user_struct {
15 	refcount_t __count;	/* reference count */
16 	atomic_t processes;	/* How many processes does this user have? */
17 	atomic_t sigpending;	/* How many pending signals does this user have? */
18 #ifdef CONFIG_FANOTIFY
19 	atomic_t fanotify_listeners;
20 #endif
21 #ifdef CONFIG_EPOLL
22 	atomic_long_t epoll_watches; /* The number of file descriptors currently watched */
23 #endif
24 #ifdef CONFIG_POSIX_MQUEUE
25 	/* protected by mq_lock	*/
26 	unsigned long mq_bytes;	/* How many bytes can be allocated to mqueue? */
27 #endif
28 	unsigned long locked_shm; /* How many pages of mlocked shm ? */
29 	unsigned long unix_inflight;	/* How many files in flight in unix sockets */
30 	atomic_long_t pipe_bufs;  /* how many pages are allocated in pipe buffers */
31 
32 	/* Hash table maintenance information */
33 	struct hlist_node uidhash_node;
34 	kuid_t uid;
35 
36 #if defined(CONFIG_PERF_EVENTS) || defined(CONFIG_BPF_SYSCALL) || \
37     defined(CONFIG_NET) || defined(CONFIG_IO_URING)
38 	atomic_long_t locked_vm;
39 #endif
40 #ifdef CONFIG_WATCH_QUEUE
41 	atomic_t nr_watches;	/* The number of watches this user currently has */
42 #endif
43 
44 	/* Miscellaneous per-user rate limit */
45 	struct ratelimit_state ratelimit;
46 
47 	ANDROID_KABI_RESERVE(1);
48 	ANDROID_KABI_RESERVE(2);
49 	ANDROID_OEM_DATA_ARRAY(1, 2);
50 };
51 
52 extern int uids_sysfs_init(void);
53 
54 extern struct user_struct *find_user(kuid_t);
55 
56 extern struct user_struct root_user;
57 #define INIT_USER (&root_user)
58 
59 
60 /* per-UID process charging. */
61 extern struct user_struct * alloc_uid(kuid_t);
get_uid(struct user_struct * u)62 static inline struct user_struct *get_uid(struct user_struct *u)
63 {
64 	refcount_inc(&u->__count);
65 	return u;
66 }
67 extern void free_uid(struct user_struct *);
68 
69 #endif /* _LINUX_SCHED_USER_H */
70