XenevaOS
Loading...
Searching...
No Matches
types.h
Go to the documentation of this file.
1#ifndef __LINUX_TYPES_H__
2#define __LINUX_TYPES_H__
3
4/*
5 * DCL <linux/types.h> -- the fixed-width typedefs a ported file starts with.
6 *
7 * Everything mainline puts here already exists in <linux/kernel.h> (u8 through
8 * u64, s8 through s64, __u8 through __u64, phys_addr_t, gfp_t), so this header
9 * is a re-export: it exists because a ported file opens with
10 * `#include <linux/types.h>` and the include has to resolve.
11 *
12 * It also pulls in <stdbool.h> for `bool`/`true`/`false`, which the tty_buffer
13 * struct fields (`bool flags`) and every `if (likely(...))` in the set need.
14 * Xeneva's stdbool.h defines `bool` as _Bool (stdbool.h:35).
15 *
16 * Deliberately does *not* re-typedef anything: two typedefs of the same name
17 * are only legal in C11 when they are identical, and "identical" here would
18 * mean byte-for-byte matching an expression from a header we do not own.
19 */
20
21/*
22 * __kernel_long_t / __kernel_ulong_t -- <uapi/linux/sysinfo.h>'s struct
23 * sysinfo hangs every field on them, and that header arrives through
24 * uapi/linux/kernel.h:5, which linux/math.h:7 includes, which kernel.h:90
25 * includes.
26 *
27 * They sit *above* the include of kernel.h, and that placement is the whole
28 * point: when the chain above runs, sysinfo.h includes <linux/types.h> from
29 * inside kernel.h -- by then this header's guard is already set, so the
30 * re-entry is skipped and anything defined *below* the kernel.h include does
31 * not exist yet. The first build with the kernel.h -> math.h edge failed at
32 * sysinfo.h:9 with "unknown type name '__kernel_long_t'" for exactly that
33 * reason. These two are self-contained -- no size_t, nothing from kernel.h --
34 * so they can go first; the rest of the file cannot.
35 *
36 * The fixed-width spelling rather than mainline's `long`/`unsigned long` is
37 * about the target: aarch64-unknown-windows is LLP64, so `long` is 32 bits
38 * here where Linux/arm64's is 64 (verified: sizeof(long) == 4). Following
39 * mainline's spelling would silently shrink struct sysinfo from 104 bytes to
40 * 64 and turn the `_f[20 - 2*sizeof(__kernel_ulong_t) - sizeof(__u32)]`
41 * trailer into 8 bytes of padding where Linux has none. Nothing in DCL
42 * implements sysinfo() or ships the struct over an ABI boundary today, but a
43 * uapi struct whose size nobody has checked is exactly the thing that gets
44 * found out by the first syscall that does.
45 */
46typedef long long __kernel_long_t;
47typedef unsigned long long __kernel_ulong_t;
48
49#include <linux/kernel.h>
50#include <stdbool.h>
51
52/*
53 * pid_t -- mainline has it at include/linux/types.h:26 over __kernel_pid_t,
54 * which is `int` on this ABI. DCL's <uapi/linux/posix_types.h> does not
55 * carry __kernel_pid_t (nothing in userspace names it), so the typedef is
56 * written directly. First consumer: drm_device.h:46, the wedge task info
57 * the panic path fills in.
58 */
59typedef int pid_t;
60
61/*
62 * __kernel_size_t -- the kernel-side spelling of size_t, which uapi/drm/drm.h
63 * hangs three struct drm_version length fields on (drm.h:127/129/139). It is
64 * <asm/posix_types.h>'s job on mainline; DCL has no posix_types, and this
65 * header is what drm.h's __KERNEL__ branch includes, so the typedef lives
66 * here. size_t rather than `unsigned long`: aarch64-unknown-windows is LLP64
67 * (long is 32 bits), and the userspace half of drm.h -- which takes the BSD
68 * arm and writes `typedef size_t __kernel_size_t;` itself -- would otherwise
69 * disagree about the width of name_len/date_len/desc_len across the ioctl.
70 */
71typedef size_t __kernel_size_t;
72
73/*
74 * uint -- mainline keeps it in <linux/types.h> too (:93, in the sysv block
75 * beside ushort/ulong), and drm/drm_color_mgmt.h:72 and :74 name it in
76 * drm_crtc_enable_color_mgmt()'s prototype. C has no `uint`; without the
77 * typedef the declaration fails at the parameter name with "unknown type
78 * name 'uint'", three lines before the function it belongs to.
79 */
80typedef unsigned int uint;
81
82/*
83 * The four sort() callback types. mainline keeps them in <linux/types.h>
84 * (:261-:265) rather than in <linux/sort.h>, which only ever mentions them in
85 * prototypes -- so a TU that reads sort.h first needs them here. Vendored
86 * lib/sort.c names all four, and without them the header fails at every one
87 * of its four declarations with "unknown type name".
88 */
89typedef void (*swap_r_func_t)(void *a, void *b, int size, const void *priv);
90typedef void (*swap_func_t)(void *a, void *b, int size);
91typedef int (*cmp_r_func_t)(const void *a, const void *b, const void *priv);
92typedef int (*cmp_func_t)(const void *a, const void *b);
93
94/*
95 * DCL delta -- byte order.
96 *
97 * mainline reaches le16_to_cpu() and friends through its byteorder layer
98 * (<linux/byteorder/generic.h> via <asm/byteorder.h>), which comes in with the
99 * rest of the driver's own include set. DCL has no byteorder layer -- nothing
100 * needed one before this port -- so the twelve conversions are defined here,
101 * which is the first header <linux/virtio_byteorder.h> includes (line 6).
102 *
103 * __LITTLE_ENDIAN is the one that is not merely convenience: clang does *not*
104 * predefined it for aarch64-unknown-windows (only __BYTE_ORDER__ comes from
105 * the compiler, verified), and virtio_byteorder.h:9 tests __LITTLE_ENDIAN to
106 * decide whether the legacy virtio device layout is little-endian. Taken at
107 * face value that reads "big-endian", which would run every virtio16/virtio32
108 * field through bswap on a little-endian target and hand the device garbage.
109 * The 1234 matches mainline's.
110 *
111 * aarch64 is little-endian, so the le_* forms are identity and the be_* forms
112 * bswap -- which is exactly mainline's little_endian.h, written out rather
113 * than fetched, because pulling in its arch indirection would reintroduce the
114 * <asm/byteorder.h> hop this tree has no file for.
115 *
116 * __BIG_ENDIAN is deliberately absent, and that is not a sibling omission of
117 * the paragraph above. mainline defines exactly one of the pair -- <linux/
118 * kconfig.h> chooses from CONFIG_CPU_BIG_ENDIAN -- and four vendored files
119 * read *presence* as the endianness test: drm_fourcc.h:42 (the DRM_FORMAT_HOST_*
120 * aliases), drm_fourcc.c:221, drm_framebuffer.c:357 and seq_buf.c:278. Both
121 * macros published means all four take the big-endian arm here, so every
122 * scanout format gets stamped with DRM_FORMAT_BIG_ENDIAN and the seq_buf hex
123 * dumps come out byte-reversed -- precisely the failure the Stage 3
124 * writeback pixel-compare is there to catch, but a month earlier.
125 */
126#define __LITTLE_ENDIAN 1234
127#define __PDP_ENDIAN 3412
128
129#define le16_to_cpu(x) ((__u16)(x))
130#define cpu_to_le16(x) ((__le16)(__u16)(x))
131#define le32_to_cpu(x) ((__u32)(x))
132#define cpu_to_le32(x) ((__le32)(__u32)(x))
133#define le64_to_cpu(x) ((__u64)(x))
134#define cpu_to_le64(x) ((__le64)(__u64)(x))
135
136#define be16_to_cpu(x) ((__u16)__builtin_bswap16((unsigned short)(x)))
137#define cpu_to_be16(x) ((__be16)__builtin_bswap16((unsigned short)(x)))
138#define be32_to_cpu(x) ((__u32)__builtin_bswap32((unsigned int)(x)))
139#define cpu_to_be32(x) ((__be32)__builtin_bswap32((unsigned int)(x)))
140#define be64_to_cpu(x) ((__u64)__builtin_bswap64((unsigned long long)(x)))
141#define cpu_to_be64(x) ((__be64)__builtin_bswap64((unsigned long long)(x)))
142
143#endif /* __LINUX_TYPES_H__ */
size_t __kernel_size_t
Definition types.h:71
int pid_t
Definition types.h:59
void(* swap_func_t)(void *a, void *b, int size)
Definition types.h:90
long long __kernel_long_t
Definition types.h:46
int(* cmp_r_func_t)(const void *a, const void *b, const void *priv)
Definition types.h:91
int(* cmp_func_t)(const void *a, const void *b)
Definition types.h:92
unsigned int uint
Definition types.h:80
void(* swap_r_func_t)(void *a, void *b, int size, const void *priv)
Definition types.h:89
unsigned long long __kernel_ulong_t
Definition types.h:47
size_t a
Definition main.cpp:156
size_t b
Definition main.cpp:156
size_t size
Definition drm_bridge.h:1299