xref: /linux/include/linux/types.h (revision 7d4e49a77d9930c69751b9192448fda6ff9100f1)
1 /* SPDX-License-Identifier: GPL-2.0 */
2 #ifndef _LINUX_TYPES_H
3 #define _LINUX_TYPES_H
4 
5 #define __EXPORTED_HEADERS__
6 #include <uapi/linux/types.h>
7 
8 #ifndef __ASSEMBLY__
9 
10 #define DECLARE_BITMAP(name,bits) \
11 	unsigned long name[BITS_TO_LONGS(bits)]
12 
13 #ifdef __SIZEOF_INT128__
14 typedef __s128 s128;
15 typedef __u128 u128;
16 #endif
17 
18 typedef u32 __kernel_dev_t;
19 
20 typedef __kernel_fd_set		fd_set;
21 typedef __kernel_dev_t		dev_t;
22 typedef __kernel_ulong_t	ino_t;
23 typedef __kernel_mode_t		mode_t;
24 typedef unsigned short		umode_t;
25 typedef u32			nlink_t;
26 typedef __kernel_off_t		off_t;
27 typedef __kernel_pid_t		pid_t;
28 typedef __kernel_daddr_t	daddr_t;
29 typedef __kernel_key_t		key_t;
30 typedef __kernel_suseconds_t	suseconds_t;
31 typedef __kernel_timer_t	timer_t;
32 typedef __kernel_clockid_t	clockid_t;
33 typedef __kernel_mqd_t		mqd_t;
34 
35 typedef _Bool			bool;
36 
37 typedef __kernel_uid32_t	uid_t;
38 typedef __kernel_gid32_t	gid_t;
39 typedef __kernel_uid16_t        uid16_t;
40 typedef __kernel_gid16_t        gid16_t;
41 
42 typedef unsigned long		uintptr_t;
43 typedef long			intptr_t;
44 
45 #ifdef CONFIG_HAVE_UID16
46 /* This is defined by arch/{arch}/include/asm/posix_types.h */
47 typedef __kernel_old_uid_t	old_uid_t;
48 typedef __kernel_old_gid_t	old_gid_t;
49 #endif /* CONFIG_UID16 */
50 
51 #if defined(__GNUC__)
52 typedef __kernel_loff_t		loff_t;
53 #endif
54 
55 /*
56  * The following typedefs are also protected by individual ifdefs for
57  * historical reasons:
58  */
59 #ifndef _SIZE_T
60 #define _SIZE_T
61 typedef __kernel_size_t		size_t;
62 #endif
63 
64 #ifndef _SSIZE_T
65 #define _SSIZE_T
66 typedef __kernel_ssize_t	ssize_t;
67 #endif
68 
69 #ifndef _PTRDIFF_T
70 #define _PTRDIFF_T
71 typedef __kernel_ptrdiff_t	ptrdiff_t;
72 #endif
73 
74 #ifndef _CLOCK_T
75 #define _CLOCK_T
76 typedef __kernel_clock_t	clock_t;
77 #endif
78 
79 #ifndef _CADDR_T
80 #define _CADDR_T
81 typedef __kernel_caddr_t	caddr_t;
82 #endif
83 
84 /* bsd */
85 typedef unsigned char		u_char;
86 typedef unsigned short		u_short;
87 typedef unsigned int		u_int;
88 typedef unsigned long		u_long;
89 
90 /* sysv */
91 typedef unsigned char		unchar;
92 typedef unsigned short		ushort;
93 typedef unsigned int		uint;
94 typedef unsigned long		ulong;
95 typedef unsigned long long	ullong;
96 
97 #ifndef __BIT_TYPES_DEFINED__
98 #define __BIT_TYPES_DEFINED__
99 
100 typedef u8			u_int8_t;
101 typedef s8			int8_t;
102 typedef u16			u_int16_t;
103 typedef s16			int16_t;
104 typedef u32			u_int32_t;
105 typedef s32			int32_t;
106 
107 #endif /* !(__BIT_TYPES_DEFINED__) */
108 
109 typedef u8			uint8_t;
110 typedef u16			uint16_t;
111 typedef u32			uint32_t;
112 
113 #if defined(__GNUC__)
114 typedef u64			uint64_t;
115 typedef u64			u_int64_t;
116 typedef s64			int64_t;
117 #endif
118 
119 /* These are the special 64-bit data types that are 8-byte aligned */
120 #define aligned_u64		__aligned_u64
121 #define aligned_s64		__aligned_s64
122 #define aligned_be64		__aligned_be64
123 #define aligned_le64		__aligned_le64
124 
125 /* Nanosecond scalar representation for kernel time values */
126 typedef s64	ktime_t;
127 
128 /**
129  * The type used for indexing onto a disc or disc partition.
130  *
131  * Linux always considers sectors to be 512 bytes long independently
132  * of the devices real block size.
133  *
134  * blkcnt_t is the type of the inode's block count.
135  */
136 typedef u64 sector_t;
137 typedef u64 blkcnt_t;
138 
139 /* generic data direction definitions */
140 #define READ			0
141 #define WRITE			1
142 
143 /*
144  * The type of an index into the pagecache.
145  */
146 #define pgoff_t unsigned long
147 
148 /*
149  * A dma_addr_t can hold any valid DMA address, i.e., any address returned
150  * by the DMA API.
151  *
152  * If the DMA API only uses 32-bit addresses, dma_addr_t need only be 32
153  * bits wide.  Bus addresses, e.g., PCI BARs, may be wider than 32 bits,
154  * but drivers do memory-mapped I/O to ioremapped kernel virtual addresses,
155  * so they don't care about the size of the actual bus addresses.
156  */
157 #ifdef CONFIG_ARCH_DMA_ADDR_T_64BIT
158 typedef u64 dma_addr_t;
159 #else
160 typedef u32 dma_addr_t;
161 #endif
162 
163 typedef unsigned int __bitwise gfp_t;
164 typedef unsigned int __bitwise slab_flags_t;
165 typedef unsigned int __bitwise fmode_t;
166 
167 #ifdef CONFIG_PHYS_ADDR_T_64BIT
168 typedef u64 phys_addr_t;
169 #else
170 typedef u32 phys_addr_t;
171 #endif
172 
173 typedef phys_addr_t resource_size_t;
174 
175 /*
176  * This type is the placeholder for a hardware interrupt number. It has to be
177  * big enough to enclose whatever representation is used by a given platform.
178  */
179 typedef unsigned long irq_hw_number_t;
180 
181 typedef struct {
182 	int counter;
183 } atomic_t;
184 
185 #define ATOMIC_INIT(i) { (i) }
186 
187 #ifdef CONFIG_64BIT
188 typedef struct {
189 	s64 counter;
190 } atomic64_t;
191 #endif
192 
193 typedef struct {
194 	atomic_t refcnt;
195 } rcuref_t;
196 
197 #define RCUREF_INIT(i)	{ .refcnt = ATOMIC_INIT(i - 1) }
198 
199 struct list_head {
200 	struct list_head *next, *prev;
201 };
202 
203 struct hlist_head {
204 	struct hlist_node *first;
205 };
206 
207 struct hlist_node {
208 	struct hlist_node *next, **pprev;
209 };
210 
211 struct ustat {
212 	__kernel_daddr_t	f_tfree;
213 #ifdef CONFIG_ARCH_32BIT_USTAT_F_TINODE
214 	unsigned int		f_tinode;
215 #else
216 	unsigned long		f_tinode;
217 #endif
218 	char			f_fname[6];
219 	char			f_fpack[6];
220 };
221 
222 /**
223  * struct callback_head - callback structure for use with RCU and task_work
224  * @next: next update requests in a list
225  * @func: actual update function to call after the grace period.
226  *
227  * The struct is aligned to size of pointer. On most architectures it happens
228  * naturally due ABI requirements, but some architectures (like CRIS) have
229  * weird ABI and we need to ask it explicitly.
230  *
231  * The alignment is required to guarantee that bit 0 of @next will be
232  * clear under normal conditions -- as long as we use call_rcu() or
233  * call_srcu() to queue the callback.
234  *
235  * This guarantee is important for few reasons:
236  *  - future call_rcu_lazy() will make use of lower bits in the pointer;
237  *  - the structure shares storage space in struct page with @compound_head,
238  *    which encode PageTail() in bit 0. The guarantee is needed to avoid
239  *    false-positive PageTail().
240  */
241 struct callback_head {
242 	struct callback_head *next;
243 	void (*func)(struct callback_head *head);
244 } __attribute__((aligned(sizeof(void *))));
245 #define rcu_head callback_head
246 
247 typedef void (*rcu_callback_t)(struct rcu_head *head);
248 typedef void (*call_rcu_func_t)(struct rcu_head *head, rcu_callback_t func);
249 
250 typedef void (*swap_r_func_t)(void *a, void *b, int size, const void *priv);
251 typedef void (*swap_func_t)(void *a, void *b, int size);
252 
253 typedef int (*cmp_r_func_t)(const void *a, const void *b, const void *priv);
254 typedef int (*cmp_func_t)(const void *a, const void *b);
255 
256 /*
257  * rcuwait provides a way of blocking and waking up a single
258  * task in an rcu-safe manner.
259  *
260  * The only time @task is non-nil is when a user is blocked (or
261  * checking if it needs to) on a condition, and reset as soon as we
262  * know that the condition has succeeded and are awoken.
263  */
264 struct rcuwait {
265 	struct task_struct __rcu *task;
266 };
267 
268 #endif /*  __ASSEMBLY__ */
269 #endif /* _LINUX_TYPES_H */
270