Greg Kroah-Hartman | b244131 | 2017-11-01 15:07:57 +0100 | [diff] [blame] | 1 | /* SPDX-License-Identifier: GPL-2.0 */ |
H. Peter Anvin | 1965aae | 2008-10-22 22:26:29 -0700 | [diff] [blame] | 2 | #ifndef _ASM_X86_COMPAT_H |
| 3 | #define _ASM_X86_COMPAT_H |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4 | |
| 5 | /* |
| 6 | * Architecture specific compatibility types |
| 7 | */ |
| 8 | #include <linux/types.h> |
| 9 | #include <linux/sched.h> |
Andy Lutomirski | d375cf1 | 2017-11-02 00:59:16 -0700 | [diff] [blame] | 10 | #include <linux/sched/task_stack.h> |
H. Peter Anvin | d1a797f | 2012-02-19 10:06:34 -0800 | [diff] [blame] | 11 | #include <asm/processor.h> |
Roland McGrath | 95d1b8f | 2007-10-19 20:35:02 +0200 | [diff] [blame] | 12 | #include <asm/user32.h> |
H. Peter Anvin | fca460f | 2012-02-19 07:56:26 -0800 | [diff] [blame] | 13 | #include <asm/unistd.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 14 | |
Arnd Bergmann | fb37397 | 2018-04-18 22:01:26 +0200 | [diff] [blame] | 15 | #include <asm-generic/compat.h> |
| 16 | |
Christoph Hellwig | e28cbf2 | 2010-03-10 15:21:19 -0800 | [diff] [blame] | 17 | #define COMPAT_USER_HZ 100 |
| 18 | #define COMPAT_UTS_MACHINE "i686\0\0" |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 19 | |
Stephen Rothwell | 202e597 | 2005-09-06 15:16:40 -0700 | [diff] [blame] | 20 | typedef u16 __compat_uid_t; |
| 21 | typedef u16 __compat_gid_t; |
| 22 | typedef u32 __compat_uid32_t; |
| 23 | typedef u32 __compat_gid32_t; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 24 | typedef u16 compat_mode_t; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 25 | typedef u16 compat_dev_t; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 26 | typedef u16 compat_nlink_t; |
| 27 | typedef u16 compat_ipc_pid_t; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 28 | typedef u32 compat_caddr_t; |
| 29 | typedef __kernel_fsid_t compat_fsid_t; |
Arnd Bergmann | 4b77758 | 2007-07-15 23:41:11 -0700 | [diff] [blame] | 30 | typedef s64 __attribute__((aligned(4))) compat_s64; |
Arnd Bergmann | 4b77758 | 2007-07-15 23:41:11 -0700 | [diff] [blame] | 31 | typedef u64 __attribute__((aligned(4))) compat_u64; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 32 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 33 | struct compat_stat { |
| 34 | compat_dev_t st_dev; |
| 35 | u16 __pad1; |
| 36 | compat_ino_t st_ino; |
| 37 | compat_mode_t st_mode; |
| 38 | compat_nlink_t st_nlink; |
Stephen Rothwell | 202e597 | 2005-09-06 15:16:40 -0700 | [diff] [blame] | 39 | __compat_uid_t st_uid; |
| 40 | __compat_gid_t st_gid; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 41 | compat_dev_t st_rdev; |
| 42 | u16 __pad2; |
| 43 | u32 st_size; |
| 44 | u32 st_blksize; |
| 45 | u32 st_blocks; |
| 46 | u32 st_atime; |
| 47 | u32 st_atime_nsec; |
| 48 | u32 st_mtime; |
| 49 | u32 st_mtime_nsec; |
| 50 | u32 st_ctime; |
| 51 | u32 st_ctime_nsec; |
| 52 | u32 __unused4; |
| 53 | u32 __unused5; |
| 54 | }; |
| 55 | |
| 56 | struct compat_flock { |
| 57 | short l_type; |
| 58 | short l_whence; |
| 59 | compat_off_t l_start; |
| 60 | compat_off_t l_len; |
| 61 | compat_pid_t l_pid; |
| 62 | }; |
| 63 | |
| 64 | #define F_GETLK64 12 /* using 'struct flock64' */ |
| 65 | #define F_SETLK64 13 |
| 66 | #define F_SETLKW64 14 |
| 67 | |
| 68 | /* |
| 69 | * IA32 uses 4 byte alignment for 64 bit quantities, |
| 70 | * so we need to pack this structure. |
| 71 | */ |
| 72 | struct compat_flock64 { |
| 73 | short l_type; |
| 74 | short l_whence; |
| 75 | compat_loff_t l_start; |
| 76 | compat_loff_t l_len; |
| 77 | compat_pid_t l_pid; |
| 78 | } __attribute__((packed)); |
| 79 | |
| 80 | struct compat_statfs { |
| 81 | int f_type; |
| 82 | int f_bsize; |
| 83 | int f_blocks; |
| 84 | int f_bfree; |
| 85 | int f_bavail; |
| 86 | int f_files; |
| 87 | int f_ffree; |
| 88 | compat_fsid_t f_fsid; |
| 89 | int f_namelen; /* SunOS ignores this field. */ |
| 90 | int f_frsize; |
Eric W. Biederman | 1448c72 | 2011-10-17 13:40:02 -0700 | [diff] [blame] | 91 | int f_flags; |
| 92 | int f_spare[4]; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 93 | }; |
| 94 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 95 | #define COMPAT_RLIM_INFINITY 0xffffffff |
| 96 | |
| 97 | typedef u32 compat_old_sigset_t; /* at least 32 bits */ |
| 98 | |
| 99 | #define _COMPAT_NSIG 64 |
| 100 | #define _COMPAT_NSIG_BPW 32 |
| 101 | |
| 102 | typedef u32 compat_sigset_word; |
| 103 | |
| 104 | #define COMPAT_OFF_T_MAX 0x7fffffff |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 105 | |
| 106 | struct compat_ipc64_perm { |
| 107 | compat_key_t key; |
Stephen Rothwell | 202e597 | 2005-09-06 15:16:40 -0700 | [diff] [blame] | 108 | __compat_uid32_t uid; |
| 109 | __compat_gid32_t gid; |
| 110 | __compat_uid32_t cuid; |
| 111 | __compat_gid32_t cgid; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 112 | unsigned short mode; |
| 113 | unsigned short __pad1; |
| 114 | unsigned short seq; |
| 115 | unsigned short __pad2; |
| 116 | compat_ulong_t unused1; |
| 117 | compat_ulong_t unused2; |
| 118 | }; |
| 119 | |
| 120 | struct compat_semid64_ds { |
| 121 | struct compat_ipc64_perm sem_perm; |
Arnd Bergmann | c039dbd | 2015-05-05 23:05:19 +0200 | [diff] [blame] | 122 | compat_ulong_t sem_otime; |
| 123 | compat_ulong_t sem_otime_high; |
| 124 | compat_ulong_t sem_ctime; |
| 125 | compat_ulong_t sem_ctime_high; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 126 | compat_ulong_t sem_nsems; |
| 127 | compat_ulong_t __unused3; |
| 128 | compat_ulong_t __unused4; |
| 129 | }; |
| 130 | |
| 131 | struct compat_msqid64_ds { |
| 132 | struct compat_ipc64_perm msg_perm; |
Arnd Bergmann | c039dbd | 2015-05-05 23:05:19 +0200 | [diff] [blame] | 133 | compat_ulong_t msg_stime; |
| 134 | compat_ulong_t msg_stime_high; |
| 135 | compat_ulong_t msg_rtime; |
| 136 | compat_ulong_t msg_rtime_high; |
| 137 | compat_ulong_t msg_ctime; |
| 138 | compat_ulong_t msg_ctime_high; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 139 | compat_ulong_t msg_cbytes; |
| 140 | compat_ulong_t msg_qnum; |
| 141 | compat_ulong_t msg_qbytes; |
| 142 | compat_pid_t msg_lspid; |
| 143 | compat_pid_t msg_lrpid; |
| 144 | compat_ulong_t __unused4; |
| 145 | compat_ulong_t __unused5; |
| 146 | }; |
| 147 | |
| 148 | struct compat_shmid64_ds { |
| 149 | struct compat_ipc64_perm shm_perm; |
| 150 | compat_size_t shm_segsz; |
Arnd Bergmann | c039dbd | 2015-05-05 23:05:19 +0200 | [diff] [blame] | 151 | compat_ulong_t shm_atime; |
| 152 | compat_ulong_t shm_atime_high; |
| 153 | compat_ulong_t shm_dtime; |
| 154 | compat_ulong_t shm_dtime_high; |
| 155 | compat_ulong_t shm_ctime; |
| 156 | compat_ulong_t shm_ctime_high; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 157 | compat_pid_t shm_cpid; |
| 158 | compat_pid_t shm_lpid; |
| 159 | compat_ulong_t shm_nattch; |
| 160 | compat_ulong_t __unused4; |
| 161 | compat_ulong_t __unused5; |
| 162 | }; |
| 163 | |
| 164 | /* |
Roland McGrath | 95d1b8f | 2007-10-19 20:35:02 +0200 | [diff] [blame] | 165 | * The type of struct elf_prstatus.pr_reg in compatible core dumps. |
| 166 | */ |
H. Peter Anvin | d1a797f | 2012-02-19 10:06:34 -0800 | [diff] [blame] | 167 | typedef struct user_regs_struct compat_elf_gregset_t; |
| 168 | |
Dmitry Safonov | 90954e7 | 2016-09-05 16:33:06 +0300 | [diff] [blame] | 169 | /* Full regset -- prstatus on x32, otherwise on ia32 */ |
| 170 | #define PRSTATUS_SIZE(S, R) (R != sizeof(S.pr_reg) ? 144 : 296) |
| 171 | #define SET_PR_FPVALID(S, V, R) \ |
| 172 | do { *(int *) (((void *) &((S)->pr_reg)) + R) = (V); } \ |
H. Peter Anvin | d1a797f | 2012-02-19 10:06:34 -0800 | [diff] [blame] | 173 | while (0) |
| 174 | |
Dmitry Safonov | 7b2dd36 | 2016-11-23 21:13:30 +0300 | [diff] [blame] | 175 | #ifdef CONFIG_X86_X32_ABI |
H. Peter Anvin | d1a797f | 2012-02-19 10:06:34 -0800 | [diff] [blame] | 176 | #define COMPAT_USE_64BIT_TIME \ |
| 177 | (!!(task_pt_regs(current)->orig_ax & __X32_SYSCALL_BIT)) |
H. Peter Anvin | d1a797f | 2012-02-19 10:06:34 -0800 | [diff] [blame] | 178 | #endif |
Roland McGrath | 95d1b8f | 2007-10-19 20:35:02 +0200 | [diff] [blame] | 179 | |
H. Peter Anvin | c41d68a | 2010-09-07 16:16:18 -0700 | [diff] [blame] | 180 | static inline void __user *arch_compat_alloc_user_space(long len) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 181 | { |
H. Peter Anvin | d1a797f | 2012-02-19 10:06:34 -0800 | [diff] [blame] | 182 | compat_uptr_t sp; |
| 183 | |
| 184 | if (test_thread_flag(TIF_IA32)) { |
| 185 | sp = task_pt_regs(current)->sp; |
| 186 | } else { |
| 187 | /* -128 for the x32 ABI redzone */ |
Denys Vlasenko | 263042e | 2015-03-09 19:39:23 +0100 | [diff] [blame] | 188 | sp = task_pt_regs(current)->sp - 128; |
H. Peter Anvin | d1a797f | 2012-02-19 10:06:34 -0800 | [diff] [blame] | 189 | } |
| 190 | |
| 191 | return (void __user *)round_down(sp - len, 16); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 192 | } |
| 193 | |
Dmitry Safonov | abfb949 | 2016-04-18 16:43:43 +0300 | [diff] [blame] | 194 | static inline bool in_x32_syscall(void) |
H. Peter Anvin | a628b68 | 2012-03-05 13:39:29 -0800 | [diff] [blame] | 195 | { |
H. Peter Anvin | fca460f | 2012-02-19 07:56:26 -0800 | [diff] [blame] | 196 | #ifdef CONFIG_X86_X32_ABI |
| 197 | if (task_pt_regs(current)->orig_ax & __X32_SYSCALL_BIT) |
| 198 | return true; |
| 199 | #endif |
| 200 | return false; |
Andi Kleen | bf2fcc6 | 2006-01-11 22:44:06 +0100 | [diff] [blame] | 201 | } |
| 202 | |
Dmitry Safonov | a846446 | 2018-10-12 14:42:52 +0100 | [diff] [blame] | 203 | static inline bool in_32bit_syscall(void) |
H. Peter Anvin | a628b68 | 2012-03-05 13:39:29 -0800 | [diff] [blame] | 204 | { |
Dmitry Safonov | abfb949 | 2016-04-18 16:43:43 +0300 | [diff] [blame] | 205 | return in_ia32_syscall() || in_x32_syscall(); |
H. Peter Anvin | a628b68 | 2012-03-05 13:39:29 -0800 | [diff] [blame] | 206 | } |
Dmitry Safonov | a846446 | 2018-10-12 14:42:52 +0100 | [diff] [blame] | 207 | |
| 208 | #ifdef CONFIG_COMPAT |
| 209 | static inline bool in_compat_syscall(void) |
| 210 | { |
| 211 | return in_32bit_syscall(); |
| 212 | } |
Andy Lutomirski | f970165 | 2016-03-22 14:25:27 -0700 | [diff] [blame] | 213 | #define in_compat_syscall in_compat_syscall /* override the generic impl */ |
Dmitry Safonov | a846446 | 2018-10-12 14:42:52 +0100 | [diff] [blame] | 214 | #endif |
H. Peter Anvin | a628b68 | 2012-03-05 13:39:29 -0800 | [diff] [blame] | 215 | |
Eric W. Biederman | ea64d5a | 2018-01-15 18:03:33 -0600 | [diff] [blame] | 216 | struct compat_siginfo; |
| 217 | int __copy_siginfo_to_user32(struct compat_siginfo __user *to, |
Eric W. Biederman | ae7795b | 2018-09-25 11:27:20 +0200 | [diff] [blame] | 218 | const kernel_siginfo_t *from, bool x32_ABI); |
Eric W. Biederman | ea64d5a | 2018-01-15 18:03:33 -0600 | [diff] [blame] | 219 | |
H. Peter Anvin | 1965aae | 2008-10-22 22:26:29 -0700 | [diff] [blame] | 220 | #endif /* _ASM_X86_COMPAT_H */ |