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