Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 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> |
Heiko Carstens | 7757591 | 2009-06-12 10:26:25 +0200 | [diff] [blame] | 8 | #include <linux/thread_info.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 9 | |
Al Viro | 4683661 | 2012-11-23 09:12:59 -0500 | [diff] [blame] | 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 | |
Gerald Schaefer | c1821c2 | 2007-02-05 21:18:17 +0100 | [diff] [blame] | 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 |
Martin Schwidefsky | b50511e | 2011-10-30 15:16:50 +0100 | [diff] [blame] | 18 | #define PSW32_MASK_BASE 0x00080000UL /* Always one */ |
Gerald Schaefer | c1821c2 | 2007-02-05 21:18:17 +0100 | [diff] [blame] | 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 | |
Martin Schwidefsky | fa968ee | 2012-11-07 10:44:08 +0100 | [diff] [blame] | 26 | #define PSW32_MASK_USER 0x0000FF00UL |
Martin Schwidefsky | b50511e | 2011-10-30 15:16:50 +0100 | [diff] [blame] | 27 | |
| 28 | #define PSW32_ADDR_AMODE 0x80000000UL |
Gerald Schaefer | c1821c2 | 2007-02-05 21:18:17 +0100 | [diff] [blame] | 29 | #define PSW32_ADDR_INSN 0x7FFFFFFFUL |
| 30 | |
Martin Schwidefsky | b50511e | 2011-10-30 15:16:50 +0100 | [diff] [blame] | 31 | #define PSW32_DEFAULT_KEY (((u32) PAGE_DEFAULT_ACC) << 20) |
Gerald Schaefer | c1821c2 | 2007-02-05 21:18:17 +0100 | [diff] [blame] | 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 | |
Martin Schwidefsky | b50511e | 2011-10-30 15:16:50 +0100 | [diff] [blame] | 38 | extern u32 psw32_user_bits; |
Gerald Schaefer | c1821c2 | 2007-02-05 21:18:17 +0100 | [diff] [blame] | 39 | |
Christoph Hellwig | e28cbf2 | 2010-03-10 15:21:19 -0800 | [diff] [blame] | 40 | #define COMPAT_USER_HZ 100 |
| 41 | #define COMPAT_UTS_MACHINE "s390\0\0\0\0" |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 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; |
Stephen Rothwell | 202e597 | 2005-09-06 15:16:40 -0700 | [diff] [blame] | 48 | typedef u16 __compat_uid_t; |
| 49 | typedef u16 __compat_gid_t; |
| 50 | typedef u32 __compat_uid32_t; |
| 51 | typedef u32 __compat_gid32_t; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 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; |
Arnd Bergmann | 4b77758 | 2007-07-15 23:41:11 -0700 | [diff] [blame] | 67 | typedef s64 compat_s64; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 68 | typedef u32 compat_uint_t; |
| 69 | typedef u32 compat_ulong_t; |
Arnd Bergmann | 4b77758 | 2007-07-15 23:41:11 -0700 | [diff] [blame] | 70 | typedef u64 compat_u64; |
Denys Vlasenko | 751f409 | 2012-10-04 17:15:31 -0700 | [diff] [blame] | 71 | typedef u32 compat_uptr_t; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 72 | |
Heiko Carstens | e4371f6 | 2013-04-20 14:05:42 +0200 | [diff] [blame^] | 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 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 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; |
Stephen Rothwell | 202e597 | 2005-09-06 15:16:40 -0700 | [diff] [blame] | 105 | __compat_uid_t st_uid; |
| 106 | __compat_gid_t st_gid; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 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 | s32 f_type; |
| 144 | s32 f_bsize; |
| 145 | s32 f_blocks; |
| 146 | s32 f_bfree; |
| 147 | s32 f_bavail; |
| 148 | s32 f_files; |
| 149 | s32 f_ffree; |
| 150 | compat_fsid_t f_fsid; |
| 151 | s32 f_namelen; |
| 152 | s32 f_frsize; |
Eric W. Biederman | 1448c72 | 2011-10-17 13:40:02 -0700 | [diff] [blame] | 153 | s32 f_flags; |
Heiko Carstens | a2aec0d | 2013-04-20 13:01:19 +0200 | [diff] [blame] | 154 | s32 f_spare[4]; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 155 | }; |
| 156 | |
| 157 | #define COMPAT_RLIM_OLD_INFINITY 0x7fffffff |
| 158 | #define COMPAT_RLIM_INFINITY 0xffffffff |
| 159 | |
| 160 | typedef u32 compat_old_sigset_t; /* at least 32 bits */ |
| 161 | |
| 162 | #define _COMPAT_NSIG 64 |
| 163 | #define _COMPAT_NSIG_BPW 32 |
| 164 | |
| 165 | typedef u32 compat_sigset_word; |
| 166 | |
Denys Vlasenko | 751f409 | 2012-10-04 17:15:31 -0700 | [diff] [blame] | 167 | typedef union compat_sigval { |
| 168 | compat_int_t sival_int; |
| 169 | compat_uptr_t sival_ptr; |
| 170 | } compat_sigval_t; |
| 171 | |
| 172 | typedef struct compat_siginfo { |
| 173 | int si_signo; |
| 174 | int si_errno; |
| 175 | int si_code; |
| 176 | |
| 177 | union { |
| 178 | int _pad[128/sizeof(int) - 3]; |
| 179 | |
| 180 | /* kill() */ |
| 181 | struct { |
| 182 | pid_t _pid; /* sender's pid */ |
| 183 | uid_t _uid; /* sender's uid */ |
| 184 | } _kill; |
| 185 | |
| 186 | /* POSIX.1b timers */ |
| 187 | struct { |
| 188 | compat_timer_t _tid; /* timer id */ |
| 189 | int _overrun; /* overrun count */ |
| 190 | compat_sigval_t _sigval; /* same as below */ |
| 191 | int _sys_private; /* not to be passed to user */ |
| 192 | } _timer; |
| 193 | |
| 194 | /* POSIX.1b signals */ |
| 195 | struct { |
| 196 | pid_t _pid; /* sender's pid */ |
| 197 | uid_t _uid; /* sender's uid */ |
| 198 | compat_sigval_t _sigval; |
| 199 | } _rt; |
| 200 | |
| 201 | /* SIGCHLD */ |
| 202 | struct { |
| 203 | pid_t _pid; /* which child */ |
| 204 | uid_t _uid; /* sender's uid */ |
| 205 | int _status;/* exit code */ |
| 206 | compat_clock_t _utime; |
| 207 | compat_clock_t _stime; |
| 208 | } _sigchld; |
| 209 | |
| 210 | /* SIGILL, SIGFPE, SIGSEGV, SIGBUS */ |
| 211 | struct { |
| 212 | __u32 _addr; /* faulting insn/memory ref. - pointer */ |
| 213 | } _sigfault; |
| 214 | |
| 215 | /* SIGPOLL */ |
| 216 | struct { |
| 217 | int _band; /* POLL_IN, POLL_OUT, POLL_MSG */ |
| 218 | int _fd; |
| 219 | } _sigpoll; |
| 220 | } _sifields; |
| 221 | } compat_siginfo_t; |
| 222 | |
| 223 | /* |
| 224 | * How these fields are to be accessed. |
| 225 | */ |
| 226 | #define si_pid _sifields._kill._pid |
| 227 | #define si_uid _sifields._kill._uid |
| 228 | #define si_status _sifields._sigchld._status |
| 229 | #define si_utime _sifields._sigchld._utime |
| 230 | #define si_stime _sifields._sigchld._stime |
| 231 | #define si_value _sifields._rt._sigval |
| 232 | #define si_int _sifields._rt._sigval.sival_int |
| 233 | #define si_ptr _sifields._rt._sigval.sival_ptr |
| 234 | #define si_addr _sifields._sigfault._addr |
| 235 | #define si_band _sifields._sigpoll._band |
| 236 | #define si_fd _sifields._sigpoll._fd |
| 237 | #define si_tid _sifields._timer._tid |
| 238 | #define si_overrun _sifields._timer._overrun |
| 239 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 240 | #define COMPAT_OFF_T_MAX 0x7fffffff |
| 241 | #define COMPAT_LOFF_T_MAX 0x7fffffffffffffffL |
| 242 | |
| 243 | /* |
| 244 | * A pointer passed in from user mode. This should not |
| 245 | * be used for syscall parameters, just declare them |
| 246 | * as pointers because the syscall entry code will have |
Marcin Ĺšlusarz | 8b3de0d | 2008-02-03 16:32:51 +0200 | [diff] [blame] | 247 | * appropriately converted them already. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 248 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 249 | |
| 250 | static inline void __user *compat_ptr(compat_uptr_t uptr) |
| 251 | { |
| 252 | return (void __user *)(unsigned long)(uptr & 0x7fffffffUL); |
| 253 | } |
| 254 | |
Ingo Molnar | f267fa9 | 2006-03-27 01:16:09 -0800 | [diff] [blame] | 255 | static inline compat_uptr_t ptr_to_compat(void __user *uptr) |
| 256 | { |
| 257 | return (u32)(unsigned long)uptr; |
| 258 | } |
| 259 | |
Heiko Carstens | 7757591 | 2009-06-12 10:26:25 +0200 | [diff] [blame] | 260 | #ifdef CONFIG_COMPAT |
| 261 | |
| 262 | static inline int is_compat_task(void) |
| 263 | { |
Heiko Carstens | a05c90f | 2011-01-12 09:55:29 +0100 | [diff] [blame] | 264 | return is_32bit_task(); |
Heiko Carstens | 7757591 | 2009-06-12 10:26:25 +0200 | [diff] [blame] | 265 | } |
| 266 | |
H. Peter Anvin | c41d68a | 2010-09-07 16:16:18 -0700 | [diff] [blame] | 267 | static inline void __user *arch_compat_alloc_user_space(long len) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 268 | { |
| 269 | unsigned long stack; |
| 270 | |
| 271 | stack = KSTK_ESP(current); |
Heiko Carstens | 7757591 | 2009-06-12 10:26:25 +0200 | [diff] [blame] | 272 | if (is_compat_task()) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 273 | stack &= 0x7fffffffUL; |
| 274 | return (void __user *) (stack - len); |
| 275 | } |
| 276 | |
Heiko Carstens | 0f58104 | 2013-04-20 14:25:42 +0200 | [diff] [blame] | 277 | #endif |
| 278 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 279 | struct compat_ipc64_perm { |
| 280 | compat_key_t key; |
Stephen Rothwell | 202e597 | 2005-09-06 15:16:40 -0700 | [diff] [blame] | 281 | __compat_uid32_t uid; |
| 282 | __compat_gid32_t gid; |
| 283 | __compat_uid32_t cuid; |
| 284 | __compat_gid32_t cgid; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 285 | compat_mode_t mode; |
| 286 | unsigned short __pad1; |
| 287 | unsigned short seq; |
| 288 | unsigned short __pad2; |
| 289 | unsigned int __unused1; |
| 290 | unsigned int __unused2; |
| 291 | }; |
| 292 | |
| 293 | struct compat_semid64_ds { |
| 294 | struct compat_ipc64_perm sem_perm; |
| 295 | compat_time_t sem_otime; |
| 296 | compat_ulong_t __pad1; |
| 297 | compat_time_t sem_ctime; |
| 298 | compat_ulong_t __pad2; |
| 299 | compat_ulong_t sem_nsems; |
| 300 | compat_ulong_t __unused1; |
| 301 | compat_ulong_t __unused2; |
| 302 | }; |
| 303 | |
| 304 | struct compat_msqid64_ds { |
| 305 | struct compat_ipc64_perm msg_perm; |
| 306 | compat_time_t msg_stime; |
| 307 | compat_ulong_t __pad1; |
| 308 | compat_time_t msg_rtime; |
| 309 | compat_ulong_t __pad2; |
| 310 | compat_time_t msg_ctime; |
| 311 | compat_ulong_t __pad3; |
| 312 | compat_ulong_t msg_cbytes; |
| 313 | compat_ulong_t msg_qnum; |
| 314 | compat_ulong_t msg_qbytes; |
| 315 | compat_pid_t msg_lspid; |
| 316 | compat_pid_t msg_lrpid; |
| 317 | compat_ulong_t __unused1; |
| 318 | compat_ulong_t __unused2; |
| 319 | }; |
| 320 | |
| 321 | struct compat_shmid64_ds { |
| 322 | struct compat_ipc64_perm shm_perm; |
| 323 | compat_size_t shm_segsz; |
| 324 | compat_time_t shm_atime; |
| 325 | compat_ulong_t __pad1; |
| 326 | compat_time_t shm_dtime; |
| 327 | compat_ulong_t __pad2; |
| 328 | compat_time_t shm_ctime; |
| 329 | compat_ulong_t __pad3; |
| 330 | compat_pid_t shm_cpid; |
| 331 | compat_pid_t shm_lpid; |
| 332 | compat_ulong_t shm_nattch; |
| 333 | compat_ulong_t __unused1; |
| 334 | compat_ulong_t __unused2; |
| 335 | }; |
| 336 | #endif /* _ASM_S390X_COMPAT_H */ |