1 /* SPDX-License-Identifier: GPL-2.0 */
2 #ifndef _ASM_X86_COMPAT_H
3 #define _ASM_X86_COMPAT_H
6 * Architecture specific compatibility types
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>
15 #include <asm-generic/compat.h>
17 #define COMPAT_USER_HZ 100
18 #define COMPAT_UTS_MACHINE "i686\0\0"
20 typedef u16 __compat_uid_t
;
21 typedef u16 __compat_gid_t
;
22 typedef u32 __compat_uid32_t
;
23 typedef u32 __compat_gid32_t
;
24 typedef u16 compat_mode_t
;
25 typedef u16 compat_dev_t
;
26 typedef u16 compat_nlink_t
;
27 typedef u16 compat_ipc_pid_t
;
28 typedef u32 compat_caddr_t
;
29 typedef __kernel_fsid_t compat_fsid_t
;
30 typedef s64
__attribute__((aligned(4))) compat_s64
;
31 typedef u64
__attribute__((aligned(4))) compat_u64
;
37 compat_mode_t st_mode
;
38 compat_nlink_t st_nlink
;
39 __compat_uid_t st_uid
;
40 __compat_gid_t st_gid
;
64 #define F_GETLK64 12 /* using 'struct flock64' */
69 * IA32 uses 4 byte alignment for 64 bit quantities,
70 * so we need to pack this structure.
72 struct compat_flock64
{
75 compat_loff_t l_start
;
78 } __attribute__((packed
));
80 struct compat_statfs
{
89 int f_namelen
; /* SunOS ignores this field. */
95 #define COMPAT_RLIM_INFINITY 0xffffffff
97 typedef u32 compat_old_sigset_t
; /* at least 32 bits */
99 #define _COMPAT_NSIG 64
100 #define _COMPAT_NSIG_BPW 32
102 typedef u32 compat_sigset_word
;
104 #define COMPAT_OFF_T_MAX 0x7fffffff
106 struct compat_ipc64_perm
{
108 __compat_uid32_t uid
;
109 __compat_gid32_t gid
;
110 __compat_uid32_t cuid
;
111 __compat_gid32_t cgid
;
113 unsigned short __pad1
;
115 unsigned short __pad2
;
116 compat_ulong_t unused1
;
117 compat_ulong_t unused2
;
120 struct compat_semid64_ds
{
121 struct compat_ipc64_perm sem_perm
;
122 compat_ulong_t sem_otime
;
123 compat_ulong_t sem_otime_high
;
124 compat_ulong_t sem_ctime
;
125 compat_ulong_t sem_ctime_high
;
126 compat_ulong_t sem_nsems
;
127 compat_ulong_t __unused3
;
128 compat_ulong_t __unused4
;
131 struct compat_msqid64_ds
{
132 struct compat_ipc64_perm msg_perm
;
133 compat_ulong_t msg_stime
;
134 compat_ulong_t msg_stime_high
;
135 compat_ulong_t msg_rtime
;
136 compat_ulong_t msg_rtime_high
;
137 compat_ulong_t msg_ctime
;
138 compat_ulong_t msg_ctime_high
;
139 compat_ulong_t msg_cbytes
;
140 compat_ulong_t msg_qnum
;
141 compat_ulong_t msg_qbytes
;
142 compat_pid_t msg_lspid
;
143 compat_pid_t msg_lrpid
;
144 compat_ulong_t __unused4
;
145 compat_ulong_t __unused5
;
148 struct compat_shmid64_ds
{
149 struct compat_ipc64_perm shm_perm
;
150 compat_size_t shm_segsz
;
151 compat_ulong_t shm_atime
;
152 compat_ulong_t shm_atime_high
;
153 compat_ulong_t shm_dtime
;
154 compat_ulong_t shm_dtime_high
;
155 compat_ulong_t shm_ctime
;
156 compat_ulong_t shm_ctime_high
;
157 compat_pid_t shm_cpid
;
158 compat_pid_t shm_lpid
;
159 compat_ulong_t shm_nattch
;
160 compat_ulong_t __unused4
;
161 compat_ulong_t __unused5
;
165 * The type of struct elf_prstatus.pr_reg in compatible core dumps.
167 typedef struct user_regs_struct compat_elf_gregset_t
;
169 /* Full regset -- prstatus on x32, otherwise on ia32 */
170 #define PRSTATUS_SIZE(S, R) (R != sizeof(S.pr_reg) ? 144 : 296)
171 #define SET_PR_FPVALID(S, V, R) \
172 do { *(int *) (((void *) &((S)->pr_reg)) + R) = (V); } \
175 #ifdef CONFIG_X86_X32_ABI
176 #define COMPAT_USE_64BIT_TIME \
177 (!!(task_pt_regs(current)->orig_ax & __X32_SYSCALL_BIT))
180 static inline void __user
*arch_compat_alloc_user_space(long len
)
184 if (test_thread_flag(TIF_IA32
)) {
185 sp
= task_pt_regs(current
)->sp
;
187 /* -128 for the x32 ABI redzone */
188 sp
= task_pt_regs(current
)->sp
- 128;
191 return (void __user
*)round_down(sp
- len
, 16);
194 static inline bool in_x32_syscall(void)
196 #ifdef CONFIG_X86_X32_ABI
197 if (task_pt_regs(current
)->orig_ax
& __X32_SYSCALL_BIT
)
203 static inline bool in_32bit_syscall(void)
205 return in_ia32_syscall() || in_x32_syscall();
209 static inline bool in_compat_syscall(void)
211 return in_32bit_syscall();
213 #define in_compat_syscall in_compat_syscall /* override the generic impl */
216 struct compat_siginfo
;
217 int __copy_siginfo_to_user32(struct compat_siginfo __user
*to
,
218 const kernel_siginfo_t
*from
, bool x32_ABI
);
220 #endif /* _ASM_X86_COMPAT_H */