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 #define compat_mode_t compat_mode_t 16 typedef u16 compat_mode_t; 17 18 #include <asm-generic/compat.h> 19 20 #define COMPAT_USER_HZ 100 21 #define COMPAT_UTS_MACHINE "i686\0\0" 22 23 typedef u16 __compat_uid_t; 24 typedef u16 __compat_gid_t; 25 typedef u16 compat_dev_t; 26 typedef u16 compat_nlink_t; 27 typedef u16 compat_ipc_pid_t; 28 typedef __kernel_fsid_t compat_fsid_t; 29 30 struct compat_stat { 31 compat_dev_t st_dev; 32 u16 __pad1; 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 compat_dev_t st_rdev; 39 u16 __pad2; 40 u32 st_size; 41 u32 st_blksize; 42 u32 st_blocks; 43 u32 st_atime; 44 u32 st_atime_nsec; 45 u32 st_mtime; 46 u32 st_mtime_nsec; 47 u32 st_ctime; 48 u32 st_ctime_nsec; 49 u32 __unused4; 50 u32 __unused5; 51 }; 52 53 /* 54 * IA32 uses 4 byte alignment for 64 bit quantities, so we need to pack the 55 * compat flock64 structure. 56 */ 57 #define __ARCH_NEED_COMPAT_FLOCK64_PACKED 58 59 struct compat_statfs { 60 int f_type; 61 int f_bsize; 62 int f_blocks; 63 int f_bfree; 64 int f_bavail; 65 int f_files; 66 int f_ffree; 67 compat_fsid_t f_fsid; 68 int f_namelen; /* SunOS ignores this field. */ 69 int f_frsize; 70 int f_flags; 71 int f_spare[4]; 72 }; 73 74 #define COMPAT_RLIM_INFINITY 0xffffffff 75 76 #define COMPAT_OFF_T_MAX 0x7fffffff 77 78 struct compat_ipc64_perm { 79 compat_key_t key; 80 __compat_uid32_t uid; 81 __compat_gid32_t gid; 82 __compat_uid32_t cuid; 83 __compat_gid32_t cgid; 84 unsigned short mode; 85 unsigned short __pad1; 86 unsigned short seq; 87 unsigned short __pad2; 88 compat_ulong_t unused1; 89 compat_ulong_t unused2; 90 }; 91 92 struct compat_semid64_ds { 93 struct compat_ipc64_perm sem_perm; 94 compat_ulong_t sem_otime; 95 compat_ulong_t sem_otime_high; 96 compat_ulong_t sem_ctime; 97 compat_ulong_t sem_ctime_high; 98 compat_ulong_t sem_nsems; 99 compat_ulong_t __unused3; 100 compat_ulong_t __unused4; 101 }; 102 103 struct compat_msqid64_ds { 104 struct compat_ipc64_perm msg_perm; 105 compat_ulong_t msg_stime; 106 compat_ulong_t msg_stime_high; 107 compat_ulong_t msg_rtime; 108 compat_ulong_t msg_rtime_high; 109 compat_ulong_t msg_ctime; 110 compat_ulong_t msg_ctime_high; 111 compat_ulong_t msg_cbytes; 112 compat_ulong_t msg_qnum; 113 compat_ulong_t msg_qbytes; 114 compat_pid_t msg_lspid; 115 compat_pid_t msg_lrpid; 116 compat_ulong_t __unused4; 117 compat_ulong_t __unused5; 118 }; 119 120 struct compat_shmid64_ds { 121 struct compat_ipc64_perm shm_perm; 122 compat_size_t shm_segsz; 123 compat_ulong_t shm_atime; 124 compat_ulong_t shm_atime_high; 125 compat_ulong_t shm_dtime; 126 compat_ulong_t shm_dtime_high; 127 compat_ulong_t shm_ctime; 128 compat_ulong_t shm_ctime_high; 129 compat_pid_t shm_cpid; 130 compat_pid_t shm_lpid; 131 compat_ulong_t shm_nattch; 132 compat_ulong_t __unused4; 133 compat_ulong_t __unused5; 134 }; 135 136 #ifdef CONFIG_X86_X32_ABI 137 #define COMPAT_USE_64BIT_TIME \ 138 (!!(task_pt_regs(current)->orig_ax & __X32_SYSCALL_BIT)) 139 #endif 140 141 static inline bool in_x32_syscall(void) 142 { 143 #ifdef CONFIG_X86_X32_ABI 144 if (task_pt_regs(current)->orig_ax & __X32_SYSCALL_BIT) 145 return true; 146 #endif 147 return false; 148 } 149 150 static inline bool in_32bit_syscall(void) 151 { 152 return in_ia32_syscall() || in_x32_syscall(); 153 } 154 155 #ifdef CONFIG_COMPAT 156 static inline bool in_compat_syscall(void) 157 { 158 return in_32bit_syscall(); 159 } 160 #define in_compat_syscall in_compat_syscall /* override the generic impl */ 161 #define compat_need_64bit_alignment_fixup in_ia32_syscall 162 #endif 163 164 struct compat_siginfo; 165 166 #ifdef CONFIG_X86_X32_ABI 167 int copy_siginfo_to_user32(struct compat_siginfo __user *to, 168 const kernel_siginfo_t *from); 169 #define copy_siginfo_to_user32 copy_siginfo_to_user32 170 #endif /* CONFIG_X86_X32_ABI */ 171 172 #endif /* _ASM_X86_COMPAT_H */ 173