xref: /openbmc/linux/arch/arm64/include/asm/compat.h (revision 3ce0f237)
1 /* SPDX-License-Identifier: GPL-2.0-only */
2 /*
3  * Copyright (C) 2012 ARM Ltd.
4  */
5 #ifndef __ASM_COMPAT_H
6 #define __ASM_COMPAT_H
7 
8 #define compat_mode_t compat_mode_t
9 typedef u16		compat_mode_t;
10 
11 #include <asm-generic/compat.h>
12 
13 #ifdef CONFIG_COMPAT
14 
15 /*
16  * Architecture specific compatibility types
17  */
18 #include <linux/types.h>
19 #include <linux/sched.h>
20 #include <linux/sched/task_stack.h>
21 
22 #define COMPAT_USER_HZ		100
23 #ifdef __AARCH64EB__
24 #define COMPAT_UTS_MACHINE	"armv8b\0\0"
25 #else
26 #define COMPAT_UTS_MACHINE	"armv8l\0\0"
27 #endif
28 
29 typedef u16		__compat_uid_t;
30 typedef u16		__compat_gid_t;
31 typedef u16		__compat_uid16_t;
32 typedef u16		__compat_gid16_t;
33 typedef u32		compat_dev_t;
34 typedef s32		compat_nlink_t;
35 typedef u16		compat_ipc_pid_t;
36 typedef __kernel_fsid_t	compat_fsid_t;
37 
38 struct compat_stat {
39 #ifdef __AARCH64EB__
40 	short		st_dev;
41 	short		__pad1;
42 #else
43 	compat_dev_t	st_dev;
44 #endif
45 	compat_ino_t	st_ino;
46 	compat_mode_t	st_mode;
47 	compat_ushort_t	st_nlink;
48 	__compat_uid16_t	st_uid;
49 	__compat_gid16_t	st_gid;
50 #ifdef __AARCH64EB__
51 	short		st_rdev;
52 	short		__pad2;
53 #else
54 	compat_dev_t	st_rdev;
55 #endif
56 	compat_off_t	st_size;
57 	compat_off_t	st_blksize;
58 	compat_off_t	st_blocks;
59 	old_time32_t	st_atime;
60 	compat_ulong_t	st_atime_nsec;
61 	old_time32_t	st_mtime;
62 	compat_ulong_t	st_mtime_nsec;
63 	old_time32_t	st_ctime;
64 	compat_ulong_t	st_ctime_nsec;
65 	compat_ulong_t	__unused4[2];
66 };
67 
68 struct compat_statfs {
69 	int		f_type;
70 	int		f_bsize;
71 	int		f_blocks;
72 	int		f_bfree;
73 	int		f_bavail;
74 	int		f_files;
75 	int		f_ffree;
76 	compat_fsid_t	f_fsid;
77 	int		f_namelen;	/* SunOS ignores this field. */
78 	int		f_frsize;
79 	int		f_flags;
80 	int		f_spare[4];
81 };
82 
83 #define COMPAT_RLIM_INFINITY		0xffffffff
84 
85 #define COMPAT_OFF_T_MAX	0x7fffffff
86 
87 #define compat_user_stack_pointer() (user_stack_pointer(task_pt_regs(current)))
88 #define COMPAT_MINSIGSTKSZ	2048
89 
90 struct compat_ipc64_perm {
91 	compat_key_t key;
92 	__compat_uid32_t uid;
93 	__compat_gid32_t gid;
94 	__compat_uid32_t cuid;
95 	__compat_gid32_t cgid;
96 	unsigned short mode;
97 	unsigned short __pad1;
98 	unsigned short seq;
99 	unsigned short __pad2;
100 	compat_ulong_t unused1;
101 	compat_ulong_t unused2;
102 };
103 
104 struct compat_semid64_ds {
105 	struct compat_ipc64_perm sem_perm;
106 	compat_ulong_t sem_otime;
107 	compat_ulong_t sem_otime_high;
108 	compat_ulong_t sem_ctime;
109 	compat_ulong_t sem_ctime_high;
110 	compat_ulong_t sem_nsems;
111 	compat_ulong_t __unused3;
112 	compat_ulong_t __unused4;
113 };
114 
115 struct compat_msqid64_ds {
116 	struct compat_ipc64_perm msg_perm;
117 	compat_ulong_t msg_stime;
118 	compat_ulong_t msg_stime_high;
119 	compat_ulong_t msg_rtime;
120 	compat_ulong_t msg_rtime_high;
121 	compat_ulong_t msg_ctime;
122 	compat_ulong_t msg_ctime_high;
123 	compat_ulong_t msg_cbytes;
124 	compat_ulong_t msg_qnum;
125 	compat_ulong_t msg_qbytes;
126 	compat_pid_t   msg_lspid;
127 	compat_pid_t   msg_lrpid;
128 	compat_ulong_t __unused4;
129 	compat_ulong_t __unused5;
130 };
131 
132 struct compat_shmid64_ds {
133 	struct compat_ipc64_perm shm_perm;
134 	compat_size_t  shm_segsz;
135 	compat_ulong_t shm_atime;
136 	compat_ulong_t shm_atime_high;
137 	compat_ulong_t shm_dtime;
138 	compat_ulong_t shm_dtime_high;
139 	compat_ulong_t shm_ctime;
140 	compat_ulong_t shm_ctime_high;
141 	compat_pid_t   shm_cpid;
142 	compat_pid_t   shm_lpid;
143 	compat_ulong_t shm_nattch;
144 	compat_ulong_t __unused4;
145 	compat_ulong_t __unused5;
146 };
147 
148 static inline int is_compat_task(void)
149 {
150 	return test_thread_flag(TIF_32BIT);
151 }
152 
153 static inline int is_compat_thread(struct thread_info *thread)
154 {
155 	return test_ti_thread_flag(thread, TIF_32BIT);
156 }
157 
158 #else /* !CONFIG_COMPAT */
159 
160 static inline int is_compat_thread(struct thread_info *thread)
161 {
162 	return 0;
163 }
164 
165 #endif /* CONFIG_COMPAT */
166 #endif /* __ASM_COMPAT_H */
167