xref: /openbmc/linux/arch/arm64/include/asm/compat.h (revision feac8c8b)
1 /*
2  * Copyright (C) 2012 ARM Ltd.
3  *
4  * This program is free software; you can redistribute it and/or modify
5  * it under the terms of the GNU General Public License version 2 as
6  * published by the Free Software Foundation.
7  *
8  * This program is distributed in the hope that it will be useful,
9  * but WITHOUT ANY WARRANTY; without even the implied warranty of
10  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
11  * GNU General Public License for more details.
12  *
13  * You should have received a copy of the GNU General Public License
14  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
15  */
16 #ifndef __ASM_COMPAT_H
17 #define __ASM_COMPAT_H
18 #ifdef __KERNEL__
19 #ifdef CONFIG_COMPAT
20 
21 /*
22  * Architecture specific compatibility types
23  */
24 #include <linux/types.h>
25 #include <linux/sched.h>
26 #include <linux/sched/task_stack.h>
27 
28 #define COMPAT_USER_HZ		100
29 #ifdef __AARCH64EB__
30 #define COMPAT_UTS_MACHINE	"armv8b\0\0"
31 #else
32 #define COMPAT_UTS_MACHINE	"armv8l\0\0"
33 #endif
34 
35 typedef u32		compat_size_t;
36 typedef s32		compat_ssize_t;
37 typedef s32		compat_time_t;
38 typedef s32		compat_clock_t;
39 typedef s32		compat_pid_t;
40 typedef u16		__compat_uid_t;
41 typedef u16		__compat_gid_t;
42 typedef u16		__compat_uid16_t;
43 typedef u16		__compat_gid16_t;
44 typedef u32		__compat_uid32_t;
45 typedef u32		__compat_gid32_t;
46 typedef u16		compat_mode_t;
47 typedef u32		compat_ino_t;
48 typedef u32		compat_dev_t;
49 typedef s32		compat_off_t;
50 typedef s64		compat_loff_t;
51 typedef s32		compat_nlink_t;
52 typedef u16		compat_ipc_pid_t;
53 typedef s32		compat_daddr_t;
54 typedef u32		compat_caddr_t;
55 typedef __kernel_fsid_t	compat_fsid_t;
56 typedef s32		compat_key_t;
57 typedef s32		compat_timer_t;
58 
59 typedef s16		compat_short_t;
60 typedef s32		compat_int_t;
61 typedef s32		compat_long_t;
62 typedef s64		compat_s64;
63 typedef u16		compat_ushort_t;
64 typedef u32		compat_uint_t;
65 typedef u32		compat_ulong_t;
66 typedef u64		compat_u64;
67 typedef u32		compat_uptr_t;
68 
69 struct compat_timespec {
70 	compat_time_t	tv_sec;
71 	s32		tv_nsec;
72 };
73 
74 struct compat_timeval {
75 	compat_time_t	tv_sec;
76 	s32		tv_usec;
77 };
78 
79 struct compat_stat {
80 #ifdef __AARCH64EB__
81 	short		st_dev;
82 	short		__pad1;
83 #else
84 	compat_dev_t	st_dev;
85 #endif
86 	compat_ino_t	st_ino;
87 	compat_mode_t	st_mode;
88 	compat_ushort_t	st_nlink;
89 	__compat_uid16_t	st_uid;
90 	__compat_gid16_t	st_gid;
91 #ifdef __AARCH64EB__
92 	short		st_rdev;
93 	short		__pad2;
94 #else
95 	compat_dev_t	st_rdev;
96 #endif
97 	compat_off_t	st_size;
98 	compat_off_t	st_blksize;
99 	compat_off_t	st_blocks;
100 	compat_time_t	st_atime;
101 	compat_ulong_t	st_atime_nsec;
102 	compat_time_t	st_mtime;
103 	compat_ulong_t	st_mtime_nsec;
104 	compat_time_t	st_ctime;
105 	compat_ulong_t	st_ctime_nsec;
106 	compat_ulong_t	__unused4[2];
107 };
108 
109 struct compat_flock {
110 	short		l_type;
111 	short		l_whence;
112 	compat_off_t	l_start;
113 	compat_off_t	l_len;
114 	compat_pid_t	l_pid;
115 };
116 
117 #define F_GETLK64	12	/*  using 'struct flock64' */
118 #define F_SETLK64	13
119 #define F_SETLKW64	14
120 
121 struct compat_flock64 {
122 	short		l_type;
123 	short		l_whence;
124 	compat_loff_t	l_start;
125 	compat_loff_t	l_len;
126 	compat_pid_t	l_pid;
127 };
128 
129 struct compat_statfs {
130 	int		f_type;
131 	int		f_bsize;
132 	int		f_blocks;
133 	int		f_bfree;
134 	int		f_bavail;
135 	int		f_files;
136 	int		f_ffree;
137 	compat_fsid_t	f_fsid;
138 	int		f_namelen;	/* SunOS ignores this field. */
139 	int		f_frsize;
140 	int		f_flags;
141 	int		f_spare[4];
142 };
143 
144 #define COMPAT_RLIM_INFINITY		0xffffffff
145 
146 typedef u32		compat_old_sigset_t;
147 
148 #define _COMPAT_NSIG		64
149 #define _COMPAT_NSIG_BPW	32
150 
151 typedef u32		compat_sigset_word;
152 
153 #define COMPAT_OFF_T_MAX	0x7fffffff
154 
155 /*
156  * A pointer passed in from user mode. This should not
157  * be used for syscall parameters, just declare them
158  * as pointers because the syscall entry code will have
159  * appropriately converted them already.
160  */
161 
162 static inline void __user *compat_ptr(compat_uptr_t uptr)
163 {
164 	return (void __user *)(unsigned long)uptr;
165 }
166 
167 static inline compat_uptr_t ptr_to_compat(void __user *uptr)
168 {
169 	return (u32)(unsigned long)uptr;
170 }
171 
172 #define compat_user_stack_pointer() (user_stack_pointer(task_pt_regs(current)))
173 
174 static inline void __user *arch_compat_alloc_user_space(long len)
175 {
176 	return (void __user *)compat_user_stack_pointer() - len;
177 }
178 
179 struct compat_ipc64_perm {
180 	compat_key_t key;
181 	__compat_uid32_t uid;
182 	__compat_gid32_t gid;
183 	__compat_uid32_t cuid;
184 	__compat_gid32_t cgid;
185 	unsigned short mode;
186 	unsigned short __pad1;
187 	unsigned short seq;
188 	unsigned short __pad2;
189 	compat_ulong_t unused1;
190 	compat_ulong_t unused2;
191 };
192 
193 struct compat_semid64_ds {
194 	struct compat_ipc64_perm sem_perm;
195 	compat_time_t  sem_otime;
196 	compat_ulong_t __unused1;
197 	compat_time_t  sem_ctime;
198 	compat_ulong_t __unused2;
199 	compat_ulong_t sem_nsems;
200 	compat_ulong_t __unused3;
201 	compat_ulong_t __unused4;
202 };
203 
204 struct compat_msqid64_ds {
205 	struct compat_ipc64_perm msg_perm;
206 	compat_time_t  msg_stime;
207 	compat_ulong_t __unused1;
208 	compat_time_t  msg_rtime;
209 	compat_ulong_t __unused2;
210 	compat_time_t  msg_ctime;
211 	compat_ulong_t __unused3;
212 	compat_ulong_t msg_cbytes;
213 	compat_ulong_t msg_qnum;
214 	compat_ulong_t msg_qbytes;
215 	compat_pid_t   msg_lspid;
216 	compat_pid_t   msg_lrpid;
217 	compat_ulong_t __unused4;
218 	compat_ulong_t __unused5;
219 };
220 
221 struct compat_shmid64_ds {
222 	struct compat_ipc64_perm shm_perm;
223 	compat_size_t  shm_segsz;
224 	compat_time_t  shm_atime;
225 	compat_ulong_t __unused1;
226 	compat_time_t  shm_dtime;
227 	compat_ulong_t __unused2;
228 	compat_time_t  shm_ctime;
229 	compat_ulong_t __unused3;
230 	compat_pid_t   shm_cpid;
231 	compat_pid_t   shm_lpid;
232 	compat_ulong_t shm_nattch;
233 	compat_ulong_t __unused4;
234 	compat_ulong_t __unused5;
235 };
236 
237 static inline int is_compat_task(void)
238 {
239 	return test_thread_flag(TIF_32BIT);
240 }
241 
242 static inline int is_compat_thread(struct thread_info *thread)
243 {
244 	return test_ti_thread_flag(thread, TIF_32BIT);
245 }
246 
247 #else /* !CONFIG_COMPAT */
248 
249 static inline int is_compat_thread(struct thread_info *thread)
250 {
251 	return 0;
252 }
253 
254 #endif /* CONFIG_COMPAT */
255 #endif /* __KERNEL__ */
256 #endif /* __ASM_COMPAT_H */
257