11965aae3SH. Peter Anvin #ifndef _ASM_X86_COMPAT_H 21965aae3SH. Peter Anvin #define _ASM_X86_COMPAT_H 3bb898558SAl Viro 4bb898558SAl Viro /* 5bb898558SAl Viro * Architecture specific compatibility types 6bb898558SAl Viro */ 7bb898558SAl Viro #include <linux/types.h> 8bb898558SAl Viro #include <linux/sched.h> 9d1a797f3SH. Peter Anvin #include <asm/processor.h> 10bb898558SAl Viro #include <asm/user32.h> 11fca460f9SH. Peter Anvin #include <asm/unistd.h> 12bb898558SAl Viro 13bb898558SAl Viro #define COMPAT_USER_HZ 100 14e28cbf22SChristoph Hellwig #define COMPAT_UTS_MACHINE "i686\0\0" 15bb898558SAl Viro 16bb898558SAl Viro typedef u32 compat_size_t; 17bb898558SAl Viro typedef s32 compat_ssize_t; 18bb898558SAl Viro typedef s32 compat_time_t; 19bb898558SAl Viro typedef s32 compat_clock_t; 20bb898558SAl Viro typedef s32 compat_pid_t; 21bb898558SAl Viro typedef u16 __compat_uid_t; 22bb898558SAl Viro typedef u16 __compat_gid_t; 23bb898558SAl Viro typedef u32 __compat_uid32_t; 24bb898558SAl Viro typedef u32 __compat_gid32_t; 25bb898558SAl Viro typedef u16 compat_mode_t; 26bb898558SAl Viro typedef u32 compat_ino_t; 27bb898558SAl Viro typedef u16 compat_dev_t; 28bb898558SAl Viro typedef s32 compat_off_t; 29bb898558SAl Viro typedef s64 compat_loff_t; 30bb898558SAl Viro typedef u16 compat_nlink_t; 31bb898558SAl Viro typedef u16 compat_ipc_pid_t; 32bb898558SAl Viro typedef s32 compat_daddr_t; 33bb898558SAl Viro typedef u32 compat_caddr_t; 34bb898558SAl Viro typedef __kernel_fsid_t compat_fsid_t; 35bb898558SAl Viro typedef s32 compat_timer_t; 36bb898558SAl Viro typedef s32 compat_key_t; 37bb898558SAl Viro 38bb898558SAl Viro typedef s32 compat_int_t; 39bb898558SAl Viro typedef s32 compat_long_t; 40bb898558SAl Viro typedef s64 __attribute__((aligned(4))) compat_s64; 41bb898558SAl Viro typedef u32 compat_uint_t; 42bb898558SAl Viro typedef u32 compat_ulong_t; 43bb898558SAl Viro typedef u64 __attribute__((aligned(4))) compat_u64; 44bb898558SAl Viro 45bb898558SAl Viro struct compat_timespec { 46bb898558SAl Viro compat_time_t tv_sec; 47bb898558SAl Viro s32 tv_nsec; 48bb898558SAl Viro }; 49bb898558SAl Viro 50bb898558SAl Viro struct compat_timeval { 51bb898558SAl Viro compat_time_t tv_sec; 52bb898558SAl Viro s32 tv_usec; 53bb898558SAl Viro }; 54bb898558SAl Viro 55bb898558SAl Viro struct compat_stat { 56bb898558SAl Viro compat_dev_t st_dev; 57bb898558SAl Viro u16 __pad1; 58bb898558SAl Viro compat_ino_t st_ino; 59bb898558SAl Viro compat_mode_t st_mode; 60bb898558SAl Viro compat_nlink_t st_nlink; 61bb898558SAl Viro __compat_uid_t st_uid; 62bb898558SAl Viro __compat_gid_t st_gid; 63bb898558SAl Viro compat_dev_t st_rdev; 64bb898558SAl Viro u16 __pad2; 65bb898558SAl Viro u32 st_size; 66bb898558SAl Viro u32 st_blksize; 67bb898558SAl Viro u32 st_blocks; 68bb898558SAl Viro u32 st_atime; 69bb898558SAl Viro u32 st_atime_nsec; 70bb898558SAl Viro u32 st_mtime; 71bb898558SAl Viro u32 st_mtime_nsec; 72bb898558SAl Viro u32 st_ctime; 73bb898558SAl Viro u32 st_ctime_nsec; 74bb898558SAl Viro u32 __unused4; 75bb898558SAl Viro u32 __unused5; 76bb898558SAl Viro }; 77bb898558SAl Viro 78bb898558SAl Viro struct compat_flock { 79bb898558SAl Viro short l_type; 80bb898558SAl Viro short l_whence; 81bb898558SAl Viro compat_off_t l_start; 82bb898558SAl Viro compat_off_t l_len; 83bb898558SAl Viro compat_pid_t l_pid; 84bb898558SAl Viro }; 85bb898558SAl Viro 86bb898558SAl Viro #define F_GETLK64 12 /* using 'struct flock64' */ 87bb898558SAl Viro #define F_SETLK64 13 88bb898558SAl Viro #define F_SETLKW64 14 89bb898558SAl Viro 90bb898558SAl Viro /* 91bb898558SAl Viro * IA32 uses 4 byte alignment for 64 bit quantities, 92bb898558SAl Viro * so we need to pack this structure. 93bb898558SAl Viro */ 94bb898558SAl Viro struct compat_flock64 { 95bb898558SAl Viro short l_type; 96bb898558SAl Viro short l_whence; 97bb898558SAl Viro compat_loff_t l_start; 98bb898558SAl Viro compat_loff_t l_len; 99bb898558SAl Viro compat_pid_t l_pid; 100bb898558SAl Viro } __attribute__((packed)); 101bb898558SAl Viro 102bb898558SAl Viro struct compat_statfs { 103bb898558SAl Viro int f_type; 104bb898558SAl Viro int f_bsize; 105bb898558SAl Viro int f_blocks; 106bb898558SAl Viro int f_bfree; 107bb898558SAl Viro int f_bavail; 108bb898558SAl Viro int f_files; 109bb898558SAl Viro int f_ffree; 110bb898558SAl Viro compat_fsid_t f_fsid; 111bb898558SAl Viro int f_namelen; /* SunOS ignores this field. */ 112bb898558SAl Viro int f_frsize; 1131448c721SEric W. Biederman int f_flags; 1141448c721SEric W. Biederman int f_spare[4]; 115bb898558SAl Viro }; 116bb898558SAl Viro 117bb898558SAl Viro #define COMPAT_RLIM_OLD_INFINITY 0x7fffffff 118bb898558SAl Viro #define COMPAT_RLIM_INFINITY 0xffffffff 119bb898558SAl Viro 120bb898558SAl Viro typedef u32 compat_old_sigset_t; /* at least 32 bits */ 121bb898558SAl Viro 122bb898558SAl Viro #define _COMPAT_NSIG 64 123bb898558SAl Viro #define _COMPAT_NSIG_BPW 32 124bb898558SAl Viro 125bb898558SAl Viro typedef u32 compat_sigset_word; 126bb898558SAl Viro 127bb898558SAl Viro #define COMPAT_OFF_T_MAX 0x7fffffff 128bb898558SAl Viro #define COMPAT_LOFF_T_MAX 0x7fffffffffffffffL 129bb898558SAl Viro 130bb898558SAl Viro struct compat_ipc64_perm { 131bb898558SAl Viro compat_key_t key; 132bb898558SAl Viro __compat_uid32_t uid; 133bb898558SAl Viro __compat_gid32_t gid; 134bb898558SAl Viro __compat_uid32_t cuid; 135bb898558SAl Viro __compat_gid32_t cgid; 136bb898558SAl Viro unsigned short mode; 137bb898558SAl Viro unsigned short __pad1; 138bb898558SAl Viro unsigned short seq; 139bb898558SAl Viro unsigned short __pad2; 140bb898558SAl Viro compat_ulong_t unused1; 141bb898558SAl Viro compat_ulong_t unused2; 142bb898558SAl Viro }; 143bb898558SAl Viro 144bb898558SAl Viro struct compat_semid64_ds { 145bb898558SAl Viro struct compat_ipc64_perm sem_perm; 146bb898558SAl Viro compat_time_t sem_otime; 147bb898558SAl Viro compat_ulong_t __unused1; 148bb898558SAl Viro compat_time_t sem_ctime; 149bb898558SAl Viro compat_ulong_t __unused2; 150bb898558SAl Viro compat_ulong_t sem_nsems; 151bb898558SAl Viro compat_ulong_t __unused3; 152bb898558SAl Viro compat_ulong_t __unused4; 153bb898558SAl Viro }; 154bb898558SAl Viro 155bb898558SAl Viro struct compat_msqid64_ds { 156bb898558SAl Viro struct compat_ipc64_perm msg_perm; 157bb898558SAl Viro compat_time_t msg_stime; 158bb898558SAl Viro compat_ulong_t __unused1; 159bb898558SAl Viro compat_time_t msg_rtime; 160bb898558SAl Viro compat_ulong_t __unused2; 161bb898558SAl Viro compat_time_t msg_ctime; 162bb898558SAl Viro compat_ulong_t __unused3; 163bb898558SAl Viro compat_ulong_t msg_cbytes; 164bb898558SAl Viro compat_ulong_t msg_qnum; 165bb898558SAl Viro compat_ulong_t msg_qbytes; 166bb898558SAl Viro compat_pid_t msg_lspid; 167bb898558SAl Viro compat_pid_t msg_lrpid; 168bb898558SAl Viro compat_ulong_t __unused4; 169bb898558SAl Viro compat_ulong_t __unused5; 170bb898558SAl Viro }; 171bb898558SAl Viro 172bb898558SAl Viro struct compat_shmid64_ds { 173bb898558SAl Viro struct compat_ipc64_perm shm_perm; 174bb898558SAl Viro compat_size_t shm_segsz; 175bb898558SAl Viro compat_time_t shm_atime; 176bb898558SAl Viro compat_ulong_t __unused1; 177bb898558SAl Viro compat_time_t shm_dtime; 178bb898558SAl Viro compat_ulong_t __unused2; 179bb898558SAl Viro compat_time_t shm_ctime; 180bb898558SAl Viro compat_ulong_t __unused3; 181bb898558SAl Viro compat_pid_t shm_cpid; 182bb898558SAl Viro compat_pid_t shm_lpid; 183bb898558SAl Viro compat_ulong_t shm_nattch; 184bb898558SAl Viro compat_ulong_t __unused4; 185bb898558SAl Viro compat_ulong_t __unused5; 186bb898558SAl Viro }; 187bb898558SAl Viro 188bb898558SAl Viro /* 189bb898558SAl Viro * The type of struct elf_prstatus.pr_reg in compatible core dumps. 190bb898558SAl Viro */ 191d1a797f3SH. Peter Anvin #ifdef CONFIG_X86_X32_ABI 192d1a797f3SH. Peter Anvin typedef struct user_regs_struct compat_elf_gregset_t; 193d1a797f3SH. Peter Anvin 194d1a797f3SH. Peter Anvin #define PR_REG_SIZE(S) (test_thread_flag(TIF_IA32) ? 68 : 216) 195d1a797f3SH. Peter Anvin #define PRSTATUS_SIZE(S) (test_thread_flag(TIF_IA32) ? 144 : 296) 196d1a797f3SH. Peter Anvin #define SET_PR_FPVALID(S,V) \ 197d1a797f3SH. Peter Anvin do { *(int *) (((void *) &((S)->pr_reg)) + PR_REG_SIZE(0)) = (V); } \ 198d1a797f3SH. Peter Anvin while (0) 199d1a797f3SH. Peter Anvin 200d1a797f3SH. Peter Anvin #define COMPAT_USE_64BIT_TIME \ 201d1a797f3SH. Peter Anvin (!!(task_pt_regs(current)->orig_ax & __X32_SYSCALL_BIT)) 202d1a797f3SH. Peter Anvin #else 203bb898558SAl Viro typedef struct user_regs_struct32 compat_elf_gregset_t; 204d1a797f3SH. Peter Anvin #endif 205bb898558SAl Viro 206bb898558SAl Viro /* 207bb898558SAl Viro * A pointer passed in from user mode. This should not 208bb898558SAl Viro * be used for syscall parameters, just declare them 209bb898558SAl Viro * as pointers because the syscall entry code will have 210bb898558SAl Viro * appropriately converted them already. 211bb898558SAl Viro */ 212bb898558SAl Viro typedef u32 compat_uptr_t; 213bb898558SAl Viro 214bb898558SAl Viro static inline void __user *compat_ptr(compat_uptr_t uptr) 215bb898558SAl Viro { 216bb898558SAl Viro return (void __user *)(unsigned long)uptr; 217bb898558SAl Viro } 218bb898558SAl Viro 219bb898558SAl Viro static inline compat_uptr_t ptr_to_compat(void __user *uptr) 220bb898558SAl Viro { 221bb898558SAl Viro return (u32)(unsigned long)uptr; 222bb898558SAl Viro } 223bb898558SAl Viro 224c41d68a5SH. Peter Anvin static inline void __user *arch_compat_alloc_user_space(long len) 225bb898558SAl Viro { 226d1a797f3SH. Peter Anvin compat_uptr_t sp; 227d1a797f3SH. Peter Anvin 228d1a797f3SH. Peter Anvin if (test_thread_flag(TIF_IA32)) { 229d1a797f3SH. Peter Anvin sp = task_pt_regs(current)->sp; 230d1a797f3SH. Peter Anvin } else { 231d1a797f3SH. Peter Anvin /* -128 for the x32 ABI redzone */ 232d1a797f3SH. Peter Anvin sp = percpu_read(old_rsp) - 128; 233d1a797f3SH. Peter Anvin } 234d1a797f3SH. Peter Anvin 235d1a797f3SH. Peter Anvin return (void __user *)round_down(sp - len, 16); 236bb898558SAl Viro } 237bb898558SAl Viro 238a628b684SH. Peter Anvin static inline bool is_ia32_task(void) 239bb898558SAl Viro { 240fca460f9SH. Peter Anvin #ifdef CONFIG_IA32_EMULATION 241fca460f9SH. Peter Anvin if (current_thread_info()->status & TS_COMPAT) 242fca460f9SH. Peter Anvin return true; 243fca460f9SH. Peter Anvin #endif 244a628b684SH. Peter Anvin return false; 245a628b684SH. Peter Anvin } 246a628b684SH. Peter Anvin 247a628b684SH. Peter Anvin static inline bool is_x32_task(void) 248a628b684SH. Peter Anvin { 249fca460f9SH. Peter Anvin #ifdef CONFIG_X86_X32_ABI 250fca460f9SH. Peter Anvin if (task_pt_regs(current)->orig_ax & __X32_SYSCALL_BIT) 251fca460f9SH. Peter Anvin return true; 252fca460f9SH. Peter Anvin #endif 253fca460f9SH. Peter Anvin return false; 254bb898558SAl Viro } 255bb898558SAl Viro 256a628b684SH. Peter Anvin static inline bool is_compat_task(void) 257a628b684SH. Peter Anvin { 258a628b684SH. Peter Anvin return is_ia32_task() || is_x32_task(); 259a628b684SH. Peter Anvin } 260a628b684SH. Peter Anvin 2611965aae3SH. Peter Anvin #endif /* _ASM_X86_COMPAT_H */ 262