• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 
11 #ifdef CONFIG_COMPAT
12 
13 #include <linux/stat.h>
14 #include <linux/param.h>	/* for HZ */
15 #include <linux/sem.h>
16 #include <linux/socket.h>
17 #include <linux/if.h>
18 #include <linux/fs.h>
19 #include <linux/aio_abi.h>	/* for aio_context_t */
20 #include <linux/unistd.h>
21 
22 #include <asm/compat.h>
23 #include <asm/siginfo.h>
24 #include <asm/signal.h>
25 
26 #ifndef COMPAT_USE_64BIT_TIME
27 #define COMPAT_USE_64BIT_TIME 0
28 #endif
29 
30 #ifndef __SC_DELOUSE
31 #define __SC_DELOUSE(t,v) ((__force t)(unsigned long)(v))
32 #endif
33 
34 #define COMPAT_SYSCALL_DEFINE0(name) \
35 	asmlinkage long compat_sys_##name(void)
36 
37 #define COMPAT_SYSCALL_DEFINE1(name, ...) \
38         COMPAT_SYSCALL_DEFINEx(1, _##name, __VA_ARGS__)
39 #define COMPAT_SYSCALL_DEFINE2(name, ...) \
40 	COMPAT_SYSCALL_DEFINEx(2, _##name, __VA_ARGS__)
41 #define COMPAT_SYSCALL_DEFINE3(name, ...) \
42 	COMPAT_SYSCALL_DEFINEx(3, _##name, __VA_ARGS__)
43 #define COMPAT_SYSCALL_DEFINE4(name, ...) \
44 	COMPAT_SYSCALL_DEFINEx(4, _##name, __VA_ARGS__)
45 #define COMPAT_SYSCALL_DEFINE5(name, ...) \
46 	COMPAT_SYSCALL_DEFINEx(5, _##name, __VA_ARGS__)
47 #define COMPAT_SYSCALL_DEFINE6(name, ...) \
48 	COMPAT_SYSCALL_DEFINEx(6, _##name, __VA_ARGS__)
49 
50 #define COMPAT_SYSCALL_DEFINEx(x, name, ...)				\
51 	asmlinkage long compat_sys##name(__MAP(x,__SC_DECL,__VA_ARGS__))\
52 		__attribute__((alias(__stringify(compat_SyS##name))));  \
53 	static inline long C_SYSC##name(__MAP(x,__SC_DECL,__VA_ARGS__));\
54 	asmlinkage long compat_SyS##name(__MAP(x,__SC_LONG,__VA_ARGS__));\
55 	asmlinkage long compat_SyS##name(__MAP(x,__SC_LONG,__VA_ARGS__))\
56 	{								\
57 		return C_SYSC##name(__MAP(x,__SC_DELOUSE,__VA_ARGS__));	\
58 	}								\
59 	static inline long C_SYSC##name(__MAP(x,__SC_DECL,__VA_ARGS__))
60 
61 #ifndef compat_user_stack_pointer
62 #define compat_user_stack_pointer() current_user_stack_pointer()
63 #endif
64 #ifndef compat_sigaltstack	/* we'll need that for MIPS */
65 typedef struct compat_sigaltstack {
66 	compat_uptr_t			ss_sp;
67 	int				ss_flags;
68 	compat_size_t			ss_size;
69 } compat_stack_t;
70 #endif
71 #ifndef COMPAT_MINSIGSTKSZ
72 #define COMPAT_MINSIGSTKSZ	MINSIGSTKSZ
73 #endif
74 
75 #define compat_jiffies_to_clock_t(x)	\
76 		(((unsigned long)(x) * COMPAT_USER_HZ) / HZ)
77 
78 typedef __compat_uid32_t	compat_uid_t;
79 typedef __compat_gid32_t	compat_gid_t;
80 
81 typedef	compat_ulong_t		compat_aio_context_t;
82 
83 struct compat_sel_arg_struct;
84 struct rusage;
85 
86 struct compat_itimerspec {
87 	struct compat_timespec it_interval;
88 	struct compat_timespec it_value;
89 };
90 
91 struct compat_utimbuf {
92 	compat_time_t		actime;
93 	compat_time_t		modtime;
94 };
95 
96 struct compat_itimerval {
97 	struct compat_timeval	it_interval;
98 	struct compat_timeval	it_value;
99 };
100 
101 struct itimerval;
102 int get_compat_itimerval(struct itimerval *, const struct compat_itimerval __user *);
103 int put_compat_itimerval(struct compat_itimerval __user *, const struct itimerval *);
104 
105 struct compat_tms {
106 	compat_clock_t		tms_utime;
107 	compat_clock_t		tms_stime;
108 	compat_clock_t		tms_cutime;
109 	compat_clock_t		tms_cstime;
110 };
111 
112 struct compat_timex {
113 	compat_uint_t modes;
114 	compat_long_t offset;
115 	compat_long_t freq;
116 	compat_long_t maxerror;
117 	compat_long_t esterror;
118 	compat_int_t status;
119 	compat_long_t constant;
120 	compat_long_t precision;
121 	compat_long_t tolerance;
122 	struct compat_timeval time;
123 	compat_long_t tick;
124 	compat_long_t ppsfreq;
125 	compat_long_t jitter;
126 	compat_int_t shift;
127 	compat_long_t stabil;
128 	compat_long_t jitcnt;
129 	compat_long_t calcnt;
130 	compat_long_t errcnt;
131 	compat_long_t stbcnt;
132 	compat_int_t tai;
133 
134 	compat_int_t:32; compat_int_t:32; compat_int_t:32; compat_int_t:32;
135 	compat_int_t:32; compat_int_t:32; compat_int_t:32; compat_int_t:32;
136 	compat_int_t:32; compat_int_t:32; compat_int_t:32;
137 };
138 
139 struct timex;
140 int compat_get_timex(struct timex *, const struct compat_timex __user *);
141 int compat_put_timex(struct compat_timex __user *, const struct timex *);
142 
143 #define _COMPAT_NSIG_WORDS	(_COMPAT_NSIG / _COMPAT_NSIG_BPW)
144 
145 typedef struct {
146 	compat_sigset_word	sig[_COMPAT_NSIG_WORDS];
147 } compat_sigset_t;
148 
149 struct compat_sigaction {
150 #ifndef __ARCH_HAS_IRIX_SIGACTION
151 	compat_uptr_t			sa_handler;
152 	compat_ulong_t			sa_flags;
153 #else
154 	compat_uint_t			sa_flags;
155 	compat_uptr_t			sa_handler;
156 #endif
157 #ifdef __ARCH_HAS_SA_RESTORER
158 	compat_uptr_t			sa_restorer;
159 #endif
160 	compat_sigset_t			sa_mask __packed;
161 };
162 
163 /*
164  * These functions operate on 32- or 64-bit specs depending on
165  * COMPAT_USE_64BIT_TIME, hence the void user pointer arguments.
166  */
167 extern int compat_get_timespec(struct timespec *, const void __user *);
168 extern int compat_put_timespec(const struct timespec *, void __user *);
169 extern int compat_get_timeval(struct timeval *, const void __user *);
170 extern int compat_put_timeval(const struct timeval *, void __user *);
171 extern int compat_get_timespec64(struct timespec64 *, const void __user *);
172 extern int compat_put_timespec64(const struct timespec64 *, void __user *);
173 extern int get_compat_itimerspec64(struct itimerspec64 *its,
174 			const struct compat_itimerspec __user *uits);
175 extern int put_compat_itimerspec64(const struct itimerspec64 *its,
176 			struct compat_itimerspec __user *uits);
177 
178 struct compat_iovec {
179 	compat_uptr_t	iov_base;
180 	compat_size_t	iov_len;
181 };
182 
183 struct compat_rlimit {
184 	compat_ulong_t	rlim_cur;
185 	compat_ulong_t	rlim_max;
186 };
187 
188 struct compat_rusage {
189 	struct compat_timeval ru_utime;
190 	struct compat_timeval ru_stime;
191 	compat_long_t	ru_maxrss;
192 	compat_long_t	ru_ixrss;
193 	compat_long_t	ru_idrss;
194 	compat_long_t	ru_isrss;
195 	compat_long_t	ru_minflt;
196 	compat_long_t	ru_majflt;
197 	compat_long_t	ru_nswap;
198 	compat_long_t	ru_inblock;
199 	compat_long_t	ru_oublock;
200 	compat_long_t	ru_msgsnd;
201 	compat_long_t	ru_msgrcv;
202 	compat_long_t	ru_nsignals;
203 	compat_long_t	ru_nvcsw;
204 	compat_long_t	ru_nivcsw;
205 };
206 
207 extern int put_compat_rusage(const struct rusage *,
208 			     struct compat_rusage __user *);
209 
210 struct compat_siginfo;
211 
212 extern asmlinkage long compat_sys_waitid(int, compat_pid_t,
213 		struct compat_siginfo __user *, int,
214 		struct compat_rusage __user *);
215 
216 struct compat_dirent {
217 	u32		d_ino;
218 	compat_off_t	d_off;
219 	u16		d_reclen;
220 	char		d_name[256];
221 };
222 
223 struct compat_ustat {
224 	compat_daddr_t		f_tfree;
225 	compat_ino_t		f_tinode;
226 	char			f_fname[6];
227 	char			f_fpack[6];
228 };
229 
230 #define COMPAT_SIGEV_PAD_SIZE	((SIGEV_MAX_SIZE/sizeof(int)) - 3)
231 
232 typedef struct compat_sigevent {
233 	compat_sigval_t sigev_value;
234 	compat_int_t sigev_signo;
235 	compat_int_t sigev_notify;
236 	union {
237 		compat_int_t _pad[COMPAT_SIGEV_PAD_SIZE];
238 		compat_int_t _tid;
239 
240 		struct {
241 			compat_uptr_t _function;
242 			compat_uptr_t _attribute;
243 		} _sigev_thread;
244 	} _sigev_un;
245 } compat_sigevent_t;
246 
247 struct compat_ifmap {
248 	compat_ulong_t mem_start;
249 	compat_ulong_t mem_end;
250 	unsigned short base_addr;
251 	unsigned char irq;
252 	unsigned char dma;
253 	unsigned char port;
254 };
255 
256 struct compat_if_settings {
257 	unsigned int type;	/* Type of physical device or protocol */
258 	unsigned int size;	/* Size of the data allocated by the caller */
259 	compat_uptr_t ifs_ifsu;	/* union of pointers */
260 };
261 
262 struct compat_ifreq {
263 	union {
264 		char	ifrn_name[IFNAMSIZ];    /* if name, e.g. "en0" */
265 	} ifr_ifrn;
266 	union {
267 		struct	sockaddr ifru_addr;
268 		struct	sockaddr ifru_dstaddr;
269 		struct	sockaddr ifru_broadaddr;
270 		struct	sockaddr ifru_netmask;
271 		struct	sockaddr ifru_hwaddr;
272 		short	ifru_flags;
273 		compat_int_t	ifru_ivalue;
274 		compat_int_t	ifru_mtu;
275 		struct	compat_ifmap ifru_map;
276 		char	ifru_slave[IFNAMSIZ];   /* Just fits the size */
277 		char	ifru_newname[IFNAMSIZ];
278 		compat_caddr_t	ifru_data;
279 		struct	compat_if_settings ifru_settings;
280 	} ifr_ifru;
281 };
282 
283 struct compat_ifconf {
284 	compat_int_t	ifc_len;                /* size of buffer */
285 	compat_caddr_t  ifcbuf;
286 };
287 
288 struct compat_robust_list {
289 	compat_uptr_t			next;
290 };
291 
292 struct compat_robust_list_head {
293 	struct compat_robust_list	list;
294 	compat_long_t			futex_offset;
295 	compat_uptr_t			list_op_pending;
296 };
297 
298 #ifdef CONFIG_COMPAT_OLD_SIGACTION
299 struct compat_old_sigaction {
300 	compat_uptr_t			sa_handler;
301 	compat_old_sigset_t		sa_mask;
302 	compat_ulong_t			sa_flags;
303 	compat_uptr_t			sa_restorer;
304 };
305 #endif
306 
307 struct compat_keyctl_kdf_params {
308 	compat_uptr_t hashname;
309 	compat_uptr_t otherinfo;
310 	__u32 otherinfolen;
311 	__u32 __spare[8];
312 };
313 
314 struct compat_statfs;
315 struct compat_statfs64;
316 struct compat_old_linux_dirent;
317 struct compat_linux_dirent;
318 struct linux_dirent64;
319 struct compat_msghdr;
320 struct compat_mmsghdr;
321 struct compat_sysinfo;
322 struct compat_sysctl_args;
323 struct compat_kexec_segment;
324 struct compat_mq_attr;
325 struct compat_msgbuf;
326 
327 asmlinkage long
328 compat_sys_set_robust_list(struct compat_robust_list_head __user *head,
329 			   compat_size_t len);
330 asmlinkage long
331 compat_sys_get_robust_list(int pid, compat_uptr_t __user *head_ptr,
332 			   compat_size_t __user *len_ptr);
333 
334 asmlinkage long compat_sys_ipc(u32, int, int, u32, compat_uptr_t, u32);
335 asmlinkage long compat_sys_shmat(int shmid, compat_uptr_t shmaddr, int shmflg);
336 asmlinkage long compat_sys_semctl(int semid, int semnum, int cmd, int arg);
337 asmlinkage long compat_sys_msgsnd(int msqid, compat_uptr_t msgp,
338 		compat_ssize_t msgsz, int msgflg);
339 asmlinkage long compat_sys_msgrcv(int msqid, compat_uptr_t msgp,
340 		compat_ssize_t msgsz, compat_long_t msgtyp, int msgflg);
341 long compat_sys_msgctl(int first, int second, void __user *uptr);
342 long compat_sys_shmctl(int first, int second, void __user *uptr);
343 long compat_sys_semtimedop(int semid, struct sembuf __user *tsems,
344 		unsigned nsems, const struct compat_timespec __user *timeout);
345 asmlinkage long compat_sys_keyctl(u32 option,
346 			      u32 arg2, u32 arg3, u32 arg4, u32 arg5);
347 asmlinkage long compat_sys_ustat(unsigned dev, struct compat_ustat __user *u32);
348 
349 asmlinkage ssize_t compat_sys_readv(compat_ulong_t fd,
350 		const struct compat_iovec __user *vec, compat_ulong_t vlen);
351 asmlinkage ssize_t compat_sys_writev(compat_ulong_t fd,
352 		const struct compat_iovec __user *vec, compat_ulong_t vlen);
353 asmlinkage ssize_t compat_sys_preadv(compat_ulong_t fd,
354 		const struct compat_iovec __user *vec,
355 		compat_ulong_t vlen, u32 pos_low, u32 pos_high);
356 asmlinkage ssize_t compat_sys_pwritev(compat_ulong_t fd,
357 		const struct compat_iovec __user *vec,
358 		compat_ulong_t vlen, u32 pos_low, u32 pos_high);
359 asmlinkage ssize_t compat_sys_preadv2(compat_ulong_t fd,
360 		const struct compat_iovec __user *vec,
361 		compat_ulong_t vlen, u32 pos_low, u32 pos_high, rwf_t flags);
362 asmlinkage ssize_t compat_sys_pwritev2(compat_ulong_t fd,
363 		const struct compat_iovec __user *vec,
364 		compat_ulong_t vlen, u32 pos_low, u32 pos_high, rwf_t flags);
365 
366 #ifdef __ARCH_WANT_COMPAT_SYS_PREADV64
367 asmlinkage long compat_sys_preadv64(unsigned long fd,
368 		const struct compat_iovec __user *vec,
369 		unsigned long vlen, loff_t pos);
370 #endif
371 
372 #ifdef __ARCH_WANT_COMPAT_SYS_PWRITEV64
373 asmlinkage long compat_sys_pwritev64(unsigned long fd,
374 		const struct compat_iovec __user *vec,
375 		unsigned long vlen, loff_t pos);
376 #endif
377 
378 #ifdef __ARCH_WANT_COMPAT_SYS_PREADV64V2
379 asmlinkage long  compat_sys_readv64v2(unsigned long fd,
380 		const struct compat_iovec __user *vec,
381 		unsigned long vlen, loff_t pos, rwf_t flags);
382 #endif
383 
384 #ifdef __ARCH_WANT_COMPAT_SYS_PWRITEV64V2
385 asmlinkage long compat_sys_pwritev64v2(unsigned long fd,
386 		const struct compat_iovec __user *vec,
387 		unsigned long vlen, loff_t pos, rwf_t flags);
388 #endif
389 
390 asmlinkage long compat_sys_lseek(unsigned int, compat_off_t, unsigned int);
391 
392 asmlinkage long compat_sys_execve(const char __user *filename, const compat_uptr_t __user *argv,
393 		     const compat_uptr_t __user *envp);
394 asmlinkage long compat_sys_execveat(int dfd, const char __user *filename,
395 		     const compat_uptr_t __user *argv,
396 		     const compat_uptr_t __user *envp, int flags);
397 
398 asmlinkage long compat_sys_select(int n, compat_ulong_t __user *inp,
399 		compat_ulong_t __user *outp, compat_ulong_t __user *exp,
400 		struct compat_timeval __user *tvp);
401 
402 asmlinkage long compat_sys_old_select(struct compat_sel_arg_struct __user *arg);
403 
404 asmlinkage long compat_sys_wait4(compat_pid_t pid,
405 				 compat_uint_t __user *stat_addr, int options,
406 				 struct compat_rusage __user *ru);
407 
408 #define BITS_PER_COMPAT_LONG    (8*sizeof(compat_long_t))
409 
410 #define BITS_TO_COMPAT_LONGS(bits) DIV_ROUND_UP(bits, BITS_PER_COMPAT_LONG)
411 
412 long compat_get_bitmap(unsigned long *mask, const compat_ulong_t __user *umask,
413 		       unsigned long bitmap_size);
414 long compat_put_bitmap(compat_ulong_t __user *umask, unsigned long *mask,
415 		       unsigned long bitmap_size);
416 int copy_siginfo_from_user32(siginfo_t *to, struct compat_siginfo __user *from);
417 int copy_siginfo_to_user32(struct compat_siginfo __user *to, const siginfo_t *from);
418 int get_compat_sigevent(struct sigevent *event,
419 		const struct compat_sigevent __user *u_event);
420 long compat_sys_rt_tgsigqueueinfo(compat_pid_t tgid, compat_pid_t pid, int sig,
421 				  struct compat_siginfo __user *uinfo);
422 #ifdef CONFIG_COMPAT_OLD_SIGACTION
423 asmlinkage long compat_sys_sigaction(int sig,
424                                    const struct compat_old_sigaction __user *act,
425                                    struct compat_old_sigaction __user *oact);
426 #endif
427 
compat_timeval_compare(struct compat_timeval * lhs,struct compat_timeval * rhs)428 static inline int compat_timeval_compare(struct compat_timeval *lhs,
429 					struct compat_timeval *rhs)
430 {
431 	if (lhs->tv_sec < rhs->tv_sec)
432 		return -1;
433 	if (lhs->tv_sec > rhs->tv_sec)
434 		return 1;
435 	return lhs->tv_usec - rhs->tv_usec;
436 }
437 
compat_timespec_compare(struct compat_timespec * lhs,struct compat_timespec * rhs)438 static inline int compat_timespec_compare(struct compat_timespec *lhs,
439 					struct compat_timespec *rhs)
440 {
441 	if (lhs->tv_sec < rhs->tv_sec)
442 		return -1;
443 	if (lhs->tv_sec > rhs->tv_sec)
444 		return 1;
445 	return lhs->tv_nsec - rhs->tv_nsec;
446 }
447 
448 extern int get_compat_itimerspec(struct itimerspec *dst,
449 				 const struct compat_itimerspec __user *src);
450 extern int put_compat_itimerspec(struct compat_itimerspec __user *dst,
451 				 const struct itimerspec *src);
452 
453 asmlinkage long compat_sys_gettimeofday(struct compat_timeval __user *tv,
454 		struct timezone __user *tz);
455 asmlinkage long compat_sys_settimeofday(struct compat_timeval __user *tv,
456 		struct timezone __user *tz);
457 
458 asmlinkage long compat_sys_adjtimex(struct compat_timex __user *utp);
459 
460 extern void sigset_from_compat(sigset_t *set, const compat_sigset_t *compat);
461 extern void sigset_to_compat(compat_sigset_t *compat, const sigset_t *set);
462 
463 asmlinkage long compat_sys_migrate_pages(compat_pid_t pid,
464 		compat_ulong_t maxnode, const compat_ulong_t __user *old_nodes,
465 		const compat_ulong_t __user *new_nodes);
466 
467 extern int compat_ptrace_request(struct task_struct *child,
468 				 compat_long_t request,
469 				 compat_ulong_t addr, compat_ulong_t data);
470 
471 extern long compat_arch_ptrace(struct task_struct *child, compat_long_t request,
472 			       compat_ulong_t addr, compat_ulong_t data);
473 asmlinkage long compat_sys_ptrace(compat_long_t request, compat_long_t pid,
474 				  compat_long_t addr, compat_long_t data);
475 
476 asmlinkage long compat_sys_lookup_dcookie(u32, u32, char __user *, compat_size_t);
477 /*
478  * epoll (fs/eventpoll.c) compat bits follow ...
479  */
480 struct epoll_event;	/* fortunately, this one is fixed-layout */
481 asmlinkage long compat_sys_epoll_pwait(int epfd,
482 			struct epoll_event __user *events,
483 			int maxevents, int timeout,
484 			const compat_sigset_t __user *sigmask,
485 			compat_size_t sigsetsize);
486 
487 asmlinkage long compat_sys_utime(const char __user *filename,
488 				 struct compat_utimbuf __user *t);
489 asmlinkage long compat_sys_utimensat(unsigned int dfd,
490 				     const char __user *filename,
491 				     struct compat_timespec __user *t,
492 				     int flags);
493 
494 asmlinkage long compat_sys_time(compat_time_t __user *tloc);
495 asmlinkage long compat_sys_stime(compat_time_t __user *tptr);
496 asmlinkage long compat_sys_signalfd(int ufd,
497 				    const compat_sigset_t __user *sigmask,
498 				    compat_size_t sigsetsize);
499 asmlinkage long compat_sys_timerfd_settime(int ufd, int flags,
500 				   const struct compat_itimerspec __user *utmr,
501 				   struct compat_itimerspec __user *otmr);
502 asmlinkage long compat_sys_timerfd_gettime(int ufd,
503 				   struct compat_itimerspec __user *otmr);
504 
505 asmlinkage long compat_sys_move_pages(pid_t pid, compat_ulong_t nr_pages,
506 				      __u32 __user *pages,
507 				      const int __user *nodes,
508 				      int __user *status,
509 				      int flags);
510 asmlinkage long compat_sys_futimesat(unsigned int dfd,
511 				     const char __user *filename,
512 				     struct compat_timeval __user *t);
513 asmlinkage long compat_sys_utimes(const char __user *filename,
514 				  struct compat_timeval __user *t);
515 asmlinkage long compat_sys_newstat(const char __user *filename,
516 				   struct compat_stat __user *statbuf);
517 asmlinkage long compat_sys_newlstat(const char __user *filename,
518 				    struct compat_stat __user *statbuf);
519 asmlinkage long compat_sys_newfstatat(unsigned int dfd,
520 				      const char __user *filename,
521 				      struct compat_stat __user *statbuf,
522 				      int flag);
523 asmlinkage long compat_sys_newfstat(unsigned int fd,
524 				    struct compat_stat __user *statbuf);
525 asmlinkage long compat_sys_statfs(const char __user *pathname,
526 				  struct compat_statfs __user *buf);
527 asmlinkage long compat_sys_fstatfs(unsigned int fd,
528 				   struct compat_statfs __user *buf);
529 asmlinkage long compat_sys_statfs64(const char __user *pathname,
530 				    compat_size_t sz,
531 				    struct compat_statfs64 __user *buf);
532 asmlinkage long compat_sys_fstatfs64(unsigned int fd, compat_size_t sz,
533 				     struct compat_statfs64 __user *buf);
534 asmlinkage long compat_sys_fcntl64(unsigned int fd, unsigned int cmd,
535 				   compat_ulong_t arg);
536 asmlinkage long compat_sys_fcntl(unsigned int fd, unsigned int cmd,
537 				 compat_ulong_t arg);
538 asmlinkage long compat_sys_io_setup(unsigned nr_reqs, u32 __user *ctx32p);
539 asmlinkage long compat_sys_io_getevents(compat_aio_context_t ctx_id,
540 					compat_long_t min_nr,
541 					compat_long_t nr,
542 					struct io_event __user *events,
543 					struct compat_timespec __user *timeout);
544 asmlinkage long compat_sys_io_submit(compat_aio_context_t ctx_id, int nr,
545 				     u32 __user *iocb);
546 asmlinkage long compat_sys_mount(const char __user *dev_name,
547 				 const char __user *dir_name,
548 				 const char __user *type, compat_ulong_t flags,
549 				 const void __user *data);
550 asmlinkage long compat_sys_old_readdir(unsigned int fd,
551 				       struct compat_old_linux_dirent __user *,
552 				       unsigned int count);
553 asmlinkage long compat_sys_getdents(unsigned int fd,
554 				    struct compat_linux_dirent __user *dirent,
555 				    unsigned int count);
556 asmlinkage long compat_sys_vmsplice(int fd, const struct compat_iovec __user *,
557 				    unsigned int nr_segs, unsigned int flags);
558 asmlinkage long compat_sys_open(const char __user *filename, int flags,
559 				umode_t mode);
560 asmlinkage long compat_sys_openat(int dfd, const char __user *filename,
561 				  int flags, umode_t mode);
562 asmlinkage long compat_sys_open_by_handle_at(int mountdirfd,
563 					     struct file_handle __user *handle,
564 					     int flags);
565 asmlinkage long compat_sys_truncate(const char __user *, compat_off_t);
566 asmlinkage long compat_sys_ftruncate(unsigned int, compat_ulong_t);
567 asmlinkage long compat_sys_pselect6(int n, compat_ulong_t __user *inp,
568 				    compat_ulong_t __user *outp,
569 				    compat_ulong_t __user *exp,
570 				    struct compat_timespec __user *tsp,
571 				    void __user *sig);
572 asmlinkage long compat_sys_ppoll(struct pollfd __user *ufds,
573 				 unsigned int nfds,
574 				 struct compat_timespec __user *tsp,
575 				 const compat_sigset_t __user *sigmask,
576 				 compat_size_t sigsetsize);
577 asmlinkage long compat_sys_signalfd4(int ufd,
578 				     const compat_sigset_t __user *sigmask,
579 				     compat_size_t sigsetsize, int flags);
580 asmlinkage long compat_sys_get_mempolicy(int __user *policy,
581 					 compat_ulong_t __user *nmask,
582 					 compat_ulong_t maxnode,
583 					 compat_ulong_t addr,
584 					 compat_ulong_t flags);
585 asmlinkage long compat_sys_set_mempolicy(int mode, compat_ulong_t __user *nmask,
586 					 compat_ulong_t maxnode);
587 asmlinkage long compat_sys_mbind(compat_ulong_t start, compat_ulong_t len,
588 				 compat_ulong_t mode,
589 				 compat_ulong_t __user *nmask,
590 				 compat_ulong_t maxnode, compat_ulong_t flags);
591 
592 asmlinkage long compat_sys_setsockopt(int fd, int level, int optname,
593 				      char __user *optval, unsigned int optlen);
594 asmlinkage long compat_sys_sendmsg(int fd, struct compat_msghdr __user *msg,
595 				   unsigned flags);
596 asmlinkage long compat_sys_sendmmsg(int fd, struct compat_mmsghdr __user *mmsg,
597 				    unsigned vlen, unsigned int flags);
598 asmlinkage long compat_sys_recvmsg(int fd, struct compat_msghdr __user *msg,
599 				   unsigned int flags);
600 asmlinkage long compat_sys_recv(int fd, void __user *buf, compat_size_t len,
601 				unsigned flags);
602 asmlinkage long compat_sys_recvfrom(int fd, void __user *buf, compat_size_t len,
603 			    unsigned flags, struct sockaddr __user *addr,
604 			    int __user *addrlen);
605 asmlinkage long compat_sys_recvmmsg(int fd, struct compat_mmsghdr __user *mmsg,
606 				    unsigned vlen, unsigned int flags,
607 				    struct compat_timespec __user *timeout);
608 asmlinkage long compat_sys_nanosleep(struct compat_timespec __user *rqtp,
609 				     struct compat_timespec __user *rmtp);
610 asmlinkage long compat_sys_getitimer(int which,
611 				     struct compat_itimerval __user *it);
612 asmlinkage long compat_sys_setitimer(int which,
613 				     struct compat_itimerval __user *in,
614 				     struct compat_itimerval __user *out);
615 asmlinkage long compat_sys_times(struct compat_tms __user *tbuf);
616 asmlinkage long compat_sys_setrlimit(unsigned int resource,
617 				     struct compat_rlimit __user *rlim);
618 asmlinkage long compat_sys_getrlimit(unsigned int resource,
619 				     struct compat_rlimit __user *rlim);
620 asmlinkage long compat_sys_getrusage(int who, struct compat_rusage __user *ru);
621 asmlinkage long compat_sys_sched_setaffinity(compat_pid_t pid,
622 				     unsigned int len,
623 				     compat_ulong_t __user *user_mask_ptr);
624 asmlinkage long compat_sys_sched_getaffinity(compat_pid_t pid,
625 				     unsigned int len,
626 				     compat_ulong_t __user *user_mask_ptr);
627 asmlinkage long compat_sys_timer_create(clockid_t which_clock,
628 			struct compat_sigevent __user *timer_event_spec,
629 			timer_t __user *created_timer_id);
630 asmlinkage long compat_sys_timer_settime(timer_t timer_id, int flags,
631 					 struct compat_itimerspec __user *new,
632 					 struct compat_itimerspec __user *old);
633 asmlinkage long compat_sys_timer_gettime(timer_t timer_id,
634 				 struct compat_itimerspec __user *setting);
635 asmlinkage long compat_sys_clock_settime(clockid_t which_clock,
636 					 struct compat_timespec __user *tp);
637 asmlinkage long compat_sys_clock_gettime(clockid_t which_clock,
638 					 struct compat_timespec __user *tp);
639 asmlinkage long compat_sys_clock_adjtime(clockid_t which_clock,
640 					 struct compat_timex __user *tp);
641 asmlinkage long compat_sys_clock_getres(clockid_t which_clock,
642 					struct compat_timespec __user *tp);
643 asmlinkage long compat_sys_clock_nanosleep(clockid_t which_clock, int flags,
644 					   struct compat_timespec __user *rqtp,
645 					   struct compat_timespec __user *rmtp);
646 asmlinkage long compat_sys_rt_sigtimedwait(compat_sigset_t __user *uthese,
647 		struct compat_siginfo __user *uinfo,
648 		struct compat_timespec __user *uts, compat_size_t sigsetsize);
649 asmlinkage long compat_sys_rt_sigsuspend(compat_sigset_t __user *unewset,
650 					 compat_size_t sigsetsize);
651 asmlinkage long compat_sys_rt_sigprocmask(int how, compat_sigset_t __user *set,
652 					  compat_sigset_t __user *oset,
653 					  compat_size_t sigsetsize);
654 asmlinkage long compat_sys_rt_sigpending(compat_sigset_t __user *uset,
655 					 compat_size_t sigsetsize);
656 #ifndef CONFIG_ODD_RT_SIGACTION
657 asmlinkage long compat_sys_rt_sigaction(int,
658 				 const struct compat_sigaction __user *,
659 				 struct compat_sigaction __user *,
660 				 compat_size_t);
661 #endif
662 asmlinkage long compat_sys_rt_sigqueueinfo(compat_pid_t pid, int sig,
663 				struct compat_siginfo __user *uinfo);
664 asmlinkage long compat_sys_sysinfo(struct compat_sysinfo __user *info);
665 asmlinkage long compat_sys_ioctl(unsigned int fd, unsigned int cmd,
666 				 compat_ulong_t arg);
667 asmlinkage long compat_sys_futex(u32 __user *uaddr, int op, u32 val,
668 		struct compat_timespec __user *utime, u32 __user *uaddr2,
669 		u32 val3);
670 asmlinkage long compat_sys_getsockopt(int fd, int level, int optname,
671 				      char __user *optval, int __user *optlen);
672 asmlinkage long compat_sys_kexec_load(compat_ulong_t entry,
673 				      compat_ulong_t nr_segments,
674 				      struct compat_kexec_segment __user *,
675 				      compat_ulong_t flags);
676 asmlinkage long compat_sys_mq_getsetattr(mqd_t mqdes,
677 			const struct compat_mq_attr __user *u_mqstat,
678 			struct compat_mq_attr __user *u_omqstat);
679 asmlinkage long compat_sys_mq_notify(mqd_t mqdes,
680 			const struct compat_sigevent __user *u_notification);
681 asmlinkage long compat_sys_mq_open(const char __user *u_name,
682 			int oflag, compat_mode_t mode,
683 			struct compat_mq_attr __user *u_attr);
684 asmlinkage long compat_sys_mq_timedsend(mqd_t mqdes,
685 			const char __user *u_msg_ptr,
686 			compat_size_t msg_len, unsigned int msg_prio,
687 			const struct compat_timespec __user *u_abs_timeout);
688 asmlinkage ssize_t compat_sys_mq_timedreceive(mqd_t mqdes,
689 			char __user *u_msg_ptr,
690 			compat_size_t msg_len, unsigned int __user *u_msg_prio,
691 			const struct compat_timespec __user *u_abs_timeout);
692 asmlinkage long compat_sys_socketcall(int call, u32 __user *args);
693 asmlinkage long compat_sys_sysctl(struct compat_sysctl_args __user *args);
694 
695 extern ssize_t compat_rw_copy_check_uvector(int type,
696 		const struct compat_iovec __user *uvector,
697 		unsigned long nr_segs,
698 		unsigned long fast_segs, struct iovec *fast_pointer,
699 		struct iovec **ret_pointer);
700 
701 extern void __user *compat_alloc_user_space(unsigned long len);
702 
703 asmlinkage ssize_t compat_sys_process_vm_readv(compat_pid_t pid,
704 		const struct compat_iovec __user *lvec,
705 		compat_ulong_t liovcnt, const struct compat_iovec __user *rvec,
706 		compat_ulong_t riovcnt, compat_ulong_t flags);
707 asmlinkage ssize_t compat_sys_process_vm_writev(compat_pid_t pid,
708 		const struct compat_iovec __user *lvec,
709 		compat_ulong_t liovcnt, const struct compat_iovec __user *rvec,
710 		compat_ulong_t riovcnt, compat_ulong_t flags);
711 
712 asmlinkage long compat_sys_sendfile(int out_fd, int in_fd,
713 				    compat_off_t __user *offset, compat_size_t count);
714 asmlinkage long compat_sys_sendfile64(int out_fd, int in_fd,
715 				    compat_loff_t __user *offset, compat_size_t count);
716 asmlinkage long compat_sys_sigaltstack(const compat_stack_t __user *uss_ptr,
717 				       compat_stack_t __user *uoss_ptr);
718 
719 #ifdef __ARCH_WANT_SYS_SIGPENDING
720 asmlinkage long compat_sys_sigpending(compat_old_sigset_t __user *set);
721 #endif
722 
723 #ifdef __ARCH_WANT_SYS_SIGPROCMASK
724 asmlinkage long compat_sys_sigprocmask(int how, compat_old_sigset_t __user *nset,
725 				       compat_old_sigset_t __user *oset);
726 #endif
727 
728 int compat_restore_altstack(const compat_stack_t __user *uss);
729 int __compat_save_altstack(compat_stack_t __user *, unsigned long);
730 #define compat_save_altstack_ex(uss, sp) do { \
731 	compat_stack_t __user *__uss = uss; \
732 	struct task_struct *t = current; \
733 	put_user_ex(ptr_to_compat((void __user *)t->sas_ss_sp), &__uss->ss_sp); \
734 	put_user_ex(t->sas_ss_flags, &__uss->ss_flags); \
735 	put_user_ex(t->sas_ss_size, &__uss->ss_size); \
736 	if (t->sas_ss_flags & SS_AUTODISARM) \
737 		sas_ss_reset(t); \
738 } while (0);
739 
740 asmlinkage long compat_sys_sched_rr_get_interval(compat_pid_t pid,
741 						 struct compat_timespec __user *interval);
742 
743 asmlinkage long compat_sys_fanotify_mark(int, unsigned int, __u32, __u32,
744 					    int, const char __user *);
745 
746 asmlinkage long compat_sys_arch_prctl(int option, unsigned long arg2);
747 
748 /*
749  * For most but not all architectures, "am I in a compat syscall?" and
750  * "am I a compat task?" are the same question.  For architectures on which
751  * they aren't the same question, arch code can override in_compat_syscall.
752  */
753 
754 #ifndef in_compat_syscall
in_compat_syscall(void)755 static inline bool in_compat_syscall(void) { return is_compat_task(); }
756 #endif
757 
758 /**
759  * ns_to_compat_timeval - Compat version of ns_to_timeval
760  * @nsec:	the nanoseconds value to be converted
761  *
762  * Returns the compat_timeval representation of the nsec parameter.
763  */
ns_to_compat_timeval(s64 nsec)764 static inline struct compat_timeval ns_to_compat_timeval(s64 nsec)
765 {
766 	struct timeval tv;
767 	struct compat_timeval ctv;
768 
769 	tv = ns_to_timeval(nsec);
770 	ctv.tv_sec = tv.tv_sec;
771 	ctv.tv_usec = tv.tv_usec;
772 
773 	return ctv;
774 }
775 
776 #else /* !CONFIG_COMPAT */
777 
778 #define is_compat_task() (0)
in_compat_syscall(void)779 static inline bool in_compat_syscall(void) { return false; }
780 
781 #endif /* CONFIG_COMPAT */
782 
783 #endif /* _LINUX_COMPAT_H */
784