1b2441318SGreg Kroah-Hartman /* SPDX-License-Identifier: GPL-2.0 */ 21965aae3SH. Peter Anvin #ifndef _ASM_X86_COMPAT_H 31965aae3SH. Peter Anvin #define _ASM_X86_COMPAT_H 4bb898558SAl Viro 5bb898558SAl Viro /* 6bb898558SAl Viro * Architecture specific compatibility types 7bb898558SAl Viro */ 8bb898558SAl Viro #include <linux/types.h> 9bb898558SAl Viro #include <linux/sched.h> 10d375cf15SAndy Lutomirski #include <linux/sched/task_stack.h> 11d1a797f3SH. Peter Anvin #include <asm/processor.h> 12bb898558SAl Viro #include <asm/user32.h> 13fca460f9SH. Peter Anvin #include <asm/unistd.h> 14bb898558SAl Viro 15fb373975SArnd Bergmann #include <asm-generic/compat.h> 16fb373975SArnd Bergmann 17bb898558SAl Viro #define COMPAT_USER_HZ 100 18e28cbf22SChristoph Hellwig #define COMPAT_UTS_MACHINE "i686\0\0" 19bb898558SAl Viro 20bb898558SAl Viro typedef u16 __compat_uid_t; 21bb898558SAl Viro typedef u16 __compat_gid_t; 22bb898558SAl Viro typedef u32 __compat_uid32_t; 23bb898558SAl Viro typedef u32 __compat_gid32_t; 24bb898558SAl Viro typedef u16 compat_mode_t; 25bb898558SAl Viro typedef u16 compat_dev_t; 26bb898558SAl Viro typedef u16 compat_nlink_t; 27bb898558SAl Viro typedef u16 compat_ipc_pid_t; 28bb898558SAl Viro typedef u32 compat_caddr_t; 29bb898558SAl Viro typedef __kernel_fsid_t compat_fsid_t; 30bb898558SAl Viro typedef s64 __attribute__((aligned(4))) compat_s64; 31bb898558SAl Viro typedef u64 __attribute__((aligned(4))) compat_u64; 32bb898558SAl Viro 33bb898558SAl Viro struct compat_stat { 34bb898558SAl Viro compat_dev_t st_dev; 35bb898558SAl Viro u16 __pad1; 36bb898558SAl Viro compat_ino_t st_ino; 37bb898558SAl Viro compat_mode_t st_mode; 38bb898558SAl Viro compat_nlink_t st_nlink; 39bb898558SAl Viro __compat_uid_t st_uid; 40bb898558SAl Viro __compat_gid_t st_gid; 41bb898558SAl Viro compat_dev_t st_rdev; 42bb898558SAl Viro u16 __pad2; 43bb898558SAl Viro u32 st_size; 44bb898558SAl Viro u32 st_blksize; 45bb898558SAl Viro u32 st_blocks; 46bb898558SAl Viro u32 st_atime; 47bb898558SAl Viro u32 st_atime_nsec; 48bb898558SAl Viro u32 st_mtime; 49bb898558SAl Viro u32 st_mtime_nsec; 50bb898558SAl Viro u32 st_ctime; 51bb898558SAl Viro u32 st_ctime_nsec; 52bb898558SAl Viro u32 __unused4; 53bb898558SAl Viro u32 __unused5; 54bb898558SAl Viro }; 55bb898558SAl Viro 56bb898558SAl Viro struct compat_flock { 57bb898558SAl Viro short l_type; 58bb898558SAl Viro short l_whence; 59bb898558SAl Viro compat_off_t l_start; 60bb898558SAl Viro compat_off_t l_len; 61bb898558SAl Viro compat_pid_t l_pid; 62bb898558SAl Viro }; 63bb898558SAl Viro 64bb898558SAl Viro #define F_GETLK64 12 /* using 'struct flock64' */ 65bb898558SAl Viro #define F_SETLK64 13 66bb898558SAl Viro #define F_SETLKW64 14 67bb898558SAl Viro 68bb898558SAl Viro /* 69bb898558SAl Viro * IA32 uses 4 byte alignment for 64 bit quantities, 70bb898558SAl Viro * so we need to pack this structure. 71bb898558SAl Viro */ 72bb898558SAl Viro struct compat_flock64 { 73bb898558SAl Viro short l_type; 74bb898558SAl Viro short l_whence; 75bb898558SAl Viro compat_loff_t l_start; 76bb898558SAl Viro compat_loff_t l_len; 77bb898558SAl Viro compat_pid_t l_pid; 78bb898558SAl Viro } __attribute__((packed)); 79bb898558SAl Viro 80bb898558SAl Viro struct compat_statfs { 81bb898558SAl Viro int f_type; 82bb898558SAl Viro int f_bsize; 83bb898558SAl Viro int f_blocks; 84bb898558SAl Viro int f_bfree; 85bb898558SAl Viro int f_bavail; 86bb898558SAl Viro int f_files; 87bb898558SAl Viro int f_ffree; 88bb898558SAl Viro compat_fsid_t f_fsid; 89bb898558SAl Viro int f_namelen; /* SunOS ignores this field. */ 90bb898558SAl Viro int f_frsize; 911448c721SEric W. Biederman int f_flags; 921448c721SEric W. Biederman int f_spare[4]; 93bb898558SAl Viro }; 94bb898558SAl Viro 95bb898558SAl Viro #define COMPAT_RLIM_INFINITY 0xffffffff 96bb898558SAl Viro 97bb898558SAl Viro typedef u32 compat_old_sigset_t; /* at least 32 bits */ 98bb898558SAl Viro 99bb898558SAl Viro #define _COMPAT_NSIG 64 100bb898558SAl Viro #define _COMPAT_NSIG_BPW 32 101bb898558SAl Viro 102bb898558SAl Viro typedef u32 compat_sigset_word; 103bb898558SAl Viro 104bb898558SAl Viro #define COMPAT_OFF_T_MAX 0x7fffffff 105bb898558SAl Viro 106bb898558SAl Viro struct compat_ipc64_perm { 107bb898558SAl Viro compat_key_t key; 108bb898558SAl Viro __compat_uid32_t uid; 109bb898558SAl Viro __compat_gid32_t gid; 110bb898558SAl Viro __compat_uid32_t cuid; 111bb898558SAl Viro __compat_gid32_t cgid; 112bb898558SAl Viro unsigned short mode; 113bb898558SAl Viro unsigned short __pad1; 114bb898558SAl Viro unsigned short seq; 115bb898558SAl Viro unsigned short __pad2; 116bb898558SAl Viro compat_ulong_t unused1; 117bb898558SAl Viro compat_ulong_t unused2; 118bb898558SAl Viro }; 119bb898558SAl Viro 120bb898558SAl Viro struct compat_semid64_ds { 121bb898558SAl Viro struct compat_ipc64_perm sem_perm; 122c039dbd5SArnd Bergmann compat_ulong_t sem_otime; 123c039dbd5SArnd Bergmann compat_ulong_t sem_otime_high; 124c039dbd5SArnd Bergmann compat_ulong_t sem_ctime; 125c039dbd5SArnd Bergmann compat_ulong_t sem_ctime_high; 126bb898558SAl Viro compat_ulong_t sem_nsems; 127bb898558SAl Viro compat_ulong_t __unused3; 128bb898558SAl Viro compat_ulong_t __unused4; 129bb898558SAl Viro }; 130bb898558SAl Viro 131bb898558SAl Viro struct compat_msqid64_ds { 132bb898558SAl Viro struct compat_ipc64_perm msg_perm; 133c039dbd5SArnd Bergmann compat_ulong_t msg_stime; 134c039dbd5SArnd Bergmann compat_ulong_t msg_stime_high; 135c039dbd5SArnd Bergmann compat_ulong_t msg_rtime; 136c039dbd5SArnd Bergmann compat_ulong_t msg_rtime_high; 137c039dbd5SArnd Bergmann compat_ulong_t msg_ctime; 138c039dbd5SArnd Bergmann compat_ulong_t msg_ctime_high; 139bb898558SAl Viro compat_ulong_t msg_cbytes; 140bb898558SAl Viro compat_ulong_t msg_qnum; 141bb898558SAl Viro compat_ulong_t msg_qbytes; 142bb898558SAl Viro compat_pid_t msg_lspid; 143bb898558SAl Viro compat_pid_t msg_lrpid; 144bb898558SAl Viro compat_ulong_t __unused4; 145bb898558SAl Viro compat_ulong_t __unused5; 146bb898558SAl Viro }; 147bb898558SAl Viro 148bb898558SAl Viro struct compat_shmid64_ds { 149bb898558SAl Viro struct compat_ipc64_perm shm_perm; 150bb898558SAl Viro compat_size_t shm_segsz; 151c039dbd5SArnd Bergmann compat_ulong_t shm_atime; 152c039dbd5SArnd Bergmann compat_ulong_t shm_atime_high; 153c039dbd5SArnd Bergmann compat_ulong_t shm_dtime; 154c039dbd5SArnd Bergmann compat_ulong_t shm_dtime_high; 155c039dbd5SArnd Bergmann compat_ulong_t shm_ctime; 156c039dbd5SArnd Bergmann compat_ulong_t shm_ctime_high; 157bb898558SAl Viro compat_pid_t shm_cpid; 158bb898558SAl Viro compat_pid_t shm_lpid; 159bb898558SAl Viro compat_ulong_t shm_nattch; 160bb898558SAl Viro compat_ulong_t __unused4; 161bb898558SAl Viro compat_ulong_t __unused5; 162bb898558SAl Viro }; 163bb898558SAl Viro 164bb898558SAl Viro /* 165bb898558SAl Viro * The type of struct elf_prstatus.pr_reg in compatible core dumps. 166bb898558SAl Viro */ 167d1a797f3SH. Peter Anvin typedef struct user_regs_struct compat_elf_gregset_t; 168d1a797f3SH. Peter Anvin 16990954e7bSDmitry Safonov /* Full regset -- prstatus on x32, otherwise on ia32 */ 17090954e7bSDmitry Safonov #define PRSTATUS_SIZE(S, R) (R != sizeof(S.pr_reg) ? 144 : 296) 17190954e7bSDmitry Safonov #define SET_PR_FPVALID(S, V, R) \ 17290954e7bSDmitry Safonov do { *(int *) (((void *) &((S)->pr_reg)) + R) = (V); } \ 173d1a797f3SH. Peter Anvin while (0) 174d1a797f3SH. Peter Anvin 1757b2dd368SDmitry Safonov #ifdef CONFIG_X86_X32_ABI 176d1a797f3SH. Peter Anvin #define COMPAT_USE_64BIT_TIME \ 177d1a797f3SH. Peter Anvin (!!(task_pt_regs(current)->orig_ax & __X32_SYSCALL_BIT)) 178d1a797f3SH. Peter Anvin #endif 179bb898558SAl Viro 180bb898558SAl Viro /* 181bb898558SAl Viro * A pointer passed in from user mode. This should not 182bb898558SAl Viro * be used for syscall parameters, just declare them 183bb898558SAl Viro * as pointers because the syscall entry code will have 184bb898558SAl Viro * appropriately converted them already. 185bb898558SAl Viro */ 186bb898558SAl Viro 187bb898558SAl Viro static inline void __user *compat_ptr(compat_uptr_t uptr) 188bb898558SAl Viro { 189bb898558SAl Viro return (void __user *)(unsigned long)uptr; 190bb898558SAl Viro } 191bb898558SAl Viro 192bb898558SAl Viro static inline compat_uptr_t ptr_to_compat(void __user *uptr) 193bb898558SAl Viro { 194bb898558SAl Viro return (u32)(unsigned long)uptr; 195bb898558SAl Viro } 196bb898558SAl Viro 197c41d68a5SH. Peter Anvin static inline void __user *arch_compat_alloc_user_space(long len) 198bb898558SAl Viro { 199d1a797f3SH. Peter Anvin compat_uptr_t sp; 200d1a797f3SH. Peter Anvin 201d1a797f3SH. Peter Anvin if (test_thread_flag(TIF_IA32)) { 202d1a797f3SH. Peter Anvin sp = task_pt_regs(current)->sp; 203d1a797f3SH. Peter Anvin } else { 204d1a797f3SH. Peter Anvin /* -128 for the x32 ABI redzone */ 205263042e4SDenys Vlasenko sp = task_pt_regs(current)->sp - 128; 206d1a797f3SH. Peter Anvin } 207d1a797f3SH. Peter Anvin 208d1a797f3SH. Peter Anvin return (void __user *)round_down(sp - len, 16); 209bb898558SAl Viro } 210bb898558SAl Viro 211abfb9498SDmitry Safonov static inline bool in_x32_syscall(void) 212a628b684SH. Peter Anvin { 213fca460f9SH. Peter Anvin #ifdef CONFIG_X86_X32_ABI 214fca460f9SH. Peter Anvin if (task_pt_regs(current)->orig_ax & __X32_SYSCALL_BIT) 215fca460f9SH. Peter Anvin return true; 216fca460f9SH. Peter Anvin #endif 217fca460f9SH. Peter Anvin return false; 218bb898558SAl Viro } 219bb898558SAl Viro 220a846446bSDmitry Safonov static inline bool in_32bit_syscall(void) 221a628b684SH. Peter Anvin { 222abfb9498SDmitry Safonov return in_ia32_syscall() || in_x32_syscall(); 223a628b684SH. Peter Anvin } 224a846446bSDmitry Safonov 225a846446bSDmitry Safonov #ifdef CONFIG_COMPAT 226a846446bSDmitry Safonov static inline bool in_compat_syscall(void) 227a846446bSDmitry Safonov { 228a846446bSDmitry Safonov return in_32bit_syscall(); 229a846446bSDmitry Safonov } 230f970165bSAndy Lutomirski #define in_compat_syscall in_compat_syscall /* override the generic impl */ 231a846446bSDmitry Safonov #endif 232a628b684SH. Peter Anvin 233ea64d5acSEric W. Biederman struct compat_siginfo; 234ea64d5acSEric W. Biederman int __copy_siginfo_to_user32(struct compat_siginfo __user *to, 235ae7795bcSEric W. Biederman const kernel_siginfo_t *from, bool x32_ABI); 236ea64d5acSEric W. Biederman 2371965aae3SH. Peter Anvin #endif /* _ASM_X86_COMPAT_H */ 238