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