blob: b69e27152ea54fa204caf151d21622fb15a929c4 [file] [log] [blame]
Will Deacon3dd681d2012-03-05 11:49:32 +00001/*
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
27#define COMPAT_USER_HZ 100
Will Deacona795a382013-10-11 14:52:12 +010028#ifdef __AARCH64EB__
29#define COMPAT_UTS_MACHINE "armv8b\0\0"
30#else
Will Deacon3dd681d2012-03-05 11:49:32 +000031#define COMPAT_UTS_MACHINE "armv8l\0\0"
Will Deacona795a382013-10-11 14:52:12 +010032#endif
Will Deacon3dd681d2012-03-05 11:49:32 +000033
34typedef u32 compat_size_t;
35typedef s32 compat_ssize_t;
36typedef s32 compat_time_t;
37typedef s32 compat_clock_t;
38typedef s32 compat_pid_t;
Victor Kamensky971a5b62014-10-14 06:55:05 +010039typedef u16 __compat_uid_t;
40typedef u16 __compat_gid_t;
Catalin Marinasf15a2a12013-04-25 11:23:41 +010041typedef u16 __compat_uid16_t;
42typedef u16 __compat_gid16_t;
Will Deacon3dd681d2012-03-05 11:49:32 +000043typedef u32 __compat_uid32_t;
44typedef u32 __compat_gid32_t;
Catalin Marinasf15a2a12013-04-25 11:23:41 +010045typedef u16 compat_mode_t;
Will Deacon3dd681d2012-03-05 11:49:32 +000046typedef u32 compat_ino_t;
47typedef u32 compat_dev_t;
48typedef s32 compat_off_t;
49typedef s64 compat_loff_t;
Catalin Marinasf15a2a12013-04-25 11:23:41 +010050typedef s32 compat_nlink_t;
Will Deacon3dd681d2012-03-05 11:49:32 +000051typedef u16 compat_ipc_pid_t;
52typedef s32 compat_daddr_t;
53typedef u32 compat_caddr_t;
54typedef __kernel_fsid_t compat_fsid_t;
55typedef s32 compat_key_t;
56typedef s32 compat_timer_t;
57
Catalin Marinasf15a2a12013-04-25 11:23:41 +010058typedef s16 compat_short_t;
Will Deacon3dd681d2012-03-05 11:49:32 +000059typedef s32 compat_int_t;
60typedef s32 compat_long_t;
61typedef s64 compat_s64;
Catalin Marinasf15a2a12013-04-25 11:23:41 +010062typedef u16 compat_ushort_t;
Will Deacon3dd681d2012-03-05 11:49:32 +000063typedef u32 compat_uint_t;
64typedef u32 compat_ulong_t;
65typedef u64 compat_u64;
Denys Vlasenko751f4092012-10-04 17:15:31 -070066typedef u32 compat_uptr_t;
Will Deacon3dd681d2012-03-05 11:49:32 +000067
68struct compat_timespec {
69 compat_time_t tv_sec;
70 s32 tv_nsec;
71};
72
73struct compat_timeval {
74 compat_time_t tv_sec;
75 s32 tv_usec;
76};
77
78struct compat_stat {
Will Deacona795a382013-10-11 14:52:12 +010079#ifdef __AARCH64EB__
80 short st_dev;
81 short __pad1;
82#else
Will Deacon3dd681d2012-03-05 11:49:32 +000083 compat_dev_t st_dev;
Will Deacona795a382013-10-11 14:52:12 +010084#endif
Will Deacon3dd681d2012-03-05 11:49:32 +000085 compat_ino_t st_ino;
86 compat_mode_t st_mode;
Catalin Marinasf15a2a12013-04-25 11:23:41 +010087 compat_ushort_t st_nlink;
88 __compat_uid16_t st_uid;
89 __compat_gid16_t st_gid;
Will Deacona795a382013-10-11 14:52:12 +010090#ifdef __AARCH64EB__
91 short st_rdev;
92 short __pad2;
93#else
Will Deacon3dd681d2012-03-05 11:49:32 +000094 compat_dev_t st_rdev;
Will Deacona795a382013-10-11 14:52:12 +010095#endif
Will Deacon3dd681d2012-03-05 11:49:32 +000096 compat_off_t st_size;
97 compat_off_t st_blksize;
98 compat_off_t st_blocks;
99 compat_time_t st_atime;
Catalin Marinasf15a2a12013-04-25 11:23:41 +0100100 compat_ulong_t st_atime_nsec;
Will Deacon3dd681d2012-03-05 11:49:32 +0000101 compat_time_t st_mtime;
Catalin Marinasf15a2a12013-04-25 11:23:41 +0100102 compat_ulong_t st_mtime_nsec;
Will Deacon3dd681d2012-03-05 11:49:32 +0000103 compat_time_t st_ctime;
Catalin Marinasf15a2a12013-04-25 11:23:41 +0100104 compat_ulong_t st_ctime_nsec;
105 compat_ulong_t __unused4[2];
Will Deacon3dd681d2012-03-05 11:49:32 +0000106};
107
108struct compat_flock {
109 short l_type;
110 short l_whence;
111 compat_off_t l_start;
112 compat_off_t l_len;
113 compat_pid_t l_pid;
114};
115
116#define F_GETLK64 12 /* using 'struct flock64' */
117#define F_SETLK64 13
118#define F_SETLKW64 14
119
120struct compat_flock64 {
121 short l_type;
122 short l_whence;
123 compat_loff_t l_start;
124 compat_loff_t l_len;
125 compat_pid_t l_pid;
126};
127
128struct compat_statfs {
129 int f_type;
130 int f_bsize;
131 int f_blocks;
132 int f_bfree;
133 int f_bavail;
134 int f_files;
135 int f_ffree;
136 compat_fsid_t f_fsid;
137 int f_namelen; /* SunOS ignores this field. */
138 int f_frsize;
139 int f_flags;
140 int f_spare[4];
141};
142
143#define COMPAT_RLIM_INFINITY 0xffffffff
144
145typedef u32 compat_old_sigset_t;
146
147#define _COMPAT_NSIG 64
148#define _COMPAT_NSIG_BPW 32
149
150typedef u32 compat_sigset_word;
151
Denys Vlasenko751f4092012-10-04 17:15:31 -0700152typedef union compat_sigval {
153 compat_int_t sival_int;
154 compat_uptr_t sival_ptr;
155} compat_sigval_t;
156
157typedef struct compat_siginfo {
158 int si_signo;
159 int si_errno;
160 int si_code;
161
162 union {
Denys Vlasenko751f4092012-10-04 17:15:31 -0700163 int _pad[128/sizeof(int) - 3];
164
165 /* kill() */
166 struct {
167 compat_pid_t _pid; /* sender's pid */
168 __compat_uid32_t _uid; /* sender's uid */
169 } _kill;
170
171 /* POSIX.1b timers */
172 struct {
173 compat_timer_t _tid; /* timer id */
174 int _overrun; /* overrun count */
175 compat_sigval_t _sigval; /* same as below */
176 int _sys_private; /* not to be passed to user */
177 } _timer;
178
179 /* POSIX.1b signals */
180 struct {
181 compat_pid_t _pid; /* sender's pid */
182 __compat_uid32_t _uid; /* sender's uid */
183 compat_sigval_t _sigval;
184 } _rt;
185
186 /* SIGCHLD */
187 struct {
188 compat_pid_t _pid; /* which child */
189 __compat_uid32_t _uid; /* sender's uid */
190 int _status; /* exit code */
191 compat_clock_t _utime;
192 compat_clock_t _stime;
193 } _sigchld;
194
195 /* SIGILL, SIGFPE, SIGSEGV, SIGBUS */
196 struct {
197 compat_uptr_t _addr; /* faulting insn/memory ref. */
198 short _addr_lsb; /* LSB of the reported address */
199 } _sigfault;
200
201 /* SIGPOLL */
202 struct {
203 compat_long_t _band; /* POLL_IN, POLL_OUT, POLL_MSG */
204 int _fd;
205 } _sigpoll;
AKASHI Takahirocc5e9092014-11-28 05:26:38 +0000206
207 /* SIGSYS */
208 struct {
209 compat_uptr_t _call_addr; /* calling user insn */
210 int _syscall; /* triggering system call number */
211 compat_uint_t _arch; /* AUDIT_ARCH_* of syscall */
212 } _sigsys;
Denys Vlasenko751f4092012-10-04 17:15:31 -0700213 } _sifields;
214} compat_siginfo_t;
215
Will Deacon3dd681d2012-03-05 11:49:32 +0000216#define COMPAT_OFF_T_MAX 0x7fffffff
217#define COMPAT_LOFF_T_MAX 0x7fffffffffffffffL
218
219/*
220 * A pointer passed in from user mode. This should not
221 * be used for syscall parameters, just declare them
222 * as pointers because the syscall entry code will have
223 * appropriately converted them already.
224 */
Will Deacon3dd681d2012-03-05 11:49:32 +0000225
226static inline void __user *compat_ptr(compat_uptr_t uptr)
227{
228 return (void __user *)(unsigned long)uptr;
229}
230
231static inline compat_uptr_t ptr_to_compat(void __user *uptr)
232{
233 return (u32)(unsigned long)uptr;
234}
235
Arnd Bergmannadc235a2015-11-16 17:32:15 +0100236#define compat_user_stack_pointer() (user_stack_pointer(task_pt_regs(current)))
Will Deacon8902d3a2018-09-05 15:34:43 +0100237#define COMPAT_MINSIGSTKSZ 2048
Al Viro9b064fc2012-12-14 13:49:35 -0500238
Will Deacon3dd681d2012-03-05 11:49:32 +0000239static inline void __user *arch_compat_alloc_user_space(long len)
240{
Al Viro9b064fc2012-12-14 13:49:35 -0500241 return (void __user *)compat_user_stack_pointer() - len;
Will Deacon3dd681d2012-03-05 11:49:32 +0000242}
243
244struct compat_ipc64_perm {
245 compat_key_t key;
246 __compat_uid32_t uid;
247 __compat_gid32_t gid;
248 __compat_uid32_t cuid;
249 __compat_gid32_t cgid;
250 unsigned short mode;
251 unsigned short __pad1;
252 unsigned short seq;
253 unsigned short __pad2;
254 compat_ulong_t unused1;
255 compat_ulong_t unused2;
256};
257
258struct compat_semid64_ds {
259 struct compat_ipc64_perm sem_perm;
260 compat_time_t sem_otime;
261 compat_ulong_t __unused1;
262 compat_time_t sem_ctime;
263 compat_ulong_t __unused2;
264 compat_ulong_t sem_nsems;
265 compat_ulong_t __unused3;
266 compat_ulong_t __unused4;
267};
268
269struct compat_msqid64_ds {
270 struct compat_ipc64_perm msg_perm;
271 compat_time_t msg_stime;
272 compat_ulong_t __unused1;
273 compat_time_t msg_rtime;
274 compat_ulong_t __unused2;
275 compat_time_t msg_ctime;
276 compat_ulong_t __unused3;
277 compat_ulong_t msg_cbytes;
278 compat_ulong_t msg_qnum;
279 compat_ulong_t msg_qbytes;
280 compat_pid_t msg_lspid;
281 compat_pid_t msg_lrpid;
282 compat_ulong_t __unused4;
283 compat_ulong_t __unused5;
284};
285
286struct compat_shmid64_ds {
287 struct compat_ipc64_perm shm_perm;
288 compat_size_t shm_segsz;
289 compat_time_t shm_atime;
290 compat_ulong_t __unused1;
291 compat_time_t shm_dtime;
292 compat_ulong_t __unused2;
293 compat_time_t shm_ctime;
294 compat_ulong_t __unused3;
295 compat_pid_t shm_cpid;
296 compat_pid_t shm_lpid;
297 compat_ulong_t shm_nattch;
298 compat_ulong_t __unused4;
299 compat_ulong_t __unused5;
300};
301
302static inline int is_compat_task(void)
303{
304 return test_thread_flag(TIF_32BIT);
305}
306
307static inline int is_compat_thread(struct thread_info *thread)
308{
309 return test_ti_thread_flag(thread, TIF_32BIT);
310}
311
312#else /* !CONFIG_COMPAT */
313
Will Deacon3dd681d2012-03-05 11:49:32 +0000314static inline int is_compat_thread(struct thread_info *thread)
315{
316 return 0;
317}
318
319#endif /* CONFIG_COMPAT */
320#endif /* __KERNEL__ */
321#endif /* __ASM_COMPAT_H */