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