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 151a33b18bSArnd Bergmann #define compat_mode_t compat_mode_t 161a33b18bSArnd Bergmann typedef u16 compat_mode_t; 171a33b18bSArnd 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 /* 54*3ce0f237SChristoph Hellwig * IA32 uses 4 byte alignment for 64 bit quantities, so we need to pack the 55*3ce0f237SChristoph Hellwig * compat flock64 structure. 56bb898558SAl Viro */ 57*3ce0f237SChristoph Hellwig #define __ARCH_NEED_COMPAT_FLOCK64_PACKED 58bb898558SAl Viro 59bb898558SAl Viro struct compat_statfs { 60bb898558SAl Viro int f_type; 61bb898558SAl Viro int f_bsize; 62bb898558SAl Viro int f_blocks; 63bb898558SAl Viro int f_bfree; 64bb898558SAl Viro int f_bavail; 65bb898558SAl Viro int f_files; 66bb898558SAl Viro int f_ffree; 67bb898558SAl Viro compat_fsid_t f_fsid; 68bb898558SAl Viro int f_namelen; /* SunOS ignores this field. */ 69bb898558SAl Viro int f_frsize; 701448c721SEric W. Biederman int f_flags; 711448c721SEric W. Biederman int f_spare[4]; 72bb898558SAl Viro }; 73bb898558SAl Viro 74bb898558SAl Viro #define COMPAT_RLIM_INFINITY 0xffffffff 75bb898558SAl Viro 76bb898558SAl Viro #define COMPAT_OFF_T_MAX 0x7fffffff 77bb898558SAl Viro 78bb898558SAl Viro struct compat_ipc64_perm { 79bb898558SAl Viro compat_key_t key; 80bb898558SAl Viro __compat_uid32_t uid; 81bb898558SAl Viro __compat_gid32_t gid; 82bb898558SAl Viro __compat_uid32_t cuid; 83bb898558SAl Viro __compat_gid32_t cgid; 84bb898558SAl Viro unsigned short mode; 85bb898558SAl Viro unsigned short __pad1; 86bb898558SAl Viro unsigned short seq; 87bb898558SAl Viro unsigned short __pad2; 88bb898558SAl Viro compat_ulong_t unused1; 89bb898558SAl Viro compat_ulong_t unused2; 90bb898558SAl Viro }; 91bb898558SAl Viro 92bb898558SAl Viro struct compat_semid64_ds { 93bb898558SAl Viro struct compat_ipc64_perm sem_perm; 94c039dbd5SArnd Bergmann compat_ulong_t sem_otime; 95c039dbd5SArnd Bergmann compat_ulong_t sem_otime_high; 96c039dbd5SArnd Bergmann compat_ulong_t sem_ctime; 97c039dbd5SArnd Bergmann compat_ulong_t sem_ctime_high; 98bb898558SAl Viro compat_ulong_t sem_nsems; 99bb898558SAl Viro compat_ulong_t __unused3; 100bb898558SAl Viro compat_ulong_t __unused4; 101bb898558SAl Viro }; 102bb898558SAl Viro 103bb898558SAl Viro struct compat_msqid64_ds { 104bb898558SAl Viro struct compat_ipc64_perm msg_perm; 105c039dbd5SArnd Bergmann compat_ulong_t msg_stime; 106c039dbd5SArnd Bergmann compat_ulong_t msg_stime_high; 107c039dbd5SArnd Bergmann compat_ulong_t msg_rtime; 108c039dbd5SArnd Bergmann compat_ulong_t msg_rtime_high; 109c039dbd5SArnd Bergmann compat_ulong_t msg_ctime; 110c039dbd5SArnd Bergmann compat_ulong_t msg_ctime_high; 111bb898558SAl Viro compat_ulong_t msg_cbytes; 112bb898558SAl Viro compat_ulong_t msg_qnum; 113bb898558SAl Viro compat_ulong_t msg_qbytes; 114bb898558SAl Viro compat_pid_t msg_lspid; 115bb898558SAl Viro compat_pid_t msg_lrpid; 116bb898558SAl Viro compat_ulong_t __unused4; 117bb898558SAl Viro compat_ulong_t __unused5; 118bb898558SAl Viro }; 119bb898558SAl Viro 120bb898558SAl Viro struct compat_shmid64_ds { 121bb898558SAl Viro struct compat_ipc64_perm shm_perm; 122bb898558SAl Viro compat_size_t shm_segsz; 123c039dbd5SArnd Bergmann compat_ulong_t shm_atime; 124c039dbd5SArnd Bergmann compat_ulong_t shm_atime_high; 125c039dbd5SArnd Bergmann compat_ulong_t shm_dtime; 126c039dbd5SArnd Bergmann compat_ulong_t shm_dtime_high; 127c039dbd5SArnd Bergmann compat_ulong_t shm_ctime; 128c039dbd5SArnd Bergmann compat_ulong_t shm_ctime_high; 129bb898558SAl Viro compat_pid_t shm_cpid; 130bb898558SAl Viro compat_pid_t shm_lpid; 131bb898558SAl Viro compat_ulong_t shm_nattch; 132bb898558SAl Viro compat_ulong_t __unused4; 133bb898558SAl Viro compat_ulong_t __unused5; 134bb898558SAl Viro }; 135bb898558SAl Viro 1367b2dd368SDmitry Safonov #ifdef CONFIG_X86_X32_ABI 137d1a797f3SH. Peter Anvin #define COMPAT_USE_64BIT_TIME \ 138d1a797f3SH. Peter Anvin (!!(task_pt_regs(current)->orig_ax & __X32_SYSCALL_BIT)) 139d1a797f3SH. Peter Anvin #endif 140bb898558SAl Viro 141abfb9498SDmitry Safonov static inline bool in_x32_syscall(void) 142a628b684SH. Peter Anvin { 143fca460f9SH. Peter Anvin #ifdef CONFIG_X86_X32_ABI 144fca460f9SH. Peter Anvin if (task_pt_regs(current)->orig_ax & __X32_SYSCALL_BIT) 145fca460f9SH. Peter Anvin return true; 146fca460f9SH. Peter Anvin #endif 147fca460f9SH. Peter Anvin return false; 148bb898558SAl Viro } 149bb898558SAl Viro 150a846446bSDmitry Safonov static inline bool in_32bit_syscall(void) 151a628b684SH. Peter Anvin { 152abfb9498SDmitry Safonov return in_ia32_syscall() || in_x32_syscall(); 153a628b684SH. Peter Anvin } 154a846446bSDmitry Safonov 155a846446bSDmitry Safonov #ifdef CONFIG_COMPAT 156a846446bSDmitry Safonov static inline bool in_compat_syscall(void) 157a846446bSDmitry Safonov { 158a846446bSDmitry Safonov return in_32bit_syscall(); 159a846446bSDmitry Safonov } 160f970165bSAndy Lutomirski #define in_compat_syscall in_compat_syscall /* override the generic impl */ 161527c4125SChristoph Hellwig #define compat_need_64bit_alignment_fixup in_ia32_syscall 162a846446bSDmitry Safonov #endif 163a628b684SH. Peter Anvin 164ea64d5acSEric W. Biederman struct compat_siginfo; 165c3b3f524SChristoph Hellwig 166c3b3f524SChristoph Hellwig #ifdef CONFIG_X86_X32_ABI 167c3b3f524SChristoph Hellwig int copy_siginfo_to_user32(struct compat_siginfo __user *to, 168c3b3f524SChristoph Hellwig const kernel_siginfo_t *from); 169c3b3f524SChristoph Hellwig #define copy_siginfo_to_user32 copy_siginfo_to_user32 170c3b3f524SChristoph Hellwig #endif /* CONFIG_X86_X32_ABI */ 171ea64d5acSEric W. Biederman 1721965aae3SH. Peter Anvin #endif /* _ASM_X86_COMPAT_H */ 173