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