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