GNU Linux-libre 4.14.254-gnu1
[releases.git] / arch / mips / include / asm / compat.h
1 /* SPDX-License-Identifier: GPL-2.0 */
2 #ifndef _ASM_COMPAT_H
3 #define _ASM_COMPAT_H
4 /*
5  * Architecture specific compatibility types
6  */
7 #include <linux/thread_info.h>
8 #include <linux/types.h>
9 #include <asm/page.h>
10 #include <asm/ptrace.h>
11
12 #define COMPAT_USER_HZ          100
13 #define COMPAT_UTS_MACHINE      "mips\0\0\0"
14
15 typedef u32             compat_size_t;
16 typedef s32             compat_ssize_t;
17 typedef s32             compat_time_t;
18 typedef s32             compat_clock_t;
19 typedef s32             compat_suseconds_t;
20
21 typedef s32             compat_pid_t;
22 typedef s32             __compat_uid_t;
23 typedef s32             __compat_gid_t;
24 typedef __compat_uid_t  __compat_uid32_t;
25 typedef __compat_gid_t  __compat_gid32_t;
26 typedef u32             compat_mode_t;
27 typedef u32             compat_ino_t;
28 typedef u32             compat_dev_t;
29 typedef s32             compat_off_t;
30 typedef s64             compat_loff_t;
31 typedef u32             compat_nlink_t;
32 typedef s32             compat_ipc_pid_t;
33 typedef s32             compat_daddr_t;
34 typedef s32             compat_caddr_t;
35 typedef struct {
36         s32     val[2];
37 } compat_fsid_t;
38 typedef s32             compat_timer_t;
39 typedef s32             compat_key_t;
40
41 typedef s32             compat_int_t;
42 typedef s32             compat_long_t;
43 typedef s64             compat_s64;
44 typedef u32             compat_uint_t;
45 typedef u32             compat_ulong_t;
46 typedef u64             compat_u64;
47 typedef u32             compat_uptr_t;
48
49 struct compat_timespec {
50         compat_time_t   tv_sec;
51         s32             tv_nsec;
52 };
53
54 struct compat_timeval {
55         compat_time_t   tv_sec;
56         s32             tv_usec;
57 };
58
59 struct compat_stat {
60         compat_dev_t    st_dev;
61         s32             st_pad1[3];
62         compat_ino_t    st_ino;
63         compat_mode_t   st_mode;
64         compat_nlink_t  st_nlink;
65         __compat_uid_t  st_uid;
66         __compat_gid_t  st_gid;
67         compat_dev_t    st_rdev;
68         s32             st_pad2[2];
69         compat_off_t    st_size;
70         s32             st_pad3;
71         compat_time_t   st_atime;
72         s32             st_atime_nsec;
73         compat_time_t   st_mtime;
74         s32             st_mtime_nsec;
75         compat_time_t   st_ctime;
76         s32             st_ctime_nsec;
77         s32             st_blksize;
78         s32             st_blocks;
79         s32             st_pad4[14];
80 };
81
82 struct compat_flock {
83         short           l_type;
84         short           l_whence;
85         compat_off_t    l_start;
86         compat_off_t    l_len;
87         s32             l_sysid;
88         compat_pid_t    l_pid;
89         s32             pad[4];
90 };
91
92 #define F_GETLK64       33
93 #define F_SETLK64       34
94 #define F_SETLKW64      35
95
96 struct compat_flock64 {
97         short           l_type;
98         short           l_whence;
99         compat_loff_t   l_start;
100         compat_loff_t   l_len;
101         compat_pid_t    l_pid;
102 };
103
104 struct compat_statfs {
105         int             f_type;
106         int             f_bsize;
107         int             f_frsize;
108         int             f_blocks;
109         int             f_bfree;
110         int             f_files;
111         int             f_ffree;
112         int             f_bavail;
113         compat_fsid_t   f_fsid;
114         int             f_namelen;
115         int             f_flags;
116         int             f_spare[5];
117 };
118
119 #define COMPAT_RLIM_INFINITY    0x7fffffffUL
120
121 typedef u32             compat_old_sigset_t;    /* at least 32 bits */
122
123 #define _COMPAT_NSIG            128             /* Don't ask !$@#% ...  */
124 #define _COMPAT_NSIG_BPW        32
125
126 typedef u32             compat_sigset_word;
127
128 typedef union compat_sigval {
129         compat_int_t    sival_int;
130         compat_uptr_t   sival_ptr;
131 } compat_sigval_t;
132
133 /* Can't use the generic version because si_code and si_errno are swapped */
134
135 #define SI_PAD_SIZE32   (128/sizeof(int) - 3)
136
137 typedef struct compat_siginfo {
138         int si_signo;
139         int si_code;
140         int si_errno;
141
142         union {
143                 int _pad[128 / sizeof(int) - 3];
144
145                 /* kill() */
146                 struct {
147                         compat_pid_t _pid;      /* sender's pid */
148                         __compat_uid32_t _uid;  /* sender's uid */
149                 } _kill;
150
151                 /* POSIX.1b timers */
152                 struct {
153                         compat_timer_t _tid;    /* timer id */
154                         int _overrun;           /* overrun count */
155                         compat_sigval_t _sigval;        /* same as below */
156                 } _timer;
157
158                 /* POSIX.1b signals */
159                 struct {
160                         compat_pid_t _pid;      /* sender's pid */
161                         __compat_uid32_t _uid;  /* sender's uid */
162                         compat_sigval_t _sigval;
163                 } _rt;
164
165                 /* SIGCHLD */
166                 struct {
167                         compat_pid_t _pid;      /* which child */
168                         __compat_uid32_t _uid;  /* sender's uid */
169                         int _status;            /* exit code */
170                         compat_clock_t _utime;
171                         compat_clock_t _stime;
172                 } _sigchld;
173
174                 /* SIGILL, SIGFPE, SIGSEGV, SIGBUS */
175                 struct {
176                         compat_uptr_t _addr;    /* faulting insn/memory ref. */
177 #ifdef __ARCH_SI_TRAPNO
178                         int _trapno;    /* TRAP # which caused the signal */
179 #endif
180                         short _addr_lsb; /* LSB of the reported address */
181                         struct {
182                                 compat_uptr_t _lower;
183                                 compat_uptr_t _upper;
184                         } _addr_bnd;
185                 } _sigfault;
186
187                 /* SIGPOLL */
188                 struct {
189                         compat_long_t _band; /* POLL_IN, POLL_OUT, POLL_MSG */
190                         int _fd;
191                 } _sigpoll;
192
193                 struct {
194                         compat_uptr_t _call_addr; /* calling insn */
195                         int _syscall;   /* triggering system call number */
196                         compat_uint_t _arch;    /* AUDIT_ARCH_* of syscall */
197                 } _sigsys;
198         } _sifields;
199 } compat_siginfo_t;
200
201 #define COMPAT_OFF_T_MAX        0x7fffffff
202
203 /*
204  * A pointer passed in from user mode. This should not
205  * be used for syscall parameters, just declare them
206  * as pointers because the syscall entry code will have
207  * appropriately converted them already.
208  */
209
210 static inline void __user *compat_ptr(compat_uptr_t uptr)
211 {
212         /* cast to a __user pointer via "unsigned long" makes sparse happy */
213         return (void __user *)(unsigned long)(long)uptr;
214 }
215
216 static inline compat_uptr_t ptr_to_compat(void __user *uptr)
217 {
218         return (u32)(unsigned long)uptr;
219 }
220
221 static inline void __user *arch_compat_alloc_user_space(long len)
222 {
223         struct pt_regs *regs = (struct pt_regs *)
224                 ((unsigned long) current_thread_info() + THREAD_SIZE - 32) - 1;
225
226         return (void __user *) (regs->regs[29] - len);
227 }
228
229 struct compat_ipc64_perm {
230         compat_key_t key;
231         __compat_uid32_t uid;
232         __compat_gid32_t gid;
233         __compat_uid32_t cuid;
234         __compat_gid32_t cgid;
235         compat_mode_t mode;
236         unsigned short seq;
237         unsigned short __pad2;
238         compat_ulong_t __unused1;
239         compat_ulong_t __unused2;
240 };
241
242 struct compat_semid64_ds {
243         struct compat_ipc64_perm sem_perm;
244         compat_time_t   sem_otime;
245         compat_time_t   sem_ctime;
246         compat_ulong_t  sem_nsems;
247         compat_ulong_t  __unused1;
248         compat_ulong_t  __unused2;
249 };
250
251 struct compat_msqid64_ds {
252         struct compat_ipc64_perm msg_perm;
253 #ifndef CONFIG_CPU_LITTLE_ENDIAN
254         compat_ulong_t  __unused1;
255 #endif
256         compat_time_t   msg_stime;
257 #ifdef CONFIG_CPU_LITTLE_ENDIAN
258         compat_ulong_t  __unused1;
259 #endif
260 #ifndef CONFIG_CPU_LITTLE_ENDIAN
261         compat_ulong_t  __unused2;
262 #endif
263         compat_time_t   msg_rtime;
264 #ifdef CONFIG_CPU_LITTLE_ENDIAN
265         compat_ulong_t  __unused2;
266 #endif
267 #ifndef CONFIG_CPU_LITTLE_ENDIAN
268         compat_ulong_t  __unused3;
269 #endif
270         compat_time_t   msg_ctime;
271 #ifdef CONFIG_CPU_LITTLE_ENDIAN
272         compat_ulong_t  __unused3;
273 #endif
274         compat_ulong_t  msg_cbytes;
275         compat_ulong_t  msg_qnum;
276         compat_ulong_t  msg_qbytes;
277         compat_pid_t    msg_lspid;
278         compat_pid_t    msg_lrpid;
279         compat_ulong_t  __unused4;
280         compat_ulong_t  __unused5;
281 };
282
283 struct compat_shmid64_ds {
284         struct compat_ipc64_perm shm_perm;
285         compat_size_t   shm_segsz;
286         compat_time_t   shm_atime;
287         compat_time_t   shm_dtime;
288         compat_time_t   shm_ctime;
289         compat_pid_t    shm_cpid;
290         compat_pid_t    shm_lpid;
291         compat_ulong_t  shm_nattch;
292         compat_ulong_t  __unused1;
293         compat_ulong_t  __unused2;
294 };
295
296 /* MIPS has unusual order of fields in stack_t */
297 typedef struct compat_sigaltstack {
298         compat_uptr_t                   ss_sp;
299         compat_size_t                   ss_size;
300         int                             ss_flags;
301 } compat_stack_t;
302 #define compat_sigaltstack compat_sigaltstack
303
304 static inline int is_compat_task(void)
305 {
306         return test_thread_flag(TIF_32BIT_ADDR);
307 }
308
309 #endif /* _ASM_COMPAT_H */