History

uapi/headers: Provide types_32_64.h

Provide helper macros for fields which represent pointers in kernel-userspace ABI. This facilitates handling of 32-bit user-space by 64-bit kernels by defining those fields as 32-bit 0-padding and 32-bit integer on 32-bit architectures, which allows the kernel to treat those as 64-bit integers. The order of padding and 32-bit integer depends on the endianness.

Mathieu Desnoyers committed 8 years ago

Commit b575e831 parent 716a6851 file · +50 −0Browse files

Showing the changes to include/uapi/linux (1 of 1 file). Show all

Unified · Split

include/uapi/linux/types_32_64.h+50−0
@@ -0,0 +1,50 @@
1+/* SPDX-License-Identifier: GPL-2.0+ WITH Linux-syscall-note */
2+#ifndef _UAPI_LINUX_TYPES_32_64_H
3+#define _UAPI_LINUX_TYPES_32_64_H
4+
5+/*
6+ * linux/types_32_64.h
7+ *
8+ * Integer type declaration for pointers across 32-bit and 64-bit systems.
9+ *
10+ * Copyright (c) 2015-2018 Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
11+ */
12+
13+#ifdef __KERNEL__
14+# include <linux/types.h>
15+#else
16+# include <stdint.h>
17+#endif
18+
19+#include <asm/byteorder.h>
20+
21+#ifdef __BYTE_ORDER
22+# if (__BYTE_ORDER == __BIG_ENDIAN)
23+# define LINUX_BYTE_ORDER_BIG_ENDIAN
24+# else
25+# define LINUX_BYTE_ORDER_LITTLE_ENDIAN
26+# endif
27+#else
28+# ifdef __BIG_ENDIAN
29+# define LINUX_BYTE_ORDER_BIG_ENDIAN
30+# else
31+# define LINUX_BYTE_ORDER_LITTLE_ENDIAN
32+# endif
33+#endif
34+
35+#ifdef __LP64__
36+# define LINUX_FIELD_u32_u64(field) __u64 field
37+# define LINUX_FIELD_u32_u64_INIT_ONSTACK(field, v) field = (intptr_t)v
38+#else
39+# ifdef LINUX_BYTE_ORDER_BIG_ENDIAN
40+# define LINUX_FIELD_u32_u64(field) __u32 field ## _padding, field
41+# define LINUX_FIELD_u32_u64_INIT_ONSTACK(field, v) \
42+ field ## _padding = 0, field = (intptr_t)v
43+# else
44+# define LINUX_FIELD_u32_u64(field) __u32 field, field ## _padding
45+# define LINUX_FIELD_u32_u64_INIT_ONSTACK(field, v) \
46+ field = (intptr_t)v, field ## _padding = 0
47+# endif
48+#endif
49+
50+#endif /* _UAPI_LINUX_TYPES_32_64_H */