xref: /linux-6.15/include/linux/compat.h (revision 3ce0f237)
1 /* SPDX-License-Identifier: GPL-2.0 */
2 #ifndef _LINUX_COMPAT_H
3 #define _LINUX_COMPAT_H
4 /*
5  * These are the type definitions for the architecture specific
6  * syscall compatibility layer.
7  */
8 
9 #include <linux/types.h>
10 #include <linux/time.h>
11 
12 #include <linux/stat.h>
13 #include <linux/param.h>	/* for HZ */
14 #include <linux/sem.h>
15 #include <linux/socket.h>
16 #include <linux/if.h>
17 #include <linux/fs.h>
18 #include <linux/aio_abi.h>	/* for aio_context_t */
19 #include <linux/uaccess.h>
20 #include <linux/unistd.h>
21 
22 #include <asm/compat.h>
23 #include <asm/siginfo.h>
24 #include <asm/signal.h>
25 
26 #ifdef CONFIG_ARCH_HAS_SYSCALL_WRAPPER
27 /*
28  * It may be useful for an architecture to override the definitions of the
29  * COMPAT_SYSCALL_DEFINE0 and COMPAT_SYSCALL_DEFINEx() macros, in particular
30  * to use a different calling convention for syscalls. To allow for that,
31  + the prototypes for the compat_sys_*() functions below will *not* be included
32  * if CONFIG_ARCH_HAS_SYSCALL_WRAPPER is enabled.
33  */
34 #include <asm/syscall_wrapper.h>
35 #endif /* CONFIG_ARCH_HAS_SYSCALL_WRAPPER */
36 
37 #ifndef COMPAT_USE_64BIT_TIME
38 #define COMPAT_USE_64BIT_TIME 0
39 #endif
40 
41 #ifndef __SC_DELOUSE
42 #define __SC_DELOUSE(t,v) ((__force t)(unsigned long)(v))
43 #endif
44 
45 #ifndef COMPAT_SYSCALL_DEFINE0
46 #define COMPAT_SYSCALL_DEFINE0(name) \
47 	asmlinkage long compat_sys_##name(void); \
48 	ALLOW_ERROR_INJECTION(compat_sys_##name, ERRNO); \
49 	asmlinkage long compat_sys_##name(void)
50 #endif /* COMPAT_SYSCALL_DEFINE0 */
51 
52 #define COMPAT_SYSCALL_DEFINE1(name, ...) \
53         COMPAT_SYSCALL_DEFINEx(1, _##name, __VA_ARGS__)
54 #define COMPAT_SYSCALL_DEFINE2(name, ...) \
55 	COMPAT_SYSCALL_DEFINEx(2, _##name, __VA_ARGS__)
56 #define COMPAT_SYSCALL_DEFINE3(name, ...) \
57 	COMPAT_SYSCALL_DEFINEx(3, _##name, __VA_ARGS__)
58 #define COMPAT_SYSCALL_DEFINE4(name, ...) \
59 	COMPAT_SYSCALL_DEFINEx(4, _##name, __VA_ARGS__)
60 #define COMPAT_SYSCALL_DEFINE5(name, ...) \
61 	COMPAT_SYSCALL_DEFINEx(5, _##name, __VA_ARGS__)
62 #define COMPAT_SYSCALL_DEFINE6(name, ...) \
63 	COMPAT_SYSCALL_DEFINEx(6, _##name, __VA_ARGS__)
64 
65 /*
66  * The asmlinkage stub is aliased to a function named __se_compat_sys_*() which
67  * sign-extends 32-bit ints to longs whenever needed. The actual work is
68  * done within __do_compat_sys_*().
69  */
70 #ifndef COMPAT_SYSCALL_DEFINEx
71 #define COMPAT_SYSCALL_DEFINEx(x, name, ...)					\
72 	__diag_push();								\
73 	__diag_ignore(GCC, 8, "-Wattribute-alias",				\
74 		      "Type aliasing is used to sanitize syscall arguments");\
75 	asmlinkage long compat_sys##name(__MAP(x,__SC_DECL,__VA_ARGS__))	\
76 		__attribute__((alias(__stringify(__se_compat_sys##name))));	\
77 	ALLOW_ERROR_INJECTION(compat_sys##name, ERRNO);				\
78 	static inline long __do_compat_sys##name(__MAP(x,__SC_DECL,__VA_ARGS__));\
79 	asmlinkage long __se_compat_sys##name(__MAP(x,__SC_LONG,__VA_ARGS__));	\
80 	asmlinkage long __se_compat_sys##name(__MAP(x,__SC_LONG,__VA_ARGS__))	\
81 	{									\
82 		long ret = __do_compat_sys##name(__MAP(x,__SC_DELOUSE,__VA_ARGS__));\
83 		__MAP(x,__SC_TEST,__VA_ARGS__);					\
84 		return ret;							\
85 	}									\
86 	__diag_pop();								\
87 	static inline long __do_compat_sys##name(__MAP(x,__SC_DECL,__VA_ARGS__))
88 #endif /* COMPAT_SYSCALL_DEFINEx */
89 
90 struct compat_iovec {
91 	compat_uptr_t	iov_base;
92 	compat_size_t	iov_len;
93 };
94 
95 #ifndef compat_user_stack_pointer
96 #define compat_user_stack_pointer() current_user_stack_pointer()
97 #endif
98 #ifndef compat_sigaltstack	/* we'll need that for MIPS */
99 typedef struct compat_sigaltstack {
100 	compat_uptr_t			ss_sp;
101 	int				ss_flags;
102 	compat_size_t			ss_size;
103 } compat_stack_t;
104 #endif
105 #ifndef COMPAT_MINSIGSTKSZ
106 #define COMPAT_MINSIGSTKSZ	MINSIGSTKSZ
107 #endif
108 
109 #define compat_jiffies_to_clock_t(x)	\
110 		(((unsigned long)(x) * COMPAT_USER_HZ) / HZ)
111 
112 typedef __compat_uid32_t	compat_uid_t;
113 typedef __compat_gid32_t	compat_gid_t;
114 
115 struct compat_sel_arg_struct;
116 struct rusage;
117 
118 struct old_itimerval32;
119 
120 struct compat_tms {
121 	compat_clock_t		tms_utime;
122 	compat_clock_t		tms_stime;
123 	compat_clock_t		tms_cutime;
124 	compat_clock_t		tms_cstime;
125 };
126 
127 #define _COMPAT_NSIG_WORDS	(_COMPAT_NSIG / _COMPAT_NSIG_BPW)
128 
129 #ifndef compat_sigset_t
130 typedef struct {
131 	compat_sigset_word	sig[_COMPAT_NSIG_WORDS];
132 } compat_sigset_t;
133 #endif
134 
135 int set_compat_user_sigmask(const compat_sigset_t __user *umask,
136 			    size_t sigsetsize);
137 
138 struct compat_sigaction {
139 #ifndef __ARCH_HAS_IRIX_SIGACTION
140 	compat_uptr_t			sa_handler;
141 	compat_ulong_t			sa_flags;
142 #else
143 	compat_uint_t			sa_flags;
144 	compat_uptr_t			sa_handler;
145 #endif
146 #ifdef __ARCH_HAS_SA_RESTORER
147 	compat_uptr_t			sa_restorer;
148 #endif
149 	compat_sigset_t			sa_mask __packed;
150 };
151 
152 typedef union compat_sigval {
153 	compat_int_t	sival_int;
154 	compat_uptr_t	sival_ptr;
155 } compat_sigval_t;
156 
157 typedef struct compat_siginfo {
158 	int si_signo;
159 #ifndef __ARCH_HAS_SWAPPED_SIGINFO
160 	int si_errno;
161 	int si_code;
162 #else
163 	int si_code;
164 	int si_errno;
165 #endif
166 
167 	union {
168 		int _pad[128/sizeof(int) - 3];
169 
170 		/* kill() */
171 		struct {
172 			compat_pid_t _pid;	/* sender's pid */
173 			__compat_uid32_t _uid;	/* sender's uid */
174 		} _kill;
175 
176 		/* POSIX.1b timers */
177 		struct {
178 			compat_timer_t _tid;	/* timer id */
179 			int _overrun;		/* overrun count */
180 			compat_sigval_t _sigval;	/* same as below */
181 		} _timer;
182 
183 		/* POSIX.1b signals */
184 		struct {
185 			compat_pid_t _pid;	/* sender's pid */
186 			__compat_uid32_t _uid;	/* sender's uid */
187 			compat_sigval_t _sigval;
188 		} _rt;
189 
190 		/* SIGCHLD */
191 		struct {
192 			compat_pid_t _pid;	/* which child */
193 			__compat_uid32_t _uid;	/* sender's uid */
194 			int _status;		/* exit code */
195 			compat_clock_t _utime;
196 			compat_clock_t _stime;
197 		} _sigchld;
198 
199 #ifdef CONFIG_X86_X32_ABI
200 		/* SIGCHLD (x32 version) */
201 		struct {
202 			compat_pid_t _pid;	/* which child */
203 			__compat_uid32_t _uid;	/* sender's uid */
204 			int _status;		/* exit code */
205 			compat_s64 _utime;
206 			compat_s64 _stime;
207 		} _sigchld_x32;
208 #endif
209 
210 		/* SIGILL, SIGFPE, SIGSEGV, SIGBUS, SIGTRAP, SIGEMT */
211 		struct {
212 			compat_uptr_t _addr;	/* faulting insn/memory ref. */
213 #define __COMPAT_ADDR_BND_PKEY_PAD  (__alignof__(compat_uptr_t) < sizeof(short) ? \
214 				     sizeof(short) : __alignof__(compat_uptr_t))
215 			union {
216 				/* used on alpha and sparc */
217 				int _trapno;	/* TRAP # which caused the signal */
218 				/*
219 				 * used when si_code=BUS_MCEERR_AR or
220 				 * used when si_code=BUS_MCEERR_AO
221 				 */
222 				short int _addr_lsb;	/* Valid LSB of the reported address. */
223 				/* used when si_code=SEGV_BNDERR */
224 				struct {
225 					char _dummy_bnd[__COMPAT_ADDR_BND_PKEY_PAD];
226 					compat_uptr_t _lower;
227 					compat_uptr_t _upper;
228 				} _addr_bnd;
229 				/* used when si_code=SEGV_PKUERR */
230 				struct {
231 					char _dummy_pkey[__COMPAT_ADDR_BND_PKEY_PAD];
232 					u32 _pkey;
233 				} _addr_pkey;
234 				/* used when si_code=TRAP_PERF */
235 				struct {
236 					compat_ulong_t _data;
237 					u32 _type;
238 				} _perf;
239 			};
240 		} _sigfault;
241 
242 		/* SIGPOLL */
243 		struct {
244 			compat_long_t _band;	/* POLL_IN, POLL_OUT, POLL_MSG */
245 			int _fd;
246 		} _sigpoll;
247 
248 		struct {
249 			compat_uptr_t _call_addr; /* calling user insn */
250 			int _syscall;	/* triggering system call number */
251 			unsigned int _arch;	/* AUDIT_ARCH_* of syscall */
252 		} _sigsys;
253 	} _sifields;
254 } compat_siginfo_t;
255 
256 struct compat_rlimit {
257 	compat_ulong_t	rlim_cur;
258 	compat_ulong_t	rlim_max;
259 };
260 
261 #ifdef __ARCH_NEED_COMPAT_FLOCK64_PACKED
262 #define __ARCH_COMPAT_FLOCK64_PACK	__attribute__((packed))
263 #else
264 #define __ARCH_COMPAT_FLOCK64_PACK
265 #endif
266 
267 struct compat_flock {
268 	short			l_type;
269 	short			l_whence;
270 	compat_off_t		l_start;
271 	compat_off_t		l_len;
272 #ifdef __ARCH_COMPAT_FLOCK_EXTRA_SYSID
273 	__ARCH_COMPAT_FLOCK_EXTRA_SYSID
274 #endif
275 	compat_pid_t		l_pid;
276 #ifdef __ARCH_COMPAT_FLOCK_PAD
277 	__ARCH_COMPAT_FLOCK_PAD
278 #endif
279 };
280 
281 struct compat_flock64 {
282 	short		l_type;
283 	short		l_whence;
284 	compat_loff_t	l_start;
285 	compat_loff_t	l_len;
286 	compat_pid_t	l_pid;
287 #ifdef __ARCH_COMPAT_FLOCK64_PAD
288 	__ARCH_COMPAT_FLOCK64_PAD
289 #endif
290 } __ARCH_COMPAT_FLOCK64_PACK;
291 
292 struct compat_rusage {
293 	struct old_timeval32 ru_utime;
294 	struct old_timeval32 ru_stime;
295 	compat_long_t	ru_maxrss;
296 	compat_long_t	ru_ixrss;
297 	compat_long_t	ru_idrss;
298 	compat_long_t	ru_isrss;
299 	compat_long_t	ru_minflt;
300 	compat_long_t	ru_majflt;
301 	compat_long_t	ru_nswap;
302 	compat_long_t	ru_inblock;
303 	compat_long_t	ru_oublock;
304 	compat_long_t	ru_msgsnd;
305 	compat_long_t	ru_msgrcv;
306 	compat_long_t	ru_nsignals;
307 	compat_long_t	ru_nvcsw;
308 	compat_long_t	ru_nivcsw;
309 };
310 
311 extern int put_compat_rusage(const struct rusage *,
312 			     struct compat_rusage __user *);
313 
314 struct compat_siginfo;
315 struct __compat_aio_sigset;
316 
317 struct compat_dirent {
318 	u32		d_ino;
319 	compat_off_t	d_off;
320 	u16		d_reclen;
321 	char		d_name[256];
322 };
323 
324 struct compat_ustat {
325 	compat_daddr_t		f_tfree;
326 	compat_ino_t		f_tinode;
327 	char			f_fname[6];
328 	char			f_fpack[6];
329 };
330 
331 #define COMPAT_SIGEV_PAD_SIZE	((SIGEV_MAX_SIZE/sizeof(int)) - 3)
332 
333 typedef struct compat_sigevent {
334 	compat_sigval_t sigev_value;
335 	compat_int_t sigev_signo;
336 	compat_int_t sigev_notify;
337 	union {
338 		compat_int_t _pad[COMPAT_SIGEV_PAD_SIZE];
339 		compat_int_t _tid;
340 
341 		struct {
342 			compat_uptr_t _function;
343 			compat_uptr_t _attribute;
344 		} _sigev_thread;
345 	} _sigev_un;
346 } compat_sigevent_t;
347 
348 struct compat_ifmap {
349 	compat_ulong_t mem_start;
350 	compat_ulong_t mem_end;
351 	unsigned short base_addr;
352 	unsigned char irq;
353 	unsigned char dma;
354 	unsigned char port;
355 };
356 
357 struct compat_if_settings {
358 	unsigned int type;	/* Type of physical device or protocol */
359 	unsigned int size;	/* Size of the data allocated by the caller */
360 	compat_uptr_t ifs_ifsu;	/* union of pointers */
361 };
362 
363 struct compat_ifreq {
364 	union {
365 		char	ifrn_name[IFNAMSIZ];    /* if name, e.g. "en0" */
366 	} ifr_ifrn;
367 	union {
368 		struct	sockaddr ifru_addr;
369 		struct	sockaddr ifru_dstaddr;
370 		struct	sockaddr ifru_broadaddr;
371 		struct	sockaddr ifru_netmask;
372 		struct	sockaddr ifru_hwaddr;
373 		short	ifru_flags;
374 		compat_int_t	ifru_ivalue;
375 		compat_int_t	ifru_mtu;
376 		struct	compat_ifmap ifru_map;
377 		char	ifru_slave[IFNAMSIZ];   /* Just fits the size */
378 		char	ifru_newname[IFNAMSIZ];
379 		compat_caddr_t	ifru_data;
380 		struct	compat_if_settings ifru_settings;
381 	} ifr_ifru;
382 };
383 
384 struct compat_ifconf {
385 	compat_int_t	ifc_len;                /* size of buffer */
386 	compat_caddr_t  ifcbuf;
387 };
388 
389 struct compat_robust_list {
390 	compat_uptr_t			next;
391 };
392 
393 struct compat_robust_list_head {
394 	struct compat_robust_list	list;
395 	compat_long_t			futex_offset;
396 	compat_uptr_t			list_op_pending;
397 };
398 
399 #ifdef CONFIG_COMPAT_OLD_SIGACTION
400 struct compat_old_sigaction {
401 	compat_uptr_t			sa_handler;
402 	compat_old_sigset_t		sa_mask;
403 	compat_ulong_t			sa_flags;
404 	compat_uptr_t			sa_restorer;
405 };
406 #endif
407 
408 struct compat_keyctl_kdf_params {
409 	compat_uptr_t hashname;
410 	compat_uptr_t otherinfo;
411 	__u32 otherinfolen;
412 	__u32 __spare[8];
413 };
414 
415 struct compat_stat;
416 struct compat_statfs;
417 struct compat_statfs64;
418 struct compat_old_linux_dirent;
419 struct compat_linux_dirent;
420 struct linux_dirent64;
421 struct compat_msghdr;
422 struct compat_mmsghdr;
423 struct compat_sysinfo;
424 struct compat_sysctl_args;
425 struct compat_kexec_segment;
426 struct compat_mq_attr;
427 struct compat_msgbuf;
428 
429 void copy_siginfo_to_external32(struct compat_siginfo *to,
430 		const struct kernel_siginfo *from);
431 int copy_siginfo_from_user32(kernel_siginfo_t *to,
432 		const struct compat_siginfo __user *from);
433 int __copy_siginfo_to_user32(struct compat_siginfo __user *to,
434 		const kernel_siginfo_t *from);
435 #ifndef copy_siginfo_to_user32
436 #define copy_siginfo_to_user32 __copy_siginfo_to_user32
437 #endif
438 int get_compat_sigevent(struct sigevent *event,
439 		const struct compat_sigevent __user *u_event);
440 
441 extern int get_compat_sigset(sigset_t *set, const compat_sigset_t __user *compat);
442 
443 /*
444  * Defined inline such that size can be compile time constant, which avoids
445  * CONFIG_HARDENED_USERCOPY complaining about copies from task_struct
446  */
447 static inline int
448 put_compat_sigset(compat_sigset_t __user *compat, const sigset_t *set,
449 		  unsigned int size)
450 {
451 	/* size <= sizeof(compat_sigset_t) <= sizeof(sigset_t) */
452 #if defined(__BIG_ENDIAN) && defined(CONFIG_64BIT)
453 	compat_sigset_t v;
454 	switch (_NSIG_WORDS) {
455 	case 4: v.sig[7] = (set->sig[3] >> 32); v.sig[6] = set->sig[3];
456 		fallthrough;
457 	case 3: v.sig[5] = (set->sig[2] >> 32); v.sig[4] = set->sig[2];
458 		fallthrough;
459 	case 2: v.sig[3] = (set->sig[1] >> 32); v.sig[2] = set->sig[1];
460 		fallthrough;
461 	case 1: v.sig[1] = (set->sig[0] >> 32); v.sig[0] = set->sig[0];
462 	}
463 	return copy_to_user(compat, &v, size) ? -EFAULT : 0;
464 #else
465 	return copy_to_user(compat, set, size) ? -EFAULT : 0;
466 #endif
467 }
468 
469 #ifdef CONFIG_CPU_BIG_ENDIAN
470 #define unsafe_put_compat_sigset(compat, set, label) do {		\
471 	compat_sigset_t __user *__c = compat;				\
472 	const sigset_t *__s = set;					\
473 									\
474 	switch (_NSIG_WORDS) {						\
475 	case 4:								\
476 		unsafe_put_user(__s->sig[3] >> 32, &__c->sig[7], label);	\
477 		unsafe_put_user(__s->sig[3], &__c->sig[6], label);	\
478 		fallthrough;						\
479 	case 3:								\
480 		unsafe_put_user(__s->sig[2] >> 32, &__c->sig[5], label);	\
481 		unsafe_put_user(__s->sig[2], &__c->sig[4], label);	\
482 		fallthrough;						\
483 	case 2:								\
484 		unsafe_put_user(__s->sig[1] >> 32, &__c->sig[3], label);	\
485 		unsafe_put_user(__s->sig[1], &__c->sig[2], label);	\
486 		fallthrough;						\
487 	case 1:								\
488 		unsafe_put_user(__s->sig[0] >> 32, &__c->sig[1], label);	\
489 		unsafe_put_user(__s->sig[0], &__c->sig[0], label);	\
490 	}								\
491 } while (0)
492 
493 #define unsafe_get_compat_sigset(set, compat, label) do {		\
494 	const compat_sigset_t __user *__c = compat;			\
495 	compat_sigset_word hi, lo;					\
496 	sigset_t *__s = set;						\
497 									\
498 	switch (_NSIG_WORDS) {						\
499 	case 4:								\
500 		unsafe_get_user(lo, &__c->sig[7], label);		\
501 		unsafe_get_user(hi, &__c->sig[6], label);		\
502 		__s->sig[3] = hi | (((long)lo) << 32);			\
503 		fallthrough;						\
504 	case 3:								\
505 		unsafe_get_user(lo, &__c->sig[5], label);		\
506 		unsafe_get_user(hi, &__c->sig[4], label);		\
507 		__s->sig[2] = hi | (((long)lo) << 32);			\
508 		fallthrough;						\
509 	case 2:								\
510 		unsafe_get_user(lo, &__c->sig[3], label);		\
511 		unsafe_get_user(hi, &__c->sig[2], label);		\
512 		__s->sig[1] = hi | (((long)lo) << 32);			\
513 		fallthrough;						\
514 	case 1:								\
515 		unsafe_get_user(lo, &__c->sig[1], label);		\
516 		unsafe_get_user(hi, &__c->sig[0], label);		\
517 		__s->sig[0] = hi | (((long)lo) << 32);			\
518 	}								\
519 } while (0)
520 #else
521 #define unsafe_put_compat_sigset(compat, set, label) do {		\
522 	compat_sigset_t __user *__c = compat;				\
523 	const sigset_t *__s = set;					\
524 									\
525 	unsafe_copy_to_user(__c, __s, sizeof(*__c), label);		\
526 } while (0)
527 
528 #define unsafe_get_compat_sigset(set, compat, label) do {		\
529 	const compat_sigset_t __user *__c = compat;			\
530 	sigset_t *__s = set;						\
531 									\
532 	unsafe_copy_from_user(__s, __c, sizeof(*__c), label);		\
533 } while (0)
534 #endif
535 
536 extern int compat_ptrace_request(struct task_struct *child,
537 				 compat_long_t request,
538 				 compat_ulong_t addr, compat_ulong_t data);
539 
540 extern long compat_arch_ptrace(struct task_struct *child, compat_long_t request,
541 			       compat_ulong_t addr, compat_ulong_t data);
542 
543 struct epoll_event;	/* fortunately, this one is fixed-layout */
544 
545 int compat_restore_altstack(const compat_stack_t __user *uss);
546 int __compat_save_altstack(compat_stack_t __user *, unsigned long);
547 #define unsafe_compat_save_altstack(uss, sp, label) do { \
548 	compat_stack_t __user *__uss = uss; \
549 	struct task_struct *t = current; \
550 	unsafe_put_user(ptr_to_compat((void __user *)t->sas_ss_sp), \
551 			&__uss->ss_sp, label); \
552 	unsafe_put_user(t->sas_ss_flags, &__uss->ss_flags, label); \
553 	unsafe_put_user(t->sas_ss_size, &__uss->ss_size, label); \
554 } while (0);
555 
556 /*
557  * These syscall function prototypes are kept in the same order as
558  * include/uapi/asm-generic/unistd.h. Deprecated or obsolete system calls
559  * go below.
560  *
561  * Please note that these prototypes here are only provided for information
562  * purposes, for static analysis, and for linking from the syscall table.
563  * These functions should not be called elsewhere from kernel code.
564  *
565  * As the syscall calling convention may be different from the default
566  * for architectures overriding the syscall calling convention, do not
567  * include the prototypes if CONFIG_ARCH_HAS_SYSCALL_WRAPPER is enabled.
568  */
569 #ifndef CONFIG_ARCH_HAS_SYSCALL_WRAPPER
570 asmlinkage long compat_sys_io_setup(unsigned nr_reqs, u32 __user *ctx32p);
571 asmlinkage long compat_sys_io_submit(compat_aio_context_t ctx_id, int nr,
572 				     u32 __user *iocb);
573 asmlinkage long compat_sys_io_pgetevents(compat_aio_context_t ctx_id,
574 					compat_long_t min_nr,
575 					compat_long_t nr,
576 					struct io_event __user *events,
577 					struct old_timespec32 __user *timeout,
578 					const struct __compat_aio_sigset __user *usig);
579 asmlinkage long compat_sys_io_pgetevents_time64(compat_aio_context_t ctx_id,
580 					compat_long_t min_nr,
581 					compat_long_t nr,
582 					struct io_event __user *events,
583 					struct __kernel_timespec __user *timeout,
584 					const struct __compat_aio_sigset __user *usig);
585 
586 /* fs/cookies.c */
587 asmlinkage long compat_sys_lookup_dcookie(u32, u32, char __user *, compat_size_t);
588 
589 /* fs/eventpoll.c */
590 asmlinkage long compat_sys_epoll_pwait(int epfd,
591 			struct epoll_event __user *events,
592 			int maxevents, int timeout,
593 			const compat_sigset_t __user *sigmask,
594 			compat_size_t sigsetsize);
595 asmlinkage long compat_sys_epoll_pwait2(int epfd,
596 			struct epoll_event __user *events,
597 			int maxevents,
598 			const struct __kernel_timespec __user *timeout,
599 			const compat_sigset_t __user *sigmask,
600 			compat_size_t sigsetsize);
601 
602 /* fs/fcntl.c */
603 asmlinkage long compat_sys_fcntl(unsigned int fd, unsigned int cmd,
604 				 compat_ulong_t arg);
605 asmlinkage long compat_sys_fcntl64(unsigned int fd, unsigned int cmd,
606 				   compat_ulong_t arg);
607 
608 /* fs/ioctl.c */
609 asmlinkage long compat_sys_ioctl(unsigned int fd, unsigned int cmd,
610 				 compat_ulong_t arg);
611 
612 /* fs/open.c */
613 asmlinkage long compat_sys_statfs(const char __user *pathname,
614 				  struct compat_statfs __user *buf);
615 asmlinkage long compat_sys_statfs64(const char __user *pathname,
616 				    compat_size_t sz,
617 				    struct compat_statfs64 __user *buf);
618 asmlinkage long compat_sys_fstatfs(unsigned int fd,
619 				   struct compat_statfs __user *buf);
620 asmlinkage long compat_sys_fstatfs64(unsigned int fd, compat_size_t sz,
621 				     struct compat_statfs64 __user *buf);
622 asmlinkage long compat_sys_truncate(const char __user *, compat_off_t);
623 asmlinkage long compat_sys_ftruncate(unsigned int, compat_ulong_t);
624 /* No generic prototype for truncate64, ftruncate64, fallocate */
625 asmlinkage long compat_sys_openat(int dfd, const char __user *filename,
626 				  int flags, umode_t mode);
627 
628 /* fs/readdir.c */
629 asmlinkage long compat_sys_getdents(unsigned int fd,
630 				    struct compat_linux_dirent __user *dirent,
631 				    unsigned int count);
632 
633 /* fs/read_write.c */
634 asmlinkage long compat_sys_lseek(unsigned int, compat_off_t, unsigned int);
635 /* No generic prototype for pread64 and pwrite64 */
636 asmlinkage ssize_t compat_sys_preadv(compat_ulong_t fd,
637 		const struct iovec __user *vec,
638 		compat_ulong_t vlen, u32 pos_low, u32 pos_high);
639 asmlinkage ssize_t compat_sys_pwritev(compat_ulong_t fd,
640 		const struct iovec __user *vec,
641 		compat_ulong_t vlen, u32 pos_low, u32 pos_high);
642 #ifdef __ARCH_WANT_COMPAT_SYS_PREADV64
643 asmlinkage long compat_sys_preadv64(unsigned long fd,
644 		const struct iovec __user *vec,
645 		unsigned long vlen, loff_t pos);
646 #endif
647 
648 #ifdef __ARCH_WANT_COMPAT_SYS_PWRITEV64
649 asmlinkage long compat_sys_pwritev64(unsigned long fd,
650 		const struct iovec __user *vec,
651 		unsigned long vlen, loff_t pos);
652 #endif
653 
654 /* fs/sendfile.c */
655 asmlinkage long compat_sys_sendfile(int out_fd, int in_fd,
656 				    compat_off_t __user *offset, compat_size_t count);
657 asmlinkage long compat_sys_sendfile64(int out_fd, int in_fd,
658 				    compat_loff_t __user *offset, compat_size_t count);
659 
660 /* fs/select.c */
661 asmlinkage long compat_sys_pselect6_time32(int n, compat_ulong_t __user *inp,
662 				    compat_ulong_t __user *outp,
663 				    compat_ulong_t __user *exp,
664 				    struct old_timespec32 __user *tsp,
665 				    void __user *sig);
666 asmlinkage long compat_sys_pselect6_time64(int n, compat_ulong_t __user *inp,
667 				    compat_ulong_t __user *outp,
668 				    compat_ulong_t __user *exp,
669 				    struct __kernel_timespec __user *tsp,
670 				    void __user *sig);
671 asmlinkage long compat_sys_ppoll_time32(struct pollfd __user *ufds,
672 				 unsigned int nfds,
673 				 struct old_timespec32 __user *tsp,
674 				 const compat_sigset_t __user *sigmask,
675 				 compat_size_t sigsetsize);
676 asmlinkage long compat_sys_ppoll_time64(struct pollfd __user *ufds,
677 				 unsigned int nfds,
678 				 struct __kernel_timespec __user *tsp,
679 				 const compat_sigset_t __user *sigmask,
680 				 compat_size_t sigsetsize);
681 
682 /* fs/signalfd.c */
683 asmlinkage long compat_sys_signalfd4(int ufd,
684 				     const compat_sigset_t __user *sigmask,
685 				     compat_size_t sigsetsize, int flags);
686 
687 /* fs/stat.c */
688 asmlinkage long compat_sys_newfstatat(unsigned int dfd,
689 				      const char __user *filename,
690 				      struct compat_stat __user *statbuf,
691 				      int flag);
692 asmlinkage long compat_sys_newfstat(unsigned int fd,
693 				    struct compat_stat __user *statbuf);
694 
695 /* fs/sync.c: No generic prototype for sync_file_range and sync_file_range2 */
696 
697 /* kernel/exit.c */
698 asmlinkage long compat_sys_waitid(int, compat_pid_t,
699 		struct compat_siginfo __user *, int,
700 		struct compat_rusage __user *);
701 
702 
703 
704 /* kernel/futex.c */
705 asmlinkage long
706 compat_sys_set_robust_list(struct compat_robust_list_head __user *head,
707 			   compat_size_t len);
708 asmlinkage long
709 compat_sys_get_robust_list(int pid, compat_uptr_t __user *head_ptr,
710 			   compat_size_t __user *len_ptr);
711 
712 /* kernel/itimer.c */
713 asmlinkage long compat_sys_getitimer(int which,
714 				     struct old_itimerval32 __user *it);
715 asmlinkage long compat_sys_setitimer(int which,
716 				     struct old_itimerval32 __user *in,
717 				     struct old_itimerval32 __user *out);
718 
719 /* kernel/kexec.c */
720 asmlinkage long compat_sys_kexec_load(compat_ulong_t entry,
721 				      compat_ulong_t nr_segments,
722 				      struct compat_kexec_segment __user *,
723 				      compat_ulong_t flags);
724 
725 /* kernel/posix-timers.c */
726 asmlinkage long compat_sys_timer_create(clockid_t which_clock,
727 			struct compat_sigevent __user *timer_event_spec,
728 			timer_t __user *created_timer_id);
729 
730 /* kernel/ptrace.c */
731 asmlinkage long compat_sys_ptrace(compat_long_t request, compat_long_t pid,
732 				  compat_long_t addr, compat_long_t data);
733 
734 /* kernel/sched/core.c */
735 asmlinkage long compat_sys_sched_setaffinity(compat_pid_t pid,
736 				     unsigned int len,
737 				     compat_ulong_t __user *user_mask_ptr);
738 asmlinkage long compat_sys_sched_getaffinity(compat_pid_t pid,
739 				     unsigned int len,
740 				     compat_ulong_t __user *user_mask_ptr);
741 
742 /* kernel/signal.c */
743 asmlinkage long compat_sys_sigaltstack(const compat_stack_t __user *uss_ptr,
744 				       compat_stack_t __user *uoss_ptr);
745 asmlinkage long compat_sys_rt_sigsuspend(compat_sigset_t __user *unewset,
746 					 compat_size_t sigsetsize);
747 #ifndef CONFIG_ODD_RT_SIGACTION
748 asmlinkage long compat_sys_rt_sigaction(int,
749 				 const struct compat_sigaction __user *,
750 				 struct compat_sigaction __user *,
751 				 compat_size_t);
752 #endif
753 asmlinkage long compat_sys_rt_sigprocmask(int how, compat_sigset_t __user *set,
754 					  compat_sigset_t __user *oset,
755 					  compat_size_t sigsetsize);
756 asmlinkage long compat_sys_rt_sigpending(compat_sigset_t __user *uset,
757 					 compat_size_t sigsetsize);
758 asmlinkage long compat_sys_rt_sigtimedwait_time32(compat_sigset_t __user *uthese,
759 		struct compat_siginfo __user *uinfo,
760 		struct old_timespec32 __user *uts, compat_size_t sigsetsize);
761 asmlinkage long compat_sys_rt_sigtimedwait_time64(compat_sigset_t __user *uthese,
762 		struct compat_siginfo __user *uinfo,
763 		struct __kernel_timespec __user *uts, compat_size_t sigsetsize);
764 asmlinkage long compat_sys_rt_sigqueueinfo(compat_pid_t pid, int sig,
765 				struct compat_siginfo __user *uinfo);
766 /* No generic prototype for rt_sigreturn */
767 
768 /* kernel/sys.c */
769 asmlinkage long compat_sys_times(struct compat_tms __user *tbuf);
770 asmlinkage long compat_sys_getrlimit(unsigned int resource,
771 				     struct compat_rlimit __user *rlim);
772 asmlinkage long compat_sys_setrlimit(unsigned int resource,
773 				     struct compat_rlimit __user *rlim);
774 asmlinkage long compat_sys_getrusage(int who, struct compat_rusage __user *ru);
775 
776 /* kernel/time.c */
777 asmlinkage long compat_sys_gettimeofday(struct old_timeval32 __user *tv,
778 		struct timezone __user *tz);
779 asmlinkage long compat_sys_settimeofday(struct old_timeval32 __user *tv,
780 		struct timezone __user *tz);
781 
782 /* kernel/timer.c */
783 asmlinkage long compat_sys_sysinfo(struct compat_sysinfo __user *info);
784 
785 /* ipc/mqueue.c */
786 asmlinkage long compat_sys_mq_open(const char __user *u_name,
787 			int oflag, compat_mode_t mode,
788 			struct compat_mq_attr __user *u_attr);
789 asmlinkage long compat_sys_mq_notify(mqd_t mqdes,
790 			const struct compat_sigevent __user *u_notification);
791 asmlinkage long compat_sys_mq_getsetattr(mqd_t mqdes,
792 			const struct compat_mq_attr __user *u_mqstat,
793 			struct compat_mq_attr __user *u_omqstat);
794 
795 /* ipc/msg.c */
796 asmlinkage long compat_sys_msgctl(int first, int second, void __user *uptr);
797 asmlinkage long compat_sys_msgrcv(int msqid, compat_uptr_t msgp,
798 		compat_ssize_t msgsz, compat_long_t msgtyp, int msgflg);
799 asmlinkage long compat_sys_msgsnd(int msqid, compat_uptr_t msgp,
800 		compat_ssize_t msgsz, int msgflg);
801 
802 /* ipc/sem.c */
803 asmlinkage long compat_sys_semctl(int semid, int semnum, int cmd, int arg);
804 
805 /* ipc/shm.c */
806 asmlinkage long compat_sys_shmctl(int first, int second, void __user *uptr);
807 asmlinkage long compat_sys_shmat(int shmid, compat_uptr_t shmaddr, int shmflg);
808 
809 /* net/socket.c */
810 asmlinkage long compat_sys_recvfrom(int fd, void __user *buf, compat_size_t len,
811 			    unsigned flags, struct sockaddr __user *addr,
812 			    int __user *addrlen);
813 asmlinkage long compat_sys_sendmsg(int fd, struct compat_msghdr __user *msg,
814 				   unsigned flags);
815 asmlinkage long compat_sys_recvmsg(int fd, struct compat_msghdr __user *msg,
816 				   unsigned int flags);
817 
818 /* mm/filemap.c: No generic prototype for readahead */
819 
820 /* security/keys/keyctl.c */
821 asmlinkage long compat_sys_keyctl(u32 option,
822 			      u32 arg2, u32 arg3, u32 arg4, u32 arg5);
823 
824 /* arch/example/kernel/sys_example.c */
825 asmlinkage long compat_sys_execve(const char __user *filename, const compat_uptr_t __user *argv,
826 		     const compat_uptr_t __user *envp);
827 
828 /* mm/fadvise.c: No generic prototype for fadvise64_64 */
829 
830 /* mm/, CONFIG_MMU only */
831 asmlinkage long compat_sys_rt_tgsigqueueinfo(compat_pid_t tgid,
832 					compat_pid_t pid, int sig,
833 					struct compat_siginfo __user *uinfo);
834 asmlinkage long compat_sys_recvmmsg_time64(int fd, struct compat_mmsghdr __user *mmsg,
835 				    unsigned vlen, unsigned int flags,
836 				    struct __kernel_timespec __user *timeout);
837 asmlinkage long compat_sys_recvmmsg_time32(int fd, struct compat_mmsghdr __user *mmsg,
838 				    unsigned vlen, unsigned int flags,
839 				    struct old_timespec32 __user *timeout);
840 asmlinkage long compat_sys_wait4(compat_pid_t pid,
841 				 compat_uint_t __user *stat_addr, int options,
842 				 struct compat_rusage __user *ru);
843 asmlinkage long compat_sys_fanotify_mark(int, unsigned int, __u32, __u32,
844 					    int, const char __user *);
845 asmlinkage long compat_sys_open_by_handle_at(int mountdirfd,
846 					     struct file_handle __user *handle,
847 					     int flags);
848 asmlinkage long compat_sys_sendmmsg(int fd, struct compat_mmsghdr __user *mmsg,
849 				    unsigned vlen, unsigned int flags);
850 asmlinkage long compat_sys_execveat(int dfd, const char __user *filename,
851 		     const compat_uptr_t __user *argv,
852 		     const compat_uptr_t __user *envp, int flags);
853 asmlinkage ssize_t compat_sys_preadv2(compat_ulong_t fd,
854 		const struct iovec __user *vec,
855 		compat_ulong_t vlen, u32 pos_low, u32 pos_high, rwf_t flags);
856 asmlinkage ssize_t compat_sys_pwritev2(compat_ulong_t fd,
857 		const struct iovec __user *vec,
858 		compat_ulong_t vlen, u32 pos_low, u32 pos_high, rwf_t flags);
859 #ifdef __ARCH_WANT_COMPAT_SYS_PREADV64V2
860 asmlinkage long  compat_sys_preadv64v2(unsigned long fd,
861 		const struct iovec __user *vec,
862 		unsigned long vlen, loff_t pos, rwf_t flags);
863 #endif
864 
865 #ifdef __ARCH_WANT_COMPAT_SYS_PWRITEV64V2
866 asmlinkage long compat_sys_pwritev64v2(unsigned long fd,
867 		const struct iovec __user *vec,
868 		unsigned long vlen, loff_t pos, rwf_t flags);
869 #endif
870 
871 
872 /*
873  * Deprecated system calls which are still defined in
874  * include/uapi/asm-generic/unistd.h and wanted by >= 1 arch
875  */
876 
877 /* __ARCH_WANT_SYSCALL_NO_AT */
878 asmlinkage long compat_sys_open(const char __user *filename, int flags,
879 				umode_t mode);
880 
881 /* __ARCH_WANT_SYSCALL_NO_FLAGS */
882 asmlinkage long compat_sys_signalfd(int ufd,
883 				    const compat_sigset_t __user *sigmask,
884 				    compat_size_t sigsetsize);
885 
886 /* __ARCH_WANT_SYSCALL_OFF_T */
887 asmlinkage long compat_sys_newstat(const char __user *filename,
888 				   struct compat_stat __user *statbuf);
889 asmlinkage long compat_sys_newlstat(const char __user *filename,
890 				    struct compat_stat __user *statbuf);
891 
892 /* __ARCH_WANT_SYSCALL_DEPRECATED */
893 asmlinkage long compat_sys_select(int n, compat_ulong_t __user *inp,
894 		compat_ulong_t __user *outp, compat_ulong_t __user *exp,
895 		struct old_timeval32 __user *tvp);
896 asmlinkage long compat_sys_ustat(unsigned dev, struct compat_ustat __user *u32);
897 asmlinkage long compat_sys_recv(int fd, void __user *buf, compat_size_t len,
898 				unsigned flags);
899 
900 /* obsolete: fs/readdir.c */
901 asmlinkage long compat_sys_old_readdir(unsigned int fd,
902 				       struct compat_old_linux_dirent __user *,
903 				       unsigned int count);
904 
905 /* obsolete: fs/select.c */
906 asmlinkage long compat_sys_old_select(struct compat_sel_arg_struct __user *arg);
907 
908 /* obsolete: ipc */
909 asmlinkage long compat_sys_ipc(u32, int, int, u32, compat_uptr_t, u32);
910 
911 /* obsolete: kernel/signal.c */
912 #ifdef __ARCH_WANT_SYS_SIGPENDING
913 asmlinkage long compat_sys_sigpending(compat_old_sigset_t __user *set);
914 #endif
915 
916 #ifdef __ARCH_WANT_SYS_SIGPROCMASK
917 asmlinkage long compat_sys_sigprocmask(int how, compat_old_sigset_t __user *nset,
918 				       compat_old_sigset_t __user *oset);
919 #endif
920 #ifdef CONFIG_COMPAT_OLD_SIGACTION
921 asmlinkage long compat_sys_sigaction(int sig,
922                                    const struct compat_old_sigaction __user *act,
923                                    struct compat_old_sigaction __user *oact);
924 #endif
925 
926 /* obsolete: net/socket.c */
927 asmlinkage long compat_sys_socketcall(int call, u32 __user *args);
928 
929 #endif /* CONFIG_ARCH_HAS_SYSCALL_WRAPPER */
930 
931 /**
932  * ns_to_old_timeval32 - Compat version of ns_to_timeval
933  * @nsec:	the nanoseconds value to be converted
934  *
935  * Returns the old_timeval32 representation of the nsec parameter.
936  */
937 static inline struct old_timeval32 ns_to_old_timeval32(s64 nsec)
938 {
939 	struct __kernel_old_timeval tv;
940 	struct old_timeval32 ctv;
941 
942 	tv = ns_to_kernel_old_timeval(nsec);
943 	ctv.tv_sec = tv.tv_sec;
944 	ctv.tv_usec = tv.tv_usec;
945 
946 	return ctv;
947 }
948 
949 /*
950  * Kernel code should not call compat syscalls (i.e., compat_sys_xyzyyz())
951  * directly.  Instead, use one of the functions which work equivalently, such
952  * as the kcompat_sys_xyzyyz() functions prototyped below.
953  */
954 
955 int kcompat_sys_statfs64(const char __user * pathname, compat_size_t sz,
956 		     struct compat_statfs64 __user * buf);
957 int kcompat_sys_fstatfs64(unsigned int fd, compat_size_t sz,
958 			  struct compat_statfs64 __user * buf);
959 
960 #ifdef CONFIG_COMPAT
961 
962 /*
963  * For most but not all architectures, "am I in a compat syscall?" and
964  * "am I a compat task?" are the same question.  For architectures on which
965  * they aren't the same question, arch code can override in_compat_syscall.
966  */
967 #ifndef in_compat_syscall
968 static inline bool in_compat_syscall(void) { return is_compat_task(); }
969 #endif
970 
971 #else /* !CONFIG_COMPAT */
972 
973 #define is_compat_task() (0)
974 /* Ensure no one redefines in_compat_syscall() under !CONFIG_COMPAT */
975 #define in_compat_syscall in_compat_syscall
976 static inline bool in_compat_syscall(void) { return false; }
977 
978 #endif /* CONFIG_COMPAT */
979 
980 #define BITS_PER_COMPAT_LONG    (8*sizeof(compat_long_t))
981 
982 #define BITS_TO_COMPAT_LONGS(bits) DIV_ROUND_UP(bits, BITS_PER_COMPAT_LONG)
983 
984 long compat_get_bitmap(unsigned long *mask, const compat_ulong_t __user *umask,
985 		       unsigned long bitmap_size);
986 long compat_put_bitmap(compat_ulong_t __user *umask, unsigned long *mask,
987 		       unsigned long bitmap_size);
988 
989 /*
990  * Some legacy ABIs like the i386 one use less than natural alignment for 64-bit
991  * types, and will need special compat treatment for that.  Most architectures
992  * don't need that special handling even for compat syscalls.
993  */
994 #ifndef compat_need_64bit_alignment_fixup
995 #define compat_need_64bit_alignment_fixup()		false
996 #endif
997 
998 /*
999  * A pointer passed in from user mode. This should not
1000  * be used for syscall parameters, just declare them
1001  * as pointers because the syscall entry code will have
1002  * appropriately converted them already.
1003  */
1004 #ifndef compat_ptr
1005 static inline void __user *compat_ptr(compat_uptr_t uptr)
1006 {
1007 	return (void __user *)(unsigned long)uptr;
1008 }
1009 #endif
1010 
1011 static inline compat_uptr_t ptr_to_compat(void __user *uptr)
1012 {
1013 	return (u32)(unsigned long)uptr;
1014 }
1015 
1016 #endif /* _LINUX_COMPAT_H */
1017