xref: /openbmc/linux/arch/s390/include/asm/compat.h (revision e23feb16)
1 #ifndef _ASM_S390X_COMPAT_H
2 #define _ASM_S390X_COMPAT_H
3 /*
4  * Architecture specific compatibility types
5  */
6 #include <linux/types.h>
7 #include <linux/sched.h>
8 #include <linux/thread_info.h>
9 
10 #define __TYPE_IS_PTR(t) (!__builtin_types_compatible_p(typeof(0?(t)0:0ULL), u64))
11 #define __SC_DELOUSE(t,v) (t)(__TYPE_IS_PTR(t) ? ((v) & 0x7fffffff) : (v))
12 
13 #define PSW32_MASK_PER		0x40000000UL
14 #define PSW32_MASK_DAT		0x04000000UL
15 #define PSW32_MASK_IO		0x02000000UL
16 #define PSW32_MASK_EXT		0x01000000UL
17 #define PSW32_MASK_KEY		0x00F00000UL
18 #define PSW32_MASK_BASE		0x00080000UL	/* Always one */
19 #define PSW32_MASK_MCHECK	0x00040000UL
20 #define PSW32_MASK_WAIT		0x00020000UL
21 #define PSW32_MASK_PSTATE	0x00010000UL
22 #define PSW32_MASK_ASC		0x0000C000UL
23 #define PSW32_MASK_CC		0x00003000UL
24 #define PSW32_MASK_PM		0x00000f00UL
25 
26 #define PSW32_MASK_USER		0x0000FF00UL
27 
28 #define PSW32_ADDR_AMODE	0x80000000UL
29 #define PSW32_ADDR_INSN		0x7FFFFFFFUL
30 
31 #define PSW32_DEFAULT_KEY	(((u32) PAGE_DEFAULT_ACC) << 20)
32 
33 #define PSW32_ASC_PRIMARY	0x00000000UL
34 #define PSW32_ASC_ACCREG	0x00004000UL
35 #define PSW32_ASC_SECONDARY	0x00008000UL
36 #define PSW32_ASC_HOME		0x0000C000UL
37 
38 extern u32 psw32_user_bits;
39 
40 #define COMPAT_USER_HZ		100
41 #define COMPAT_UTS_MACHINE	"s390\0\0\0\0"
42 
43 typedef u32		compat_size_t;
44 typedef s32		compat_ssize_t;
45 typedef s32		compat_time_t;
46 typedef s32		compat_clock_t;
47 typedef s32		compat_pid_t;
48 typedef u16		__compat_uid_t;
49 typedef u16		__compat_gid_t;
50 typedef u32		__compat_uid32_t;
51 typedef u32		__compat_gid32_t;
52 typedef u16		compat_mode_t;
53 typedef u32		compat_ino_t;
54 typedef u16		compat_dev_t;
55 typedef s32		compat_off_t;
56 typedef s64		compat_loff_t;
57 typedef u16		compat_nlink_t;
58 typedef u16		compat_ipc_pid_t;
59 typedef s32		compat_daddr_t;
60 typedef u32		compat_caddr_t;
61 typedef __kernel_fsid_t	compat_fsid_t;
62 typedef s32		compat_key_t;
63 typedef s32		compat_timer_t;
64 
65 typedef s32		compat_int_t;
66 typedef s32		compat_long_t;
67 typedef s64		compat_s64;
68 typedef u32		compat_uint_t;
69 typedef u32		compat_ulong_t;
70 typedef u64		compat_u64;
71 typedef u32		compat_uptr_t;
72 
73 typedef struct {
74 	u32 mask;
75 	u32 addr;
76 } __aligned(8) psw_compat_t;
77 
78 typedef struct {
79 	psw_compat_t psw;
80 	u32 gprs[NUM_GPRS];
81 	u32 acrs[NUM_ACRS];
82 	u32 orig_gpr2;
83 } s390_compat_regs;
84 
85 typedef struct {
86 	u32 gprs_high[NUM_GPRS];
87 } s390_compat_regs_high;
88 
89 struct compat_timespec {
90 	compat_time_t	tv_sec;
91 	s32		tv_nsec;
92 };
93 
94 struct compat_timeval {
95 	compat_time_t	tv_sec;
96 	s32		tv_usec;
97 };
98 
99 struct compat_stat {
100 	compat_dev_t	st_dev;
101 	u16		__pad1;
102 	compat_ino_t	st_ino;
103 	compat_mode_t	st_mode;
104 	compat_nlink_t	st_nlink;
105 	__compat_uid_t	st_uid;
106 	__compat_gid_t	st_gid;
107 	compat_dev_t	st_rdev;
108 	u16		__pad2;
109 	u32		st_size;
110 	u32		st_blksize;
111 	u32		st_blocks;
112 	u32		st_atime;
113 	u32		st_atime_nsec;
114 	u32		st_mtime;
115 	u32		st_mtime_nsec;
116 	u32		st_ctime;
117 	u32		st_ctime_nsec;
118 	u32		__unused4;
119 	u32		__unused5;
120 };
121 
122 struct compat_flock {
123 	short		l_type;
124 	short		l_whence;
125 	compat_off_t	l_start;
126 	compat_off_t	l_len;
127 	compat_pid_t	l_pid;
128 };
129 
130 #define F_GETLK64       12
131 #define F_SETLK64       13
132 #define F_SETLKW64      14
133 
134 struct compat_flock64 {
135 	short		l_type;
136 	short		l_whence;
137 	compat_loff_t	l_start;
138 	compat_loff_t	l_len;
139 	compat_pid_t	l_pid;
140 };
141 
142 struct compat_statfs {
143 	u32		f_type;
144 	u32		f_bsize;
145 	u32		f_blocks;
146 	u32		f_bfree;
147 	u32		f_bavail;
148 	u32		f_files;
149 	u32		f_ffree;
150 	compat_fsid_t	f_fsid;
151 	u32		f_namelen;
152 	u32		f_frsize;
153 	u32		f_flags;
154 	u32		f_spare[4];
155 };
156 
157 struct compat_statfs64 {
158 	u32		f_type;
159 	u32		f_bsize;
160 	u64		f_blocks;
161 	u64		f_bfree;
162 	u64		f_bavail;
163 	u64		f_files;
164 	u64		f_ffree;
165 	compat_fsid_t	f_fsid;
166 	u32		f_namelen;
167 	u32		f_frsize;
168 	u32		f_flags;
169 	u32		f_spare[4];
170 };
171 
172 #define COMPAT_RLIM_OLD_INFINITY	0x7fffffff
173 #define COMPAT_RLIM_INFINITY		0xffffffff
174 
175 typedef u32		compat_old_sigset_t;	/* at least 32 bits */
176 
177 #define _COMPAT_NSIG		64
178 #define _COMPAT_NSIG_BPW	32
179 
180 typedef u32		compat_sigset_word;
181 
182 typedef union compat_sigval {
183 	compat_int_t	sival_int;
184 	compat_uptr_t	sival_ptr;
185 } compat_sigval_t;
186 
187 typedef struct compat_siginfo {
188 	int	si_signo;
189 	int	si_errno;
190 	int	si_code;
191 
192 	union {
193 		int _pad[128/sizeof(int) - 3];
194 
195 		/* kill() */
196 		struct {
197 			pid_t	_pid;	/* sender's pid */
198 			uid_t	_uid;	/* sender's uid */
199 		} _kill;
200 
201 		/* POSIX.1b timers */
202 		struct {
203 			compat_timer_t _tid;		/* timer id */
204 			int _overrun;			/* overrun count */
205 			compat_sigval_t _sigval;	/* same as below */
206 			int _sys_private;	/* not to be passed to user */
207 		} _timer;
208 
209 		/* POSIX.1b signals */
210 		struct {
211 			pid_t			_pid;	/* sender's pid */
212 			uid_t			_uid;	/* sender's uid */
213 			compat_sigval_t		_sigval;
214 		} _rt;
215 
216 		/* SIGCHLD */
217 		struct {
218 			pid_t			_pid;	/* which child */
219 			uid_t			_uid;	/* sender's uid */
220 			int			_status;/* exit code */
221 			compat_clock_t		_utime;
222 			compat_clock_t		_stime;
223 		} _sigchld;
224 
225 		/* SIGILL, SIGFPE, SIGSEGV, SIGBUS */
226 		struct {
227 			__u32	_addr;	/* faulting insn/memory ref. - pointer */
228 		} _sigfault;
229 
230 		/* SIGPOLL */
231 		struct {
232 			int	_band;	/* POLL_IN, POLL_OUT, POLL_MSG */
233 			int	_fd;
234 		} _sigpoll;
235 	} _sifields;
236 } compat_siginfo_t;
237 
238 /*
239  * How these fields are to be accessed.
240  */
241 #define si_pid		_sifields._kill._pid
242 #define si_uid		_sifields._kill._uid
243 #define si_status	_sifields._sigchld._status
244 #define si_utime	_sifields._sigchld._utime
245 #define si_stime	_sifields._sigchld._stime
246 #define si_value	_sifields._rt._sigval
247 #define si_int		_sifields._rt._sigval.sival_int
248 #define si_ptr		_sifields._rt._sigval.sival_ptr
249 #define si_addr		_sifields._sigfault._addr
250 #define si_band		_sifields._sigpoll._band
251 #define si_fd		_sifields._sigpoll._fd
252 #define si_tid		_sifields._timer._tid
253 #define si_overrun	_sifields._timer._overrun
254 
255 #define COMPAT_OFF_T_MAX	0x7fffffff
256 #define COMPAT_LOFF_T_MAX	0x7fffffffffffffffL
257 
258 /*
259  * A pointer passed in from user mode. This should not
260  * be used for syscall parameters, just declare them
261  * as pointers because the syscall entry code will have
262  * appropriately converted them already.
263  */
264 
265 static inline void __user *compat_ptr(compat_uptr_t uptr)
266 {
267 	return (void __user *)(unsigned long)(uptr & 0x7fffffffUL);
268 }
269 
270 static inline compat_uptr_t ptr_to_compat(void __user *uptr)
271 {
272 	return (u32)(unsigned long)uptr;
273 }
274 
275 #ifdef CONFIG_COMPAT
276 
277 static inline int is_compat_task(void)
278 {
279 	return is_32bit_task();
280 }
281 
282 static inline void __user *arch_compat_alloc_user_space(long len)
283 {
284 	unsigned long stack;
285 
286 	stack = KSTK_ESP(current);
287 	if (is_compat_task())
288 		stack &= 0x7fffffffUL;
289 	return (void __user *) (stack - len);
290 }
291 
292 #endif
293 
294 struct compat_ipc64_perm {
295 	compat_key_t key;
296 	__compat_uid32_t uid;
297 	__compat_gid32_t gid;
298 	__compat_uid32_t cuid;
299 	__compat_gid32_t cgid;
300 	compat_mode_t mode;
301 	unsigned short __pad1;
302 	unsigned short seq;
303 	unsigned short __pad2;
304 	unsigned int __unused1;
305 	unsigned int __unused2;
306 };
307 
308 struct compat_semid64_ds {
309 	struct compat_ipc64_perm sem_perm;
310 	compat_time_t  sem_otime;
311 	compat_ulong_t __pad1;
312 	compat_time_t  sem_ctime;
313 	compat_ulong_t __pad2;
314 	compat_ulong_t sem_nsems;
315 	compat_ulong_t __unused1;
316 	compat_ulong_t __unused2;
317 };
318 
319 struct compat_msqid64_ds {
320 	struct compat_ipc64_perm msg_perm;
321 	compat_time_t   msg_stime;
322 	compat_ulong_t __pad1;
323 	compat_time_t   msg_rtime;
324 	compat_ulong_t __pad2;
325 	compat_time_t   msg_ctime;
326 	compat_ulong_t __pad3;
327 	compat_ulong_t msg_cbytes;
328 	compat_ulong_t msg_qnum;
329 	compat_ulong_t msg_qbytes;
330 	compat_pid_t   msg_lspid;
331 	compat_pid_t   msg_lrpid;
332 	compat_ulong_t __unused1;
333 	compat_ulong_t __unused2;
334 };
335 
336 struct compat_shmid64_ds {
337 	struct compat_ipc64_perm shm_perm;
338 	compat_size_t  shm_segsz;
339 	compat_time_t  shm_atime;
340 	compat_ulong_t __pad1;
341 	compat_time_t  shm_dtime;
342 	compat_ulong_t __pad2;
343 	compat_time_t  shm_ctime;
344 	compat_ulong_t __pad3;
345 	compat_pid_t   shm_cpid;
346 	compat_pid_t   shm_lpid;
347 	compat_ulong_t shm_nattch;
348 	compat_ulong_t __unused1;
349 	compat_ulong_t __unused2;
350 };
351 #endif /* _ASM_S390X_COMPAT_H */
352