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