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