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