H. Peter Anvin | 1965aae | 2008-10-22 22:26:29 -0700 | [diff] [blame] | 1 | #ifndef _ASM_X86_COMPAT_H |
| 2 | #define _ASM_X86_COMPAT_H |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3 | |
| 4 | /* |
| 5 | * Architecture specific compatibility types |
| 6 | */ |
| 7 | #include <linux/types.h> |
| 8 | #include <linux/sched.h> |
H. Peter Anvin | d1a797f | 2012-02-19 10:06:34 -0800 | [diff] [blame] | 9 | #include <asm/processor.h> |
Roland McGrath | 95d1b8f | 2007-10-19 20:35:02 +0200 | [diff] [blame] | 10 | #include <asm/user32.h> |
H. Peter Anvin | fca460f | 2012-02-19 07:56:26 -0800 | [diff] [blame] | 11 | #include <asm/unistd.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 12 | |
Christoph Hellwig | e28cbf2 | 2010-03-10 15:21:19 -0800 | [diff] [blame] | 13 | #define COMPAT_USER_HZ 100 |
| 14 | #define COMPAT_UTS_MACHINE "i686\0\0" |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 15 | |
| 16 | typedef u32 compat_size_t; |
| 17 | typedef s32 compat_ssize_t; |
| 18 | typedef s32 compat_time_t; |
| 19 | typedef s32 compat_clock_t; |
| 20 | typedef s32 compat_pid_t; |
Stephen Rothwell | 202e597 | 2005-09-06 15:16:40 -0700 | [diff] [blame] | 21 | typedef u16 __compat_uid_t; |
| 22 | typedef u16 __compat_gid_t; |
| 23 | typedef u32 __compat_uid32_t; |
| 24 | typedef u32 __compat_gid32_t; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 25 | typedef u16 compat_mode_t; |
| 26 | typedef u32 compat_ino_t; |
| 27 | typedef u16 compat_dev_t; |
| 28 | typedef s32 compat_off_t; |
| 29 | typedef s64 compat_loff_t; |
| 30 | typedef u16 compat_nlink_t; |
| 31 | typedef u16 compat_ipc_pid_t; |
| 32 | typedef s32 compat_daddr_t; |
| 33 | typedef u32 compat_caddr_t; |
| 34 | typedef __kernel_fsid_t compat_fsid_t; |
| 35 | typedef s32 compat_timer_t; |
| 36 | typedef s32 compat_key_t; |
| 37 | |
| 38 | typedef s32 compat_int_t; |
| 39 | typedef s32 compat_long_t; |
Arnd Bergmann | 4b77758 | 2007-07-15 23:41:11 -0700 | [diff] [blame] | 40 | typedef s64 __attribute__((aligned(4))) compat_s64; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 41 | typedef u32 compat_uint_t; |
| 42 | typedef u32 compat_ulong_t; |
Dave Hansen | a445508 | 2016-06-08 10:25:33 -0700 | [diff] [blame] | 43 | typedef u32 compat_u32; |
Arnd Bergmann | 4b77758 | 2007-07-15 23:41:11 -0700 | [diff] [blame] | 44 | typedef u64 __attribute__((aligned(4))) compat_u64; |
Denys Vlasenko | 751f409 | 2012-10-04 17:15:31 -0700 | [diff] [blame] | 45 | typedef u32 compat_uptr_t; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 46 | |
| 47 | struct compat_timespec { |
| 48 | compat_time_t tv_sec; |
| 49 | s32 tv_nsec; |
| 50 | }; |
| 51 | |
| 52 | struct compat_timeval { |
| 53 | compat_time_t tv_sec; |
| 54 | s32 tv_usec; |
| 55 | }; |
| 56 | |
| 57 | struct compat_stat { |
| 58 | compat_dev_t st_dev; |
| 59 | u16 __pad1; |
| 60 | compat_ino_t st_ino; |
| 61 | compat_mode_t st_mode; |
| 62 | compat_nlink_t st_nlink; |
Stephen Rothwell | 202e597 | 2005-09-06 15:16:40 -0700 | [diff] [blame] | 63 | __compat_uid_t st_uid; |
| 64 | __compat_gid_t st_gid; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 65 | compat_dev_t st_rdev; |
| 66 | u16 __pad2; |
| 67 | u32 st_size; |
| 68 | u32 st_blksize; |
| 69 | u32 st_blocks; |
| 70 | u32 st_atime; |
| 71 | u32 st_atime_nsec; |
| 72 | u32 st_mtime; |
| 73 | u32 st_mtime_nsec; |
| 74 | u32 st_ctime; |
| 75 | u32 st_ctime_nsec; |
| 76 | u32 __unused4; |
| 77 | u32 __unused5; |
| 78 | }; |
| 79 | |
| 80 | struct compat_flock { |
| 81 | short l_type; |
| 82 | short l_whence; |
| 83 | compat_off_t l_start; |
| 84 | compat_off_t l_len; |
| 85 | compat_pid_t l_pid; |
| 86 | }; |
| 87 | |
| 88 | #define F_GETLK64 12 /* using 'struct flock64' */ |
| 89 | #define F_SETLK64 13 |
| 90 | #define F_SETLKW64 14 |
| 91 | |
| 92 | /* |
| 93 | * IA32 uses 4 byte alignment for 64 bit quantities, |
| 94 | * so we need to pack this structure. |
| 95 | */ |
| 96 | struct compat_flock64 { |
| 97 | short l_type; |
| 98 | short l_whence; |
| 99 | compat_loff_t l_start; |
| 100 | compat_loff_t l_len; |
| 101 | compat_pid_t l_pid; |
| 102 | } __attribute__((packed)); |
| 103 | |
| 104 | struct compat_statfs { |
| 105 | int f_type; |
| 106 | int f_bsize; |
| 107 | int f_blocks; |
| 108 | int f_bfree; |
| 109 | int f_bavail; |
| 110 | int f_files; |
| 111 | int f_ffree; |
| 112 | compat_fsid_t f_fsid; |
| 113 | int f_namelen; /* SunOS ignores this field. */ |
| 114 | int f_frsize; |
Eric W. Biederman | 1448c72 | 2011-10-17 13:40:02 -0700 | [diff] [blame] | 115 | int f_flags; |
| 116 | int f_spare[4]; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 117 | }; |
| 118 | |
| 119 | #define COMPAT_RLIM_OLD_INFINITY 0x7fffffff |
| 120 | #define COMPAT_RLIM_INFINITY 0xffffffff |
| 121 | |
| 122 | typedef u32 compat_old_sigset_t; /* at least 32 bits */ |
| 123 | |
| 124 | #define _COMPAT_NSIG 64 |
| 125 | #define _COMPAT_NSIG_BPW 32 |
| 126 | |
| 127 | typedef u32 compat_sigset_word; |
| 128 | |
Denys Vlasenko | 751f409 | 2012-10-04 17:15:31 -0700 | [diff] [blame] | 129 | typedef union compat_sigval { |
| 130 | compat_int_t sival_int; |
| 131 | compat_uptr_t sival_ptr; |
| 132 | } compat_sigval_t; |
| 133 | |
| 134 | typedef struct compat_siginfo { |
| 135 | int si_signo; |
| 136 | int si_errno; |
| 137 | int si_code; |
| 138 | |
| 139 | union { |
| 140 | int _pad[128/sizeof(int) - 3]; |
| 141 | |
| 142 | /* kill() */ |
| 143 | struct { |
| 144 | unsigned int _pid; /* sender's pid */ |
| 145 | unsigned int _uid; /* sender's uid */ |
| 146 | } _kill; |
| 147 | |
| 148 | /* POSIX.1b timers */ |
| 149 | struct { |
| 150 | compat_timer_t _tid; /* timer id */ |
| 151 | int _overrun; /* overrun count */ |
| 152 | compat_sigval_t _sigval; /* same as below */ |
| 153 | int _sys_private; /* not to be passed to user */ |
| 154 | int _overrun_incr; /* amount to add to overrun */ |
| 155 | } _timer; |
| 156 | |
| 157 | /* POSIX.1b signals */ |
| 158 | struct { |
| 159 | unsigned int _pid; /* sender's pid */ |
| 160 | unsigned int _uid; /* sender's uid */ |
| 161 | compat_sigval_t _sigval; |
| 162 | } _rt; |
| 163 | |
| 164 | /* SIGCHLD */ |
| 165 | struct { |
| 166 | unsigned int _pid; /* which child */ |
| 167 | unsigned int _uid; /* sender's uid */ |
| 168 | int _status; /* exit code */ |
| 169 | compat_clock_t _utime; |
| 170 | compat_clock_t _stime; |
| 171 | } _sigchld; |
| 172 | |
| 173 | /* SIGCHLD (x32 version) */ |
| 174 | struct { |
| 175 | unsigned int _pid; /* which child */ |
| 176 | unsigned int _uid; /* sender's uid */ |
| 177 | int _status; /* exit code */ |
| 178 | compat_s64 _utime; |
| 179 | compat_s64 _stime; |
| 180 | } _sigchld_x32; |
| 181 | |
| 182 | /* SIGILL, SIGFPE, SIGSEGV, SIGBUS */ |
| 183 | struct { |
| 184 | unsigned int _addr; /* faulting insn/memory ref. */ |
Dave Hansen | a445508 | 2016-06-08 10:25:33 -0700 | [diff] [blame] | 185 | short int _addr_lsb; /* Valid LSB of the reported address. */ |
| 186 | union { |
| 187 | /* used when si_code=SEGV_BNDERR */ |
| 188 | struct { |
| 189 | compat_uptr_t _lower; |
| 190 | compat_uptr_t _upper; |
| 191 | } _addr_bnd; |
| 192 | /* used when si_code=SEGV_PKUERR */ |
| 193 | compat_u32 _pkey; |
| 194 | }; |
Denys Vlasenko | 751f409 | 2012-10-04 17:15:31 -0700 | [diff] [blame] | 195 | } _sigfault; |
| 196 | |
| 197 | /* SIGPOLL */ |
| 198 | struct { |
| 199 | int _band; /* POLL_IN, POLL_OUT, POLL_MSG */ |
| 200 | int _fd; |
| 201 | } _sigpoll; |
| 202 | |
| 203 | struct { |
| 204 | unsigned int _call_addr; /* calling insn */ |
| 205 | int _syscall; /* triggering system call number */ |
| 206 | unsigned int _arch; /* AUDIT_ARCH_* of syscall */ |
| 207 | } _sigsys; |
| 208 | } _sifields; |
| 209 | } compat_siginfo_t; |
| 210 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 211 | #define COMPAT_OFF_T_MAX 0x7fffffff |
| 212 | #define COMPAT_LOFF_T_MAX 0x7fffffffffffffffL |
| 213 | |
| 214 | struct compat_ipc64_perm { |
| 215 | compat_key_t key; |
Stephen Rothwell | 202e597 | 2005-09-06 15:16:40 -0700 | [diff] [blame] | 216 | __compat_uid32_t uid; |
| 217 | __compat_gid32_t gid; |
| 218 | __compat_uid32_t cuid; |
| 219 | __compat_gid32_t cgid; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 220 | unsigned short mode; |
| 221 | unsigned short __pad1; |
| 222 | unsigned short seq; |
| 223 | unsigned short __pad2; |
| 224 | compat_ulong_t unused1; |
| 225 | compat_ulong_t unused2; |
| 226 | }; |
| 227 | |
| 228 | struct compat_semid64_ds { |
| 229 | struct compat_ipc64_perm sem_perm; |
| 230 | compat_time_t sem_otime; |
| 231 | compat_ulong_t __unused1; |
| 232 | compat_time_t sem_ctime; |
| 233 | compat_ulong_t __unused2; |
| 234 | compat_ulong_t sem_nsems; |
| 235 | compat_ulong_t __unused3; |
| 236 | compat_ulong_t __unused4; |
| 237 | }; |
| 238 | |
| 239 | struct compat_msqid64_ds { |
| 240 | struct compat_ipc64_perm msg_perm; |
| 241 | compat_time_t msg_stime; |
| 242 | compat_ulong_t __unused1; |
| 243 | compat_time_t msg_rtime; |
| 244 | compat_ulong_t __unused2; |
| 245 | compat_time_t msg_ctime; |
| 246 | compat_ulong_t __unused3; |
| 247 | compat_ulong_t msg_cbytes; |
| 248 | compat_ulong_t msg_qnum; |
| 249 | compat_ulong_t msg_qbytes; |
| 250 | compat_pid_t msg_lspid; |
| 251 | compat_pid_t msg_lrpid; |
| 252 | compat_ulong_t __unused4; |
| 253 | compat_ulong_t __unused5; |
| 254 | }; |
| 255 | |
| 256 | struct compat_shmid64_ds { |
| 257 | struct compat_ipc64_perm shm_perm; |
| 258 | compat_size_t shm_segsz; |
| 259 | compat_time_t shm_atime; |
| 260 | compat_ulong_t __unused1; |
| 261 | compat_time_t shm_dtime; |
| 262 | compat_ulong_t __unused2; |
| 263 | compat_time_t shm_ctime; |
| 264 | compat_ulong_t __unused3; |
| 265 | compat_pid_t shm_cpid; |
| 266 | compat_pid_t shm_lpid; |
| 267 | compat_ulong_t shm_nattch; |
| 268 | compat_ulong_t __unused4; |
| 269 | compat_ulong_t __unused5; |
| 270 | }; |
| 271 | |
| 272 | /* |
Roland McGrath | 95d1b8f | 2007-10-19 20:35:02 +0200 | [diff] [blame] | 273 | * The type of struct elf_prstatus.pr_reg in compatible core dumps. |
| 274 | */ |
H. Peter Anvin | d1a797f | 2012-02-19 10:06:34 -0800 | [diff] [blame] | 275 | typedef struct user_regs_struct compat_elf_gregset_t; |
| 276 | |
Dmitry Safonov | 90954e7 | 2016-09-05 16:33:06 +0300 | [diff] [blame] | 277 | /* Full regset -- prstatus on x32, otherwise on ia32 */ |
| 278 | #define PRSTATUS_SIZE(S, R) (R != sizeof(S.pr_reg) ? 144 : 296) |
| 279 | #define SET_PR_FPVALID(S, V, R) \ |
| 280 | do { *(int *) (((void *) &((S)->pr_reg)) + R) = (V); } \ |
H. Peter Anvin | d1a797f | 2012-02-19 10:06:34 -0800 | [diff] [blame] | 281 | while (0) |
| 282 | |
Dmitry Safonov | 7b2dd36 | 2016-11-23 21:13:30 +0300 | [diff] [blame^] | 283 | #ifdef CONFIG_X86_X32_ABI |
H. Peter Anvin | d1a797f | 2012-02-19 10:06:34 -0800 | [diff] [blame] | 284 | #define COMPAT_USE_64BIT_TIME \ |
| 285 | (!!(task_pt_regs(current)->orig_ax & __X32_SYSCALL_BIT)) |
H. Peter Anvin | d1a797f | 2012-02-19 10:06:34 -0800 | [diff] [blame] | 286 | #endif |
Roland McGrath | 95d1b8f | 2007-10-19 20:35:02 +0200 | [diff] [blame] | 287 | |
| 288 | /* |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 289 | * A pointer passed in from user mode. This should not |
| 290 | * be used for syscall parameters, just declare them |
| 291 | * as pointers because the syscall entry code will have |
Marcin Ĺšlusarz | 8b3de0d | 2008-02-03 16:32:51 +0200 | [diff] [blame] | 292 | * appropriately converted them already. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 293 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 294 | |
| 295 | static inline void __user *compat_ptr(compat_uptr_t uptr) |
| 296 | { |
| 297 | return (void __user *)(unsigned long)uptr; |
| 298 | } |
| 299 | |
| 300 | static inline compat_uptr_t ptr_to_compat(void __user *uptr) |
| 301 | { |
| 302 | return (u32)(unsigned long)uptr; |
| 303 | } |
| 304 | |
H. Peter Anvin | c41d68a | 2010-09-07 16:16:18 -0700 | [diff] [blame] | 305 | static inline void __user *arch_compat_alloc_user_space(long len) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 306 | { |
H. Peter Anvin | d1a797f | 2012-02-19 10:06:34 -0800 | [diff] [blame] | 307 | compat_uptr_t sp; |
| 308 | |
| 309 | if (test_thread_flag(TIF_IA32)) { |
| 310 | sp = task_pt_regs(current)->sp; |
| 311 | } else { |
| 312 | /* -128 for the x32 ABI redzone */ |
Denys Vlasenko | 263042e | 2015-03-09 19:39:23 +0100 | [diff] [blame] | 313 | sp = task_pt_regs(current)->sp - 128; |
H. Peter Anvin | d1a797f | 2012-02-19 10:06:34 -0800 | [diff] [blame] | 314 | } |
| 315 | |
| 316 | return (void __user *)round_down(sp - len, 16); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 317 | } |
| 318 | |
Dmitry Safonov | abfb949 | 2016-04-18 16:43:43 +0300 | [diff] [blame] | 319 | static inline bool in_x32_syscall(void) |
H. Peter Anvin | a628b68 | 2012-03-05 13:39:29 -0800 | [diff] [blame] | 320 | { |
H. Peter Anvin | fca460f | 2012-02-19 07:56:26 -0800 | [diff] [blame] | 321 | #ifdef CONFIG_X86_X32_ABI |
| 322 | if (task_pt_regs(current)->orig_ax & __X32_SYSCALL_BIT) |
| 323 | return true; |
| 324 | #endif |
| 325 | return false; |
Andi Kleen | bf2fcc6 | 2006-01-11 22:44:06 +0100 | [diff] [blame] | 326 | } |
| 327 | |
Andy Lutomirski | f970165 | 2016-03-22 14:25:27 -0700 | [diff] [blame] | 328 | static inline bool in_compat_syscall(void) |
H. Peter Anvin | a628b68 | 2012-03-05 13:39:29 -0800 | [diff] [blame] | 329 | { |
Dmitry Safonov | abfb949 | 2016-04-18 16:43:43 +0300 | [diff] [blame] | 330 | return in_ia32_syscall() || in_x32_syscall(); |
H. Peter Anvin | a628b68 | 2012-03-05 13:39:29 -0800 | [diff] [blame] | 331 | } |
Andy Lutomirski | f970165 | 2016-03-22 14:25:27 -0700 | [diff] [blame] | 332 | #define in_compat_syscall in_compat_syscall /* override the generic impl */ |
H. Peter Anvin | a628b68 | 2012-03-05 13:39:29 -0800 | [diff] [blame] | 333 | |
H. Peter Anvin | 1965aae | 2008-10-22 22:26:29 -0700 | [diff] [blame] | 334 | #endif /* _ASM_X86_COMPAT_H */ |