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 15*1a33b18bSArnd Bergmann #define compat_mode_t compat_mode_t 16*1a33b18bSArnd Bergmann typedef u16 compat_mode_t; 17*1a33b18bSArnd Bergmann 18fb373975SArnd Bergmann #include <asm-generic/compat.h> 19fb373975SArnd Bergmann 20bb898558SAl Viro #define COMPAT_USER_HZ 100 21e28cbf22SChristoph Hellwig #define COMPAT_UTS_MACHINE "i686\0\0" 22bb898558SAl Viro 23bb898558SAl Viro typedef u16 __compat_uid_t; 24bb898558SAl Viro typedef u16 __compat_gid_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 __kernel_fsid_t compat_fsid_t; 29bb898558SAl Viro 30bb898558SAl Viro struct compat_stat { 31bb898558SAl Viro compat_dev_t st_dev; 32bb898558SAl Viro u16 __pad1; 33bb898558SAl Viro compat_ino_t st_ino; 34bb898558SAl Viro compat_mode_t st_mode; 35bb898558SAl Viro compat_nlink_t st_nlink; 36bb898558SAl Viro __compat_uid_t st_uid; 37bb898558SAl Viro __compat_gid_t st_gid; 38bb898558SAl Viro compat_dev_t st_rdev; 39bb898558SAl Viro u16 __pad2; 40bb898558SAl Viro u32 st_size; 41bb898558SAl Viro u32 st_blksize; 42bb898558SAl Viro u32 st_blocks; 43bb898558SAl Viro u32 st_atime; 44bb898558SAl Viro u32 st_atime_nsec; 45bb898558SAl Viro u32 st_mtime; 46bb898558SAl Viro u32 st_mtime_nsec; 47bb898558SAl Viro u32 st_ctime; 48bb898558SAl Viro u32 st_ctime_nsec; 49bb898558SAl Viro u32 __unused4; 50bb898558SAl Viro u32 __unused5; 51bb898558SAl Viro }; 52bb898558SAl Viro 53bb898558SAl Viro struct compat_flock { 54bb898558SAl Viro short l_type; 55bb898558SAl Viro short l_whence; 56bb898558SAl Viro compat_off_t l_start; 57bb898558SAl Viro compat_off_t l_len; 58bb898558SAl Viro compat_pid_t l_pid; 59bb898558SAl Viro }; 60bb898558SAl Viro 61bb898558SAl Viro #define F_GETLK64 12 /* using 'struct flock64' */ 62bb898558SAl Viro #define F_SETLK64 13 63bb898558SAl Viro #define F_SETLKW64 14 64bb898558SAl Viro 65bb898558SAl Viro /* 66bb898558SAl Viro * IA32 uses 4 byte alignment for 64 bit quantities, 67bb898558SAl Viro * so we need to pack this structure. 68bb898558SAl Viro */ 69bb898558SAl Viro struct compat_flock64 { 70bb898558SAl Viro short l_type; 71bb898558SAl Viro short l_whence; 72bb898558SAl Viro compat_loff_t l_start; 73bb898558SAl Viro compat_loff_t l_len; 74bb898558SAl Viro compat_pid_t l_pid; 75bb898558SAl Viro } __attribute__((packed)); 76bb898558SAl Viro 77bb898558SAl Viro struct compat_statfs { 78bb898558SAl Viro int f_type; 79bb898558SAl Viro int f_bsize; 80bb898558SAl Viro int f_blocks; 81bb898558SAl Viro int f_bfree; 82bb898558SAl Viro int f_bavail; 83bb898558SAl Viro int f_files; 84bb898558SAl Viro int f_ffree; 85bb898558SAl Viro compat_fsid_t f_fsid; 86bb898558SAl Viro int f_namelen; /* SunOS ignores this field. */ 87bb898558SAl Viro int f_frsize; 881448c721SEric W. Biederman int f_flags; 891448c721SEric W. Biederman int f_spare[4]; 90bb898558SAl Viro }; 91bb898558SAl Viro 92bb898558SAl Viro #define COMPAT_RLIM_INFINITY 0xffffffff 93bb898558SAl Viro 94bb898558SAl Viro #define COMPAT_OFF_T_MAX 0x7fffffff 95bb898558SAl Viro 96bb898558SAl Viro struct compat_ipc64_perm { 97bb898558SAl Viro compat_key_t key; 98bb898558SAl Viro __compat_uid32_t uid; 99bb898558SAl Viro __compat_gid32_t gid; 100bb898558SAl Viro __compat_uid32_t cuid; 101bb898558SAl Viro __compat_gid32_t cgid; 102bb898558SAl Viro unsigned short mode; 103bb898558SAl Viro unsigned short __pad1; 104bb898558SAl Viro unsigned short seq; 105bb898558SAl Viro unsigned short __pad2; 106bb898558SAl Viro compat_ulong_t unused1; 107bb898558SAl Viro compat_ulong_t unused2; 108bb898558SAl Viro }; 109bb898558SAl Viro 110bb898558SAl Viro struct compat_semid64_ds { 111bb898558SAl Viro struct compat_ipc64_perm sem_perm; 112c039dbd5SArnd Bergmann compat_ulong_t sem_otime; 113c039dbd5SArnd Bergmann compat_ulong_t sem_otime_high; 114c039dbd5SArnd Bergmann compat_ulong_t sem_ctime; 115c039dbd5SArnd Bergmann compat_ulong_t sem_ctime_high; 116bb898558SAl Viro compat_ulong_t sem_nsems; 117bb898558SAl Viro compat_ulong_t __unused3; 118bb898558SAl Viro compat_ulong_t __unused4; 119bb898558SAl Viro }; 120bb898558SAl Viro 121bb898558SAl Viro struct compat_msqid64_ds { 122bb898558SAl Viro struct compat_ipc64_perm msg_perm; 123c039dbd5SArnd Bergmann compat_ulong_t msg_stime; 124c039dbd5SArnd Bergmann compat_ulong_t msg_stime_high; 125c039dbd5SArnd Bergmann compat_ulong_t msg_rtime; 126c039dbd5SArnd Bergmann compat_ulong_t msg_rtime_high; 127c039dbd5SArnd Bergmann compat_ulong_t msg_ctime; 128c039dbd5SArnd Bergmann compat_ulong_t msg_ctime_high; 129bb898558SAl Viro compat_ulong_t msg_cbytes; 130bb898558SAl Viro compat_ulong_t msg_qnum; 131bb898558SAl Viro compat_ulong_t msg_qbytes; 132bb898558SAl Viro compat_pid_t msg_lspid; 133bb898558SAl Viro compat_pid_t msg_lrpid; 134bb898558SAl Viro compat_ulong_t __unused4; 135bb898558SAl Viro compat_ulong_t __unused5; 136bb898558SAl Viro }; 137bb898558SAl Viro 138bb898558SAl Viro struct compat_shmid64_ds { 139bb898558SAl Viro struct compat_ipc64_perm shm_perm; 140bb898558SAl Viro compat_size_t shm_segsz; 141c039dbd5SArnd Bergmann compat_ulong_t shm_atime; 142c039dbd5SArnd Bergmann compat_ulong_t shm_atime_high; 143c039dbd5SArnd Bergmann compat_ulong_t shm_dtime; 144c039dbd5SArnd Bergmann compat_ulong_t shm_dtime_high; 145c039dbd5SArnd Bergmann compat_ulong_t shm_ctime; 146c039dbd5SArnd Bergmann compat_ulong_t shm_ctime_high; 147bb898558SAl Viro compat_pid_t shm_cpid; 148bb898558SAl Viro compat_pid_t shm_lpid; 149bb898558SAl Viro compat_ulong_t shm_nattch; 150bb898558SAl Viro compat_ulong_t __unused4; 151bb898558SAl Viro compat_ulong_t __unused5; 152bb898558SAl Viro }; 153bb898558SAl Viro 1547b2dd368SDmitry Safonov #ifdef CONFIG_X86_X32_ABI 155d1a797f3SH. Peter Anvin #define COMPAT_USE_64BIT_TIME \ 156d1a797f3SH. Peter Anvin (!!(task_pt_regs(current)->orig_ax & __X32_SYSCALL_BIT)) 157d1a797f3SH. Peter Anvin #endif 158bb898558SAl Viro 159c41d68a5SH. Peter Anvin static inline void __user *arch_compat_alloc_user_space(long len) 160bb898558SAl Viro { 161214f0e80SGabriel Krisman Bertazi compat_uptr_t sp = task_pt_regs(current)->sp; 162d1a797f3SH. Peter Anvin 163214f0e80SGabriel Krisman Bertazi /* 164214f0e80SGabriel Krisman Bertazi * -128 for the x32 ABI redzone. For IA32, it is not strictly 165214f0e80SGabriel Krisman Bertazi * necessary, but not harmful. 166214f0e80SGabriel Krisman Bertazi */ 167214f0e80SGabriel Krisman Bertazi sp -= 128; 168d1a797f3SH. Peter Anvin 169d1a797f3SH. Peter Anvin return (void __user *)round_down(sp - len, 16); 170bb898558SAl Viro } 171bb898558SAl Viro 172abfb9498SDmitry Safonov static inline bool in_x32_syscall(void) 173a628b684SH. Peter Anvin { 174fca460f9SH. Peter Anvin #ifdef CONFIG_X86_X32_ABI 175fca460f9SH. Peter Anvin if (task_pt_regs(current)->orig_ax & __X32_SYSCALL_BIT) 176fca460f9SH. Peter Anvin return true; 177fca460f9SH. Peter Anvin #endif 178fca460f9SH. Peter Anvin return false; 179bb898558SAl Viro } 180bb898558SAl Viro 181a846446bSDmitry Safonov static inline bool in_32bit_syscall(void) 182a628b684SH. Peter Anvin { 183abfb9498SDmitry Safonov return in_ia32_syscall() || in_x32_syscall(); 184a628b684SH. Peter Anvin } 185a846446bSDmitry Safonov 186a846446bSDmitry Safonov #ifdef CONFIG_COMPAT 187a846446bSDmitry Safonov static inline bool in_compat_syscall(void) 188a846446bSDmitry Safonov { 189a846446bSDmitry Safonov return in_32bit_syscall(); 190a846446bSDmitry Safonov } 191f970165bSAndy Lutomirski #define in_compat_syscall in_compat_syscall /* override the generic impl */ 192527c4125SChristoph Hellwig #define compat_need_64bit_alignment_fixup in_ia32_syscall 193a846446bSDmitry Safonov #endif 194a628b684SH. Peter Anvin 195ea64d5acSEric W. Biederman struct compat_siginfo; 196c3b3f524SChristoph Hellwig 197c3b3f524SChristoph Hellwig #ifdef CONFIG_X86_X32_ABI 198c3b3f524SChristoph Hellwig int copy_siginfo_to_user32(struct compat_siginfo __user *to, 199c3b3f524SChristoph Hellwig const kernel_siginfo_t *from); 200c3b3f524SChristoph Hellwig #define copy_siginfo_to_user32 copy_siginfo_to_user32 201c3b3f524SChristoph Hellwig #endif /* CONFIG_X86_X32_ABI */ 202ea64d5acSEric W. Biederman 2031965aae3SH. Peter Anvin #endif /* _ASM_X86_COMPAT_H */ 204