blob: cd50b00ef59adf4eab703a856ec44162433963da [file] [log] [blame]
Greg Kroah-Hartmanb2441312017-11-01 15:07:57 +01001/* SPDX-License-Identifier: GPL-2.0 */
Linus Torvalds1da177e2005-04-16 15:20:36 -07002#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 */
Linus Torvalds1da177e2005-04-16 15:20:36 -07008
Andy Lutomirski5180e3e2016-03-22 14:24:43 -07009#include <linux/types.h>
Deepa Dinamani0d553032018-03-13 21:03:25 -070010#include <linux/compat_time.h>
Andy Lutomirski5180e3e2016-03-22 14:24:43 -070011
Linus Torvalds1da177e2005-04-16 15:20:36 -070012#include <linux/stat.h>
13#include <linux/param.h> /* for HZ */
14#include <linux/sem.h>
Arnd Bergmann2dceba12009-11-06 08:09:03 +000015#include <linux/socket.h>
16#include <linux/if.h>
Chris Metcalfbe84cb42011-05-09 13:12:30 -040017#include <linux/fs.h>
Stephen Rothwell45e96832011-05-24 13:28:54 +100018#include <linux/aio_abi.h> /* for aio_context_t */
Matt Redfearnfde9fc72018-02-19 16:55:06 +000019#include <linux/uaccess.h>
Heiko Carstensf5b972e2014-03-20 15:30:14 +010020#include <linux/unistd.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070021
22#include <asm/compat.h>
Arnd Bergmann2b5a9a32018-03-26 16:59:15 +020023
24#ifdef CONFIG_COMPAT
Linus Torvalds1da177e2005-04-16 15:20:36 -070025#include <asm/siginfo.h>
David Howells3f2e05e2006-10-02 14:12:31 +010026#include <asm/signal.h>
Deepa Dinamani5055c672018-03-13 21:03:24 -070027#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -070028
Dominik Brodowski7303e302018-04-05 11:53:03 +020029#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
H. J. Lu45e87782012-02-10 14:04:27 -080040#ifndef COMPAT_USE_64BIT_TIME
41#define COMPAT_USE_64BIT_TIME 0
42#endif
43
Al Viro46836612012-11-23 09:12:59 -050044#ifndef __SC_DELOUSE
Al Viro4f59c712017-07-08 11:40:39 -040045#define __SC_DELOUSE(t,v) ((__force t)(unsigned long)(v))
Al Viro46836612012-11-23 09:12:59 -050046#endif
47
Dominik Brodowski7303e302018-04-05 11:53:03 +020048#ifndef COMPAT_SYSCALL_DEFINE0
Heiko Carstens217f4432014-02-26 10:56:20 +010049#define COMPAT_SYSCALL_DEFINE0(name) \
Howard McLauchlanc9a21192018-03-21 18:59:08 -070050 asmlinkage long compat_sys_##name(void); \
51 ALLOW_ERROR_INJECTION(compat_sys_##name, ERRNO); \
Heiko Carstens217f4432014-02-26 10:56:20 +010052 asmlinkage long compat_sys_##name(void)
Dominik Brodowski7303e302018-04-05 11:53:03 +020053#endif /* COMPAT_SYSCALL_DEFINE0 */
Heiko Carstens217f4432014-02-26 10:56:20 +010054
Al Viro46836612012-11-23 09:12:59 -050055#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
Dominik Brodowski5ac9efa2018-04-09 12:51:43 +020068/*
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 */
Dominik Brodowski7303e302018-04-05 11:53:03 +020073#ifndef COMPAT_SYSCALL_DEFINEx
Dominik Brodowski5ac9efa2018-04-09 12:51:43 +020074#define COMPAT_SYSCALL_DEFINEx(x, name, ...) \
75 asmlinkage long compat_sys##name(__MAP(x,__SC_DECL,__VA_ARGS__)); \
76 asmlinkage long compat_sys##name(__MAP(x,__SC_DECL,__VA_ARGS__)) \
77 __attribute__((alias(__stringify(__se_compat_sys##name)))); \
78 ALLOW_ERROR_INJECTION(compat_sys##name, ERRNO); \
79 static inline long __do_compat_sys##name(__MAP(x,__SC_DECL,__VA_ARGS__));\
80 asmlinkage long __se_compat_sys##name(__MAP(x,__SC_LONG,__VA_ARGS__)); \
81 asmlinkage long __se_compat_sys##name(__MAP(x,__SC_LONG,__VA_ARGS__)) \
82 { \
83 return __do_compat_sys##name(__MAP(x,__SC_DELOUSE,__VA_ARGS__));\
84 } \
85 static inline long __do_compat_sys##name(__MAP(x,__SC_DECL,__VA_ARGS__))
Dominik Brodowski7303e302018-04-05 11:53:03 +020086#endif /* COMPAT_SYSCALL_DEFINEx */
Al Viro46836612012-11-23 09:12:59 -050087
Deepa Dinamani5055c672018-03-13 21:03:24 -070088#ifdef CONFIG_COMPAT
89
Al Viro9b064fc2012-12-14 13:49:35 -050090#ifndef compat_user_stack_pointer
91#define compat_user_stack_pointer() current_user_stack_pointer()
92#endif
Al Viro90268432012-12-14 14:47:53 -050093#ifndef compat_sigaltstack /* we'll need that for MIPS */
94typedef struct compat_sigaltstack {
95 compat_uptr_t ss_sp;
96 int ss_flags;
97 compat_size_t ss_size;
98} compat_stack_t;
99#endif
Al Viro90268432012-12-14 14:47:53 -0500100
Linus Torvalds1da177e2005-04-16 15:20:36 -0700101#define compat_jiffies_to_clock_t(x) \
102 (((unsigned long)(x) * COMPAT_USER_HZ) / HZ)
103
Stephen Rothwell202e5972005-09-06 15:16:40 -0700104typedef __compat_uid32_t compat_uid_t;
105typedef __compat_gid32_t compat_gid_t;
106
Heiko Carstens932602e2014-03-04 16:07:52 +0100107typedef compat_ulong_t compat_aio_context_t;
108
Christoph Hellwig5d0e5282010-03-10 15:21:13 -0800109struct compat_sel_arg_struct;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700110struct rusage;
111
Chris Metcalf4800a5b2011-05-17 14:41:06 -0400112struct compat_itimerspec {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700113 struct compat_timespec it_interval;
114 struct compat_timespec it_value;
115};
116
117struct compat_utimbuf {
118 compat_time_t actime;
119 compat_time_t modtime;
120};
121
122struct compat_itimerval {
123 struct compat_timeval it_interval;
124 struct compat_timeval it_value;
125};
126
Al Viro54ad9c42017-06-07 09:42:37 +0100127struct itimerval;
128int get_compat_itimerval(struct itimerval *, const struct compat_itimerval __user *);
129int put_compat_itimerval(struct compat_itimerval __user *, const struct itimerval *);
130
Linus Torvalds1da177e2005-04-16 15:20:36 -0700131struct compat_tms {
132 compat_clock_t tms_utime;
133 compat_clock_t tms_stime;
134 compat_clock_t tms_cutime;
135 compat_clock_t tms_cstime;
136};
137
Stephen Rothwell88959ea2006-03-26 01:37:27 -0800138struct compat_timex {
139 compat_uint_t modes;
140 compat_long_t offset;
141 compat_long_t freq;
142 compat_long_t maxerror;
143 compat_long_t esterror;
144 compat_int_t status;
145 compat_long_t constant;
146 compat_long_t precision;
147 compat_long_t tolerance;
148 struct compat_timeval time;
149 compat_long_t tick;
150 compat_long_t ppsfreq;
151 compat_long_t jitter;
152 compat_int_t shift;
153 compat_long_t stabil;
154 compat_long_t jitcnt;
155 compat_long_t calcnt;
156 compat_long_t errcnt;
157 compat_long_t stbcnt;
Roman Zippel153b5d02008-05-01 04:34:37 -0700158 compat_int_t tai;
Stephen Rothwell88959ea2006-03-26 01:37:27 -0800159
Chris Metcalf4800a5b2011-05-17 14:41:06 -0400160 compat_int_t:32; compat_int_t:32; compat_int_t:32; compat_int_t:32;
161 compat_int_t:32; compat_int_t:32; compat_int_t:32; compat_int_t:32;
162 compat_int_t:32; compat_int_t:32; compat_int_t:32;
Stephen Rothwell88959ea2006-03-26 01:37:27 -0800163};
164
Al Viro3a4d44b2017-06-07 09:42:34 +0100165struct timex;
166int compat_get_timex(struct timex *, const struct compat_timex __user *);
167int compat_put_timex(struct compat_timex __user *, const struct timex *);
168
Linus Torvalds1da177e2005-04-16 15:20:36 -0700169#define _COMPAT_NSIG_WORDS (_COMPAT_NSIG / _COMPAT_NSIG_BPW)
170
171typedef struct {
172 compat_sigset_word sig[_COMPAT_NSIG_WORDS];
173} compat_sigset_t;
174
Al Viro08d32fe2012-12-25 18:38:15 -0500175struct compat_sigaction {
David Howells2a148692013-03-19 14:00:53 +0000176#ifndef __ARCH_HAS_IRIX_SIGACTION
Al Viro08d32fe2012-12-25 18:38:15 -0500177 compat_uptr_t sa_handler;
178 compat_ulong_t sa_flags;
179#else
David Howells2a148692013-03-19 14:00:53 +0000180 compat_uint_t sa_flags;
Al Viro08d32fe2012-12-25 18:38:15 -0500181 compat_uptr_t sa_handler;
182#endif
183#ifdef __ARCH_HAS_SA_RESTORER
184 compat_uptr_t sa_restorer;
185#endif
186 compat_sigset_t sa_mask __packed;
187};
Al Viro08d32fe2012-12-25 18:38:15 -0500188
Al Virob713da62017-07-09 15:53:17 -0400189typedef union compat_sigval {
190 compat_int_t sival_int;
191 compat_uptr_t sival_ptr;
192} compat_sigval_t;
193
194typedef struct compat_siginfo {
195 int si_signo;
196#ifndef __ARCH_HAS_SWAPPED_SIGINFO
197 int si_errno;
198 int si_code;
199#else
200 int si_code;
201 int si_errno;
202#endif
203
204 union {
205 int _pad[128/sizeof(int) - 3];
206
207 /* kill() */
208 struct {
209 compat_pid_t _pid; /* sender's pid */
210 __compat_uid32_t _uid; /* sender's uid */
211 } _kill;
212
213 /* POSIX.1b timers */
214 struct {
215 compat_timer_t _tid; /* timer id */
216 int _overrun; /* overrun count */
217 compat_sigval_t _sigval; /* same as below */
218 } _timer;
219
220 /* POSIX.1b signals */
221 struct {
222 compat_pid_t _pid; /* sender's pid */
223 __compat_uid32_t _uid; /* sender's uid */
224 compat_sigval_t _sigval;
225 } _rt;
226
227 /* SIGCHLD */
228 struct {
229 compat_pid_t _pid; /* which child */
230 __compat_uid32_t _uid; /* sender's uid */
231 int _status; /* exit code */
232 compat_clock_t _utime;
233 compat_clock_t _stime;
234 } _sigchld;
235
236#ifdef CONFIG_X86_X32_ABI
237 /* SIGCHLD (x32 version) */
238 struct {
239 compat_pid_t _pid; /* which child */
240 __compat_uid32_t _uid; /* sender's uid */
241 int _status; /* exit code */
242 compat_s64 _utime;
243 compat_s64 _stime;
244 } _sigchld_x32;
245#endif
246
247 /* SIGILL, SIGFPE, SIGSEGV, SIGBUS, SIGTRAP, SIGEMT */
248 struct {
249 compat_uptr_t _addr; /* faulting insn/memory ref. */
250#ifdef __ARCH_SI_TRAPNO
251 int _trapno; /* TRAP # which caused the signal */
252#endif
Eric W. Biederman8420f712018-04-02 14:45:42 -0500253#define __COMPAT_ADDR_BND_PKEY_PAD (__alignof__(compat_uptr_t) < sizeof(short) ? \
254 sizeof(short) : __alignof__(compat_uptr_t))
Al Virob713da62017-07-09 15:53:17 -0400255 union {
Eric W. Biedermanb68a68d2017-07-31 10:08:59 -0500256 /*
257 * used when si_code=BUS_MCEERR_AR or
258 * used when si_code=BUS_MCEERR_AO
259 */
260 short int _addr_lsb; /* Valid LSB of the reported address. */
Al Virob713da62017-07-09 15:53:17 -0400261 /* used when si_code=SEGV_BNDERR */
262 struct {
Eric W. Biederman8420f712018-04-02 14:45:42 -0500263 char _dummy_bnd[__COMPAT_ADDR_BND_PKEY_PAD];
Al Virob713da62017-07-09 15:53:17 -0400264 compat_uptr_t _lower;
265 compat_uptr_t _upper;
266 } _addr_bnd;
267 /* used when si_code=SEGV_PKUERR */
Eric W. Biedermanb68a68d2017-07-31 10:08:59 -0500268 struct {
Eric W. Biederman8420f712018-04-02 14:45:42 -0500269 char _dummy_pkey[__COMPAT_ADDR_BND_PKEY_PAD];
Eric W. Biedermanb68a68d2017-07-31 10:08:59 -0500270 u32 _pkey;
271 } _addr_pkey;
Al Virob713da62017-07-09 15:53:17 -0400272 };
273 } _sigfault;
274
275 /* SIGPOLL */
276 struct {
277 compat_long_t _band; /* POLL_IN, POLL_OUT, POLL_MSG */
278 int _fd;
279 } _sigpoll;
280
281 struct {
282 compat_uptr_t _call_addr; /* calling user insn */
283 int _syscall; /* triggering system call number */
284 unsigned int _arch; /* AUDIT_ARCH_* of syscall */
285 } _sigsys;
286 } _sifields;
287} compat_siginfo_t;
288
H. Peter Anvin6684ba22012-02-19 17:38:00 -0800289/*
H. Peter Anvin6684ba22012-02-19 17:38:00 -0800290 * These functions operate on 32- or 64-bit specs depending on
H. Peter Anvin81993e82014-02-01 18:54:11 -0800291 * COMPAT_USE_64BIT_TIME, hence the void user pointer arguments.
H. Peter Anvin6684ba22012-02-19 17:38:00 -0800292 */
293extern int compat_get_timespec(struct timespec *, const void __user *);
294extern int compat_put_timespec(const struct timespec *, void __user *);
295extern int compat_get_timeval(struct timeval *, const void __user *);
296extern int compat_put_timeval(const struct timeval *, void __user *);
Deepa Dinamanif59dd9c2017-06-24 11:45:02 -0700297extern int compat_get_timespec64(struct timespec64 *, const void __user *);
298extern int compat_put_timespec64(const struct timespec64 *, void __user *);
Deepa Dinamanid5b7ffb2017-06-24 11:45:03 -0700299extern int get_compat_itimerspec64(struct itimerspec64 *its,
300 const struct compat_itimerspec __user *uits);
301extern int put_compat_itimerspec64(const struct itimerspec64 *its,
302 struct compat_itimerspec __user *uits);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700303
304struct compat_iovec {
305 compat_uptr_t iov_base;
306 compat_size_t iov_len;
307};
308
309struct compat_rlimit {
310 compat_ulong_t rlim_cur;
311 compat_ulong_t rlim_max;
312};
313
314struct compat_rusage {
315 struct compat_timeval ru_utime;
316 struct compat_timeval ru_stime;
317 compat_long_t ru_maxrss;
318 compat_long_t ru_ixrss;
319 compat_long_t ru_idrss;
320 compat_long_t ru_isrss;
321 compat_long_t ru_minflt;
322 compat_long_t ru_majflt;
323 compat_long_t ru_nswap;
324 compat_long_t ru_inblock;
325 compat_long_t ru_oublock;
326 compat_long_t ru_msgsnd;
327 compat_long_t ru_msgrcv;
328 compat_long_t ru_nsignals;
329 compat_long_t ru_nvcsw;
330 compat_long_t ru_nivcsw;
331};
332
Chris Metcalf4800a5b2011-05-17 14:41:06 -0400333extern int put_compat_rusage(const struct rusage *,
334 struct compat_rusage __user *);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700335
336struct compat_siginfo;
337
Linus Torvalds1da177e2005-04-16 15:20:36 -0700338struct compat_dirent {
339 u32 d_ino;
340 compat_off_t d_off;
341 u16 d_reclen;
342 char d_name[256];
343};
344
Christoph Hellwig2b1c6bd2008-11-28 10:09:09 +0100345struct compat_ustat {
346 compat_daddr_t f_tfree;
347 compat_ino_t f_tinode;
348 char f_fname[6];
349 char f_fpack[6];
350};
351
Linus Torvalds1da177e2005-04-16 15:20:36 -0700352#define COMPAT_SIGEV_PAD_SIZE ((SIGEV_MAX_SIZE/sizeof(int)) - 3)
353
354typedef struct compat_sigevent {
355 compat_sigval_t sigev_value;
356 compat_int_t sigev_signo;
357 compat_int_t sigev_notify;
358 union {
359 compat_int_t _pad[COMPAT_SIGEV_PAD_SIZE];
360 compat_int_t _tid;
361
362 struct {
363 compat_uptr_t _function;
364 compat_uptr_t _attribute;
365 } _sigev_thread;
366 } _sigev_un;
367} compat_sigevent_t;
368
Arnd Bergmann2dceba12009-11-06 08:09:03 +0000369struct compat_ifmap {
370 compat_ulong_t mem_start;
371 compat_ulong_t mem_end;
372 unsigned short base_addr;
373 unsigned char irq;
374 unsigned char dma;
375 unsigned char port;
376};
377
Chris Metcalf4800a5b2011-05-17 14:41:06 -0400378struct compat_if_settings {
Arnd Bergmann7a50a242009-11-08 20:57:03 -0800379 unsigned int type; /* Type of physical device or protocol */
380 unsigned int size; /* Size of the data allocated by the caller */
381 compat_uptr_t ifs_ifsu; /* union of pointers */
382};
383
Arnd Bergmann2dceba12009-11-06 08:09:03 +0000384struct compat_ifreq {
Arnd Bergmann7a50a242009-11-08 20:57:03 -0800385 union {
386 char ifrn_name[IFNAMSIZ]; /* if name, e.g. "en0" */
387 } ifr_ifrn;
388 union {
389 struct sockaddr ifru_addr;
390 struct sockaddr ifru_dstaddr;
391 struct sockaddr ifru_broadaddr;
392 struct sockaddr ifru_netmask;
393 struct sockaddr ifru_hwaddr;
394 short ifru_flags;
395 compat_int_t ifru_ivalue;
396 compat_int_t ifru_mtu;
397 struct compat_ifmap ifru_map;
398 char ifru_slave[IFNAMSIZ]; /* Just fits the size */
Arnd Bergmann2dceba12009-11-06 08:09:03 +0000399 char ifru_newname[IFNAMSIZ];
Arnd Bergmann7a50a242009-11-08 20:57:03 -0800400 compat_caddr_t ifru_data;
401 struct compat_if_settings ifru_settings;
402 } ifr_ifru;
Arnd Bergmann2dceba12009-11-06 08:09:03 +0000403};
404
405struct compat_ifconf {
Chris Metcalf4800a5b2011-05-17 14:41:06 -0400406 compat_int_t ifc_len; /* size of buffer */
407 compat_caddr_t ifcbuf;
Arnd Bergmann2dceba12009-11-06 08:09:03 +0000408};
409
Ingo Molnar34f192c2006-03-27 01:16:24 -0800410struct compat_robust_list {
411 compat_uptr_t next;
412};
413
414struct compat_robust_list_head {
415 struct compat_robust_list list;
416 compat_long_t futex_offset;
417 compat_uptr_t list_op_pending;
418};
419
Al Viro495dfbf2012-12-25 19:09:45 -0500420#ifdef CONFIG_COMPAT_OLD_SIGACTION
421struct compat_old_sigaction {
422 compat_uptr_t sa_handler;
423 compat_old_sigset_t sa_mask;
424 compat_ulong_t sa_flags;
425 compat_uptr_t sa_restorer;
426};
427#endif
428
Stephan Muellerf1c316a2016-08-19 20:39:09 +0200429struct compat_keyctl_kdf_params {
430 compat_uptr_t hashname;
431 compat_uptr_t otherinfo;
432 __u32 otherinfolen;
433 __u32 __spare[8];
434};
435
Chris Metcalfbe84cb42011-05-09 13:12:30 -0400436struct compat_statfs;
437struct compat_statfs64;
438struct compat_old_linux_dirent;
439struct compat_linux_dirent;
440struct linux_dirent64;
441struct compat_msghdr;
442struct compat_mmsghdr;
443struct compat_sysinfo;
444struct compat_sysctl_args;
445struct compat_kexec_segment;
446struct compat_mq_attr;
Chris Metcalf48b25c42012-03-15 13:13:38 -0400447struct compat_msgbuf;
Chris Metcalfbe84cb42011-05-09 13:12:30 -0400448
Ingo Molnar34f192c2006-03-27 01:16:24 -0800449extern void compat_exit_robust_list(struct task_struct *curr);
450
Linus Torvalds1da177e2005-04-16 15:20:36 -0700451#define BITS_PER_COMPAT_LONG (8*sizeof(compat_long_t))
452
Al Viro1e1fc132017-05-30 00:29:38 -0400453#define BITS_TO_COMPAT_LONGS(bits) DIV_ROUND_UP(bits, BITS_PER_COMPAT_LONG)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700454
Stephen Rothwell5fa38392006-10-28 10:38:46 -0700455long compat_get_bitmap(unsigned long *mask, const compat_ulong_t __user *umask,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700456 unsigned long bitmap_size);
457long compat_put_bitmap(compat_ulong_t __user *umask, unsigned long *mask,
458 unsigned long bitmap_size);
Eric W. Biederman212a36a2017-07-31 17:15:31 -0500459int copy_siginfo_from_user32(siginfo_t *to, const struct compat_siginfo __user *from);
Al Viroce395962013-10-13 17:23:53 -0400460int copy_siginfo_to_user32(struct compat_siginfo __user *to, const siginfo_t *from);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700461int get_compat_sigevent(struct sigevent *event,
462 const struct compat_sigevent __user *u_event);
463
Andrew Morton643a6542006-02-11 17:55:52 -0800464static inline int compat_timeval_compare(struct compat_timeval *lhs,
465 struct compat_timeval *rhs)
466{
467 if (lhs->tv_sec < rhs->tv_sec)
468 return -1;
469 if (lhs->tv_sec > rhs->tv_sec)
470 return 1;
471 return lhs->tv_usec - rhs->tv_usec;
472}
473
474static inline int compat_timespec_compare(struct compat_timespec *lhs,
475 struct compat_timespec *rhs)
476{
477 if (lhs->tv_sec < rhs->tv_sec)
478 return -1;
479 if (lhs->tv_sec > rhs->tv_sec)
480 return 1;
481 return lhs->tv_nsec - rhs->tv_nsec;
482}
483
Al Viro3968cf62017-09-03 21:45:17 -0400484extern int get_compat_sigset(sigset_t *set, const compat_sigset_t __user *compat);
Matt Redfearnfde9fc72018-02-19 16:55:06 +0000485
486/*
487 * Defined inline such that size can be compile time constant, which avoids
488 * CONFIG_HARDENED_USERCOPY complaining about copies from task_struct
489 */
490static inline int
491put_compat_sigset(compat_sigset_t __user *compat, const sigset_t *set,
492 unsigned int size)
493{
494 /* size <= sizeof(compat_sigset_t) <= sizeof(sigset_t) */
495#ifdef __BIG_ENDIAN
496 compat_sigset_t v;
497 switch (_NSIG_WORDS) {
498 case 4: v.sig[7] = (set->sig[3] >> 32); v.sig[6] = set->sig[3];
499 case 3: v.sig[5] = (set->sig[2] >> 32); v.sig[4] = set->sig[2];
500 case 2: v.sig[3] = (set->sig[1] >> 32); v.sig[2] = set->sig[1];
501 case 1: v.sig[1] = (set->sig[0] >> 32); v.sig[0] = set->sig[0];
502 }
503 return copy_to_user(compat, &v, size) ? -EFAULT : 0;
504#else
505 return copy_to_user(compat, set, size) ? -EFAULT : 0;
506#endif
507}
Andi Kleenbebfa102006-06-26 13:56:52 +0200508
Roland McGrath032d82d2008-01-30 13:31:47 +0100509extern int compat_ptrace_request(struct task_struct *child,
510 compat_long_t request,
511 compat_ulong_t addr, compat_ulong_t data);
512
Roland McGrathc269f192008-01-30 13:31:48 +0100513extern long compat_arch_ptrace(struct task_struct *child, compat_long_t request,
514 compat_ulong_t addr, compat_ulong_t data);
Roland McGrathc269f192008-01-30 13:31:48 +0100515
Al Viro35280bd2013-02-24 14:52:17 -0500516struct epoll_event; /* fortunately, this one is fixed-layout */
Heiko Carstens4c696ba2009-01-14 14:13:53 +0100517
Jeff Moyerb8373362010-05-26 14:44:25 -0700518extern ssize_t compat_rw_copy_check_uvector(int type,
Chris Metcalf4800a5b2011-05-17 14:41:06 -0400519 const struct compat_iovec __user *uvector,
520 unsigned long nr_segs,
Jeff Moyerb8373362010-05-26 14:44:25 -0700521 unsigned long fast_segs, struct iovec *fast_pointer,
Christopher Yeohac34ebb2012-05-31 16:26:42 -0700522 struct iovec **ret_pointer);
H. Peter Anvinc41d68a2010-09-07 16:16:18 -0700523
524extern void __user *compat_alloc_user_space(unsigned long len);
525
Al Viro90268432012-12-14 14:47:53 -0500526int compat_restore_altstack(const compat_stack_t __user *uss);
Al Viroc40702c2012-11-20 14:24:26 -0500527int __compat_save_altstack(compat_stack_t __user *, unsigned long);
Al Virobd1c149a2013-09-01 20:35:01 +0100528#define compat_save_altstack_ex(uss, sp) do { \
529 compat_stack_t __user *__uss = uss; \
530 struct task_struct *t = current; \
531 put_user_ex(ptr_to_compat((void __user *)t->sas_ss_sp), &__uss->ss_sp); \
Stas Sergeev441398d2017-02-27 14:27:25 -0800532 put_user_ex(t->sas_ss_flags, &__uss->ss_flags); \
Al Virobd1c149a2013-09-01 20:35:01 +0100533 put_user_ex(t->sas_ss_size, &__uss->ss_size); \
Stas Sergeev441398d2017-02-27 14:27:25 -0800534 if (t->sas_ss_flags & SS_AUTODISARM) \
535 sas_ss_reset(t); \
Al Virobd1c149a2013-09-01 20:35:01 +0100536} while (0);
Catalin Marinas8f9c0112012-09-19 12:01:52 +0100537
Dominik Brodowskic679a082018-03-25 23:04:48 +0200538/*
539 * These syscall function prototypes are kept in the same order as
Dominik Brodowski3e2052e2018-03-22 14:09:17 +0100540 * include/uapi/asm-generic/unistd.h. Deprecated or obsolete system calls
541 * go below.
Dominik Brodowskic679a082018-03-25 23:04:48 +0200542 *
543 * Please note that these prototypes here are only provided for information
544 * purposes, for static analysis, and for linking from the syscall table.
545 * These functions should not be called elsewhere from kernel code.
Dominik Brodowski7303e302018-04-05 11:53:03 +0200546 *
547 * As the syscall calling convention may be different from the default
548 * for architectures overriding the syscall calling convention, do not
549 * include the prototypes if CONFIG_ARCH_HAS_SYSCALL_WRAPPER is enabled.
Dominik Brodowskic679a082018-03-25 23:04:48 +0200550 */
Dominik Brodowski7303e302018-04-05 11:53:03 +0200551#ifndef CONFIG_ARCH_HAS_SYSCALL_WRAPPER
Dominik Brodowskic679a082018-03-25 23:04:48 +0200552asmlinkage long compat_sys_io_setup(unsigned nr_reqs, u32 __user *ctx32p);
553asmlinkage long compat_sys_io_submit(compat_aio_context_t ctx_id, int nr,
554 u32 __user *iocb);
555asmlinkage long compat_sys_io_getevents(compat_aio_context_t ctx_id,
556 compat_long_t min_nr,
557 compat_long_t nr,
558 struct io_event __user *events,
559 struct compat_timespec __user *timeout);
560
561/* fs/cookies.c */
562asmlinkage long compat_sys_lookup_dcookie(u32, u32, char __user *, compat_size_t);
563
564/* fs/eventpoll.c */
565asmlinkage long compat_sys_epoll_pwait(int epfd,
566 struct epoll_event __user *events,
567 int maxevents, int timeout,
568 const compat_sigset_t __user *sigmask,
569 compat_size_t sigsetsize);
570
571/* fs/fcntl.c */
572asmlinkage long compat_sys_fcntl(unsigned int fd, unsigned int cmd,
573 compat_ulong_t arg);
574asmlinkage long compat_sys_fcntl64(unsigned int fd, unsigned int cmd,
575 compat_ulong_t arg);
576
577/* fs/ioctl.c */
578asmlinkage long compat_sys_ioctl(unsigned int fd, unsigned int cmd,
579 compat_ulong_t arg);
580
581/* fs/namespace.c */
582asmlinkage long compat_sys_mount(const char __user *dev_name,
583 const char __user *dir_name,
584 const char __user *type, compat_ulong_t flags,
585 const void __user *data);
586
587/* fs/open.c */
588asmlinkage long compat_sys_statfs(const char __user *pathname,
589 struct compat_statfs __user *buf);
590asmlinkage long compat_sys_statfs64(const char __user *pathname,
591 compat_size_t sz,
592 struct compat_statfs64 __user *buf);
593asmlinkage long compat_sys_fstatfs(unsigned int fd,
594 struct compat_statfs __user *buf);
595asmlinkage long compat_sys_fstatfs64(unsigned int fd, compat_size_t sz,
596 struct compat_statfs64 __user *buf);
597asmlinkage long compat_sys_truncate(const char __user *, compat_off_t);
598asmlinkage long compat_sys_ftruncate(unsigned int, compat_ulong_t);
599/* No generic prototype for truncate64, ftruncate64, fallocate */
600asmlinkage long compat_sys_openat(int dfd, const char __user *filename,
601 int flags, umode_t mode);
602
603/* fs/readdir.c */
604asmlinkage long compat_sys_getdents(unsigned int fd,
605 struct compat_linux_dirent __user *dirent,
606 unsigned int count);
607
608/* fs/read_write.c */
609asmlinkage long compat_sys_lseek(unsigned int, compat_off_t, unsigned int);
610asmlinkage ssize_t compat_sys_readv(compat_ulong_t fd,
611 const struct compat_iovec __user *vec, compat_ulong_t vlen);
612asmlinkage ssize_t compat_sys_writev(compat_ulong_t fd,
613 const struct compat_iovec __user *vec, compat_ulong_t vlen);
614/* No generic prototype for pread64 and pwrite64 */
615asmlinkage ssize_t compat_sys_preadv(compat_ulong_t fd,
616 const struct compat_iovec __user *vec,
617 compat_ulong_t vlen, u32 pos_low, u32 pos_high);
618asmlinkage ssize_t compat_sys_pwritev(compat_ulong_t fd,
619 const struct compat_iovec __user *vec,
620 compat_ulong_t vlen, u32 pos_low, u32 pos_high);
621#ifdef __ARCH_WANT_COMPAT_SYS_PREADV64
622asmlinkage long compat_sys_preadv64(unsigned long fd,
623 const struct compat_iovec __user *vec,
624 unsigned long vlen, loff_t pos);
625#endif
626
627#ifdef __ARCH_WANT_COMPAT_SYS_PWRITEV64
628asmlinkage long compat_sys_pwritev64(unsigned long fd,
629 const struct compat_iovec __user *vec,
630 unsigned long vlen, loff_t pos);
631#endif
632
633/* fs/sendfile.c */
634asmlinkage long compat_sys_sendfile(int out_fd, int in_fd,
635 compat_off_t __user *offset, compat_size_t count);
636asmlinkage long compat_sys_sendfile64(int out_fd, int in_fd,
637 compat_loff_t __user *offset, compat_size_t count);
638
639/* fs/select.c */
640asmlinkage long compat_sys_pselect6(int n, compat_ulong_t __user *inp,
641 compat_ulong_t __user *outp,
642 compat_ulong_t __user *exp,
643 struct compat_timespec __user *tsp,
644 void __user *sig);
645asmlinkage long compat_sys_ppoll(struct pollfd __user *ufds,
646 unsigned int nfds,
647 struct compat_timespec __user *tsp,
648 const compat_sigset_t __user *sigmask,
649 compat_size_t sigsetsize);
650
651/* fs/signalfd.c */
652asmlinkage long compat_sys_signalfd4(int ufd,
653 const compat_sigset_t __user *sigmask,
654 compat_size_t sigsetsize, int flags);
655
656/* fs/splice.c */
657asmlinkage long compat_sys_vmsplice(int fd, const struct compat_iovec __user *,
658 unsigned int nr_segs, unsigned int flags);
659
660/* fs/stat.c */
661asmlinkage long compat_sys_newfstatat(unsigned int dfd,
662 const char __user *filename,
663 struct compat_stat __user *statbuf,
664 int flag);
665asmlinkage long compat_sys_newfstat(unsigned int fd,
666 struct compat_stat __user *statbuf);
667
668/* fs/sync.c: No generic prototype for sync_file_range and sync_file_range2 */
669
670/* fs/timerfd.c */
671asmlinkage long compat_sys_timerfd_gettime(int ufd,
672 struct compat_itimerspec __user *otmr);
673asmlinkage long compat_sys_timerfd_settime(int ufd, int flags,
674 const struct compat_itimerspec __user *utmr,
675 struct compat_itimerspec __user *otmr);
676
677/* fs/utimes.c */
678asmlinkage long compat_sys_utimensat(unsigned int dfd,
679 const char __user *filename,
680 struct compat_timespec __user *t,
681 int flags);
682
683/* kernel/exit.c */
684asmlinkage long compat_sys_waitid(int, compat_pid_t,
685 struct compat_siginfo __user *, int,
686 struct compat_rusage __user *);
687
688
689
690/* kernel/futex.c */
691asmlinkage long compat_sys_futex(u32 __user *uaddr, int op, u32 val,
692 struct compat_timespec __user *utime, u32 __user *uaddr2,
693 u32 val3);
694asmlinkage long
695compat_sys_set_robust_list(struct compat_robust_list_head __user *head,
696 compat_size_t len);
697asmlinkage long
698compat_sys_get_robust_list(int pid, compat_uptr_t __user *head_ptr,
699 compat_size_t __user *len_ptr);
700
701/* kernel/hrtimer.c */
702asmlinkage long compat_sys_nanosleep(struct compat_timespec __user *rqtp,
703 struct compat_timespec __user *rmtp);
704
705/* kernel/itimer.c */
706asmlinkage long compat_sys_getitimer(int which,
707 struct compat_itimerval __user *it);
708asmlinkage long compat_sys_setitimer(int which,
709 struct compat_itimerval __user *in,
710 struct compat_itimerval __user *out);
711
712/* kernel/kexec.c */
713asmlinkage long compat_sys_kexec_load(compat_ulong_t entry,
714 compat_ulong_t nr_segments,
715 struct compat_kexec_segment __user *,
716 compat_ulong_t flags);
717
718/* kernel/posix-timers.c */
719asmlinkage long compat_sys_timer_create(clockid_t which_clock,
720 struct compat_sigevent __user *timer_event_spec,
721 timer_t __user *created_timer_id);
722asmlinkage long compat_sys_timer_gettime(timer_t timer_id,
723 struct compat_itimerspec __user *setting);
724asmlinkage long compat_sys_timer_settime(timer_t timer_id, int flags,
725 struct compat_itimerspec __user *new,
726 struct compat_itimerspec __user *old);
727asmlinkage long compat_sys_clock_settime(clockid_t which_clock,
728 struct compat_timespec __user *tp);
729asmlinkage long compat_sys_clock_gettime(clockid_t which_clock,
730 struct compat_timespec __user *tp);
731asmlinkage long compat_sys_clock_getres(clockid_t which_clock,
732 struct compat_timespec __user *tp);
733asmlinkage long compat_sys_clock_nanosleep(clockid_t which_clock, int flags,
734 struct compat_timespec __user *rqtp,
735 struct compat_timespec __user *rmtp);
736
737/* kernel/ptrace.c */
738asmlinkage long compat_sys_ptrace(compat_long_t request, compat_long_t pid,
739 compat_long_t addr, compat_long_t data);
740
741/* kernel/sched/core.c */
742asmlinkage long compat_sys_sched_setaffinity(compat_pid_t pid,
743 unsigned int len,
744 compat_ulong_t __user *user_mask_ptr);
745asmlinkage long compat_sys_sched_getaffinity(compat_pid_t pid,
746 unsigned int len,
747 compat_ulong_t __user *user_mask_ptr);
Catalin Marinas0ad50c32012-12-17 16:01:45 -0800748asmlinkage long compat_sys_sched_rr_get_interval(compat_pid_t pid,
749 struct compat_timespec __user *interval);
750
Dominik Brodowskic679a082018-03-25 23:04:48 +0200751/* kernel/signal.c */
752asmlinkage long compat_sys_sigaltstack(const compat_stack_t __user *uss_ptr,
753 compat_stack_t __user *uoss_ptr);
754asmlinkage long compat_sys_rt_sigsuspend(compat_sigset_t __user *unewset,
755 compat_size_t sigsetsize);
756#ifndef CONFIG_ODD_RT_SIGACTION
757asmlinkage long compat_sys_rt_sigaction(int,
758 const struct compat_sigaction __user *,
759 struct compat_sigaction __user *,
760 compat_size_t);
761#endif
762asmlinkage long compat_sys_rt_sigprocmask(int how, compat_sigset_t __user *set,
763 compat_sigset_t __user *oset,
764 compat_size_t sigsetsize);
765asmlinkage long compat_sys_rt_sigpending(compat_sigset_t __user *uset,
766 compat_size_t sigsetsize);
767asmlinkage long compat_sys_rt_sigtimedwait(compat_sigset_t __user *uthese,
768 struct compat_siginfo __user *uinfo,
769 struct compat_timespec __user *uts, compat_size_t sigsetsize);
770asmlinkage long compat_sys_rt_sigqueueinfo(compat_pid_t pid, int sig,
771 struct compat_siginfo __user *uinfo);
772/* No generic prototype for rt_sigreturn */
773
774/* kernel/sys.c */
775asmlinkage long compat_sys_times(struct compat_tms __user *tbuf);
776asmlinkage long compat_sys_getrlimit(unsigned int resource,
777 struct compat_rlimit __user *rlim);
778asmlinkage long compat_sys_setrlimit(unsigned int resource,
779 struct compat_rlimit __user *rlim);
780asmlinkage long compat_sys_getrusage(int who, struct compat_rusage __user *ru);
781
782/* kernel/time.c */
783asmlinkage long compat_sys_gettimeofday(struct compat_timeval __user *tv,
784 struct timezone __user *tz);
785asmlinkage long compat_sys_settimeofday(struct compat_timeval __user *tv,
786 struct timezone __user *tz);
787asmlinkage long compat_sys_adjtimex(struct compat_timex __user *utp);
788
789/* kernel/timer.c */
790asmlinkage long compat_sys_sysinfo(struct compat_sysinfo __user *info);
791
792/* ipc/mqueue.c */
793asmlinkage long compat_sys_mq_open(const char __user *u_name,
794 int oflag, compat_mode_t mode,
795 struct compat_mq_attr __user *u_attr);
796asmlinkage long compat_sys_mq_timedsend(mqd_t mqdes,
797 const char __user *u_msg_ptr,
798 compat_size_t msg_len, unsigned int msg_prio,
799 const struct compat_timespec __user *u_abs_timeout);
800asmlinkage ssize_t compat_sys_mq_timedreceive(mqd_t mqdes,
801 char __user *u_msg_ptr,
802 compat_size_t msg_len, unsigned int __user *u_msg_prio,
803 const struct compat_timespec __user *u_abs_timeout);
804asmlinkage long compat_sys_mq_notify(mqd_t mqdes,
805 const struct compat_sigevent __user *u_notification);
806asmlinkage long compat_sys_mq_getsetattr(mqd_t mqdes,
807 const struct compat_mq_attr __user *u_mqstat,
808 struct compat_mq_attr __user *u_omqstat);
809
810/* ipc/msg.c */
811asmlinkage long compat_sys_msgctl(int first, int second, void __user *uptr);
812asmlinkage long compat_sys_msgrcv(int msqid, compat_uptr_t msgp,
813 compat_ssize_t msgsz, compat_long_t msgtyp, int msgflg);
814asmlinkage long compat_sys_msgsnd(int msqid, compat_uptr_t msgp,
815 compat_ssize_t msgsz, int msgflg);
816
817/* ipc/sem.c */
818asmlinkage long compat_sys_semctl(int semid, int semnum, int cmd, int arg);
819asmlinkage long compat_sys_semtimedop(int semid, struct sembuf __user *tsems,
820 unsigned nsems, const struct compat_timespec __user *timeout);
821
822/* ipc/shm.c */
823asmlinkage long compat_sys_shmctl(int first, int second, void __user *uptr);
824asmlinkage long compat_sys_shmat(int shmid, compat_uptr_t shmaddr, int shmflg);
825
826/* net/socket.c */
827asmlinkage long compat_sys_recvfrom(int fd, void __user *buf, compat_size_t len,
828 unsigned flags, struct sockaddr __user *addr,
829 int __user *addrlen);
830asmlinkage long compat_sys_setsockopt(int fd, int level, int optname,
831 char __user *optval, unsigned int optlen);
832asmlinkage long compat_sys_getsockopt(int fd, int level, int optname,
833 char __user *optval, int __user *optlen);
834asmlinkage long compat_sys_sendmsg(int fd, struct compat_msghdr __user *msg,
835 unsigned flags);
836asmlinkage long compat_sys_recvmsg(int fd, struct compat_msghdr __user *msg,
837 unsigned int flags);
838
839/* mm/filemap.c: No generic prototype for readahead */
840
841/* security/keys/keyctl.c */
842asmlinkage long compat_sys_keyctl(u32 option,
843 u32 arg2, u32 arg3, u32 arg4, u32 arg5);
844
845/* arch/example/kernel/sys_example.c */
846asmlinkage long compat_sys_execve(const char __user *filename, const compat_uptr_t __user *argv,
847 const compat_uptr_t __user *envp);
848
849/* mm/fadvise.c: No generic prototype for fadvise64_64 */
850
851/* mm/, CONFIG_MMU only */
852asmlinkage long compat_sys_mbind(compat_ulong_t start, compat_ulong_t len,
853 compat_ulong_t mode,
854 compat_ulong_t __user *nmask,
855 compat_ulong_t maxnode, compat_ulong_t flags);
856asmlinkage long compat_sys_get_mempolicy(int __user *policy,
857 compat_ulong_t __user *nmask,
858 compat_ulong_t maxnode,
859 compat_ulong_t addr,
860 compat_ulong_t flags);
861asmlinkage long compat_sys_set_mempolicy(int mode, compat_ulong_t __user *nmask,
862 compat_ulong_t maxnode);
863asmlinkage long compat_sys_migrate_pages(compat_pid_t pid,
864 compat_ulong_t maxnode, const compat_ulong_t __user *old_nodes,
865 const compat_ulong_t __user *new_nodes);
866asmlinkage long compat_sys_move_pages(pid_t pid, compat_ulong_t nr_pages,
867 __u32 __user *pages,
868 const int __user *nodes,
869 int __user *status,
870 int flags);
871
872asmlinkage long compat_sys_rt_tgsigqueueinfo(compat_pid_t tgid,
873 compat_pid_t pid, int sig,
874 struct compat_siginfo __user *uinfo);
875asmlinkage long compat_sys_recvmmsg(int fd, struct compat_mmsghdr __user *mmsg,
876 unsigned vlen, unsigned int flags,
877 struct compat_timespec __user *timeout);
878asmlinkage long compat_sys_wait4(compat_pid_t pid,
879 compat_uint_t __user *stat_addr, int options,
880 struct compat_rusage __user *ru);
Al Viro91c2e0b2013-03-05 20:10:59 -0500881asmlinkage long compat_sys_fanotify_mark(int, unsigned int, __u32, __u32,
882 int, const char __user *);
Dominik Brodowskic679a082018-03-25 23:04:48 +0200883asmlinkage long compat_sys_open_by_handle_at(int mountdirfd,
884 struct file_handle __user *handle,
885 int flags);
886asmlinkage long compat_sys_clock_adjtime(clockid_t which_clock,
887 struct compat_timex __user *tp);
888asmlinkage long compat_sys_sendmmsg(int fd, struct compat_mmsghdr __user *mmsg,
889 unsigned vlen, unsigned int flags);
890asmlinkage ssize_t compat_sys_process_vm_readv(compat_pid_t pid,
891 const struct compat_iovec __user *lvec,
892 compat_ulong_t liovcnt, const struct compat_iovec __user *rvec,
893 compat_ulong_t riovcnt, compat_ulong_t flags);
894asmlinkage ssize_t compat_sys_process_vm_writev(compat_pid_t pid,
895 const struct compat_iovec __user *lvec,
896 compat_ulong_t liovcnt, const struct compat_iovec __user *rvec,
897 compat_ulong_t riovcnt, compat_ulong_t flags);
898asmlinkage long compat_sys_execveat(int dfd, const char __user *filename,
899 const compat_uptr_t __user *argv,
900 const compat_uptr_t __user *envp, int flags);
901asmlinkage ssize_t compat_sys_preadv2(compat_ulong_t fd,
902 const struct compat_iovec __user *vec,
903 compat_ulong_t vlen, u32 pos_low, u32 pos_high, rwf_t flags);
904asmlinkage ssize_t compat_sys_pwritev2(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#ifdef __ARCH_WANT_COMPAT_SYS_PREADV64V2
908asmlinkage long compat_sys_readv64v2(unsigned long fd,
909 const struct compat_iovec __user *vec,
910 unsigned long vlen, loff_t pos, rwf_t flags);
911#endif
Andy Lutomirski5180e3e2016-03-22 14:24:43 -0700912
Dominik Brodowskic679a082018-03-25 23:04:48 +0200913#ifdef __ARCH_WANT_COMPAT_SYS_PWRITEV64V2
914asmlinkage long compat_sys_pwritev64v2(unsigned long fd,
915 const struct compat_iovec __user *vec,
916 unsigned long vlen, loff_t pos, rwf_t flags);
917#endif
918
919
920/*
Dominik Brodowskic679a082018-03-25 23:04:48 +0200921 * Deprecated system calls which are still defined in
922 * include/uapi/asm-generic/unistd.h and wanted by >= 1 arch
923 */
924
925/* __ARCH_WANT_SYSCALL_NO_AT */
926asmlinkage long compat_sys_open(const char __user *filename, int flags,
927 umode_t mode);
928asmlinkage long compat_sys_utimes(const char __user *filename,
929 struct compat_timeval __user *t);
930
931/* __ARCH_WANT_SYSCALL_NO_FLAGS */
932asmlinkage long compat_sys_signalfd(int ufd,
933 const compat_sigset_t __user *sigmask,
934 compat_size_t sigsetsize);
935
936/* __ARCH_WANT_SYSCALL_OFF_T */
937asmlinkage long compat_sys_newstat(const char __user *filename,
938 struct compat_stat __user *statbuf);
939asmlinkage long compat_sys_newlstat(const char __user *filename,
940 struct compat_stat __user *statbuf);
941
942/* __ARCH_WANT_SYSCALL_DEPRECATED */
943asmlinkage long compat_sys_time(compat_time_t __user *tloc);
944asmlinkage long compat_sys_utime(const char __user *filename,
945 struct compat_utimbuf __user *t);
946asmlinkage long compat_sys_futimesat(unsigned int dfd,
947 const char __user *filename,
948 struct compat_timeval __user *t);
949asmlinkage long compat_sys_select(int n, compat_ulong_t __user *inp,
950 compat_ulong_t __user *outp, compat_ulong_t __user *exp,
951 struct compat_timeval __user *tvp);
952asmlinkage long compat_sys_ustat(unsigned dev, struct compat_ustat __user *u32);
953asmlinkage long compat_sys_recv(int fd, void __user *buf, compat_size_t len,
954 unsigned flags);
955asmlinkage long compat_sys_sysctl(struct compat_sysctl_args __user *args);
956
957/* obsolete: fs/readdir.c */
958asmlinkage long compat_sys_old_readdir(unsigned int fd,
959 struct compat_old_linux_dirent __user *,
960 unsigned int count);
961
962/* obsolete: fs/select.c */
963asmlinkage long compat_sys_old_select(struct compat_sel_arg_struct __user *arg);
964
965/* obsolete: ipc */
966asmlinkage long compat_sys_ipc(u32, int, int, u32, compat_uptr_t, u32);
967
968/* obsolete: kernel/signal.c */
969#ifdef __ARCH_WANT_SYS_SIGPENDING
970asmlinkage long compat_sys_sigpending(compat_old_sigset_t __user *set);
971#endif
972
973#ifdef __ARCH_WANT_SYS_SIGPROCMASK
974asmlinkage long compat_sys_sigprocmask(int how, compat_old_sigset_t __user *nset,
975 compat_old_sigset_t __user *oset);
976#endif
977#ifdef CONFIG_COMPAT_OLD_SIGACTION
978asmlinkage long compat_sys_sigaction(int sig,
979 const struct compat_old_sigaction __user *act,
980 struct compat_old_sigaction __user *oact);
981#endif
982
983/* obsolete: kernel/time/time.c */
984asmlinkage long compat_sys_stime(compat_time_t __user *tptr);
985
986/* obsolete: net/socket.c */
987asmlinkage long compat_sys_socketcall(int call, u32 __user *args);
988
Dominik Brodowski7303e302018-04-05 11:53:03 +0200989#endif /* CONFIG_ARCH_HAS_SYSCALL_WRAPPER */
990
Dominik Brodowskic679a082018-03-25 23:04:48 +0200991
Andy Lutomirski5180e3e2016-03-22 14:24:43 -0700992/*
993 * For most but not all architectures, "am I in a compat syscall?" and
994 * "am I a compat task?" are the same question. For architectures on which
995 * they aren't the same question, arch code can override in_compat_syscall.
996 */
997
998#ifndef in_compat_syscall
999static inline bool in_compat_syscall(void) { return is_compat_task(); }
1000#endif
1001
Frederic Weisbeckercd19c362017-01-31 04:09:27 +01001002/**
1003 * ns_to_compat_timeval - Compat version of ns_to_timeval
1004 * @nsec: the nanoseconds value to be converted
1005 *
1006 * Returns the compat_timeval representation of the nsec parameter.
1007 */
1008static inline struct compat_timeval ns_to_compat_timeval(s64 nsec)
1009{
1010 struct timeval tv;
1011 struct compat_timeval ctv;
1012
1013 tv = ns_to_timeval(nsec);
1014 ctv.tv_sec = tv.tv_sec;
1015 ctv.tv_usec = tv.tv_usec;
1016
1017 return ctv;
1018}
1019
1020#else /* !CONFIG_COMPAT */
Linus Torvalds3c761ea2012-02-26 09:44:55 -08001021
1022#define is_compat_task() (0)
Deepa Dinamani5055c672018-03-13 21:03:24 -07001023#ifndef in_compat_syscall
Andy Lutomirski5180e3e2016-03-22 14:24:43 -07001024static inline bool in_compat_syscall(void) { return false; }
Deepa Dinamani5055c672018-03-13 21:03:24 -07001025#endif
Linus Torvalds3c761ea2012-02-26 09:44:55 -08001026
Linus Torvalds1da177e2005-04-16 15:20:36 -07001027#endif /* CONFIG_COMPAT */
Andy Lutomirski5180e3e2016-03-22 14:24:43 -07001028
Linus Torvalds1da177e2005-04-16 15:20:36 -07001029#endif /* _LINUX_COMPAT_H */