blob: 48d29b1339bed1a029da276a1dc8a80c442dfeea [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>
10
Linus Torvalds1da177e2005-04-16 15:20:36 -070011#include <linux/stat.h>
12#include <linux/param.h> /* for HZ */
13#include <linux/sem.h>
Arnd Bergmann2dceba12009-11-06 08:09:03 +000014#include <linux/socket.h>
15#include <linux/if.h>
Chris Metcalfbe84cb42011-05-09 13:12:30 -040016#include <linux/fs.h>
Stephen Rothwell45e96832011-05-24 13:28:54 +100017#include <linux/aio_abi.h> /* for aio_context_t */
Matt Redfearnfde9fc72018-02-19 16:55:06 +000018#include <linux/uaccess.h>
Heiko Carstensf5b972e2014-03-20 15:30:14 +010019#include <linux/unistd.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070020
21#include <asm/compat.h>
Arnd Bergmann2b5a9a32018-03-26 16:59:15 +020022
23#ifdef CONFIG_COMPAT
Linus Torvalds1da177e2005-04-16 15:20:36 -070024#include <asm/siginfo.h>
David Howells3f2e05e2006-10-02 14:12:31 +010025#include <asm/signal.h>
Deepa Dinamani5055c672018-03-13 21:03:24 -070026#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -070027
Dominik Brodowski7303e302018-04-05 11:53:03 +020028#ifdef CONFIG_ARCH_HAS_SYSCALL_WRAPPER
29/*
30 * It may be useful for an architecture to override the definitions of the
31 * COMPAT_SYSCALL_DEFINE0 and COMPAT_SYSCALL_DEFINEx() macros, in particular
32 * to use a different calling convention for syscalls. To allow for that,
33 + the prototypes for the compat_sys_*() functions below will *not* be included
34 * if CONFIG_ARCH_HAS_SYSCALL_WRAPPER is enabled.
35 */
36#include <asm/syscall_wrapper.h>
37#endif /* CONFIG_ARCH_HAS_SYSCALL_WRAPPER */
38
H. J. Lu45e87782012-02-10 14:04:27 -080039#ifndef COMPAT_USE_64BIT_TIME
40#define COMPAT_USE_64BIT_TIME 0
41#endif
42
Al Viro46836612012-11-23 09:12:59 -050043#ifndef __SC_DELOUSE
Al Viro4f59c712017-07-08 11:40:39 -040044#define __SC_DELOUSE(t,v) ((__force t)(unsigned long)(v))
Al Viro46836612012-11-23 09:12:59 -050045#endif
46
Dominik Brodowski7303e302018-04-05 11:53:03 +020047#ifndef COMPAT_SYSCALL_DEFINE0
Heiko Carstens217f4432014-02-26 10:56:20 +010048#define COMPAT_SYSCALL_DEFINE0(name) \
Howard McLauchlanc9a21192018-03-21 18:59:08 -070049 asmlinkage long compat_sys_##name(void); \
50 ALLOW_ERROR_INJECTION(compat_sys_##name, ERRNO); \
Heiko Carstens217f4432014-02-26 10:56:20 +010051 asmlinkage long compat_sys_##name(void)
Dominik Brodowski7303e302018-04-05 11:53:03 +020052#endif /* COMPAT_SYSCALL_DEFINE0 */
Heiko Carstens217f4432014-02-26 10:56:20 +010053
Al Viro46836612012-11-23 09:12:59 -050054#define COMPAT_SYSCALL_DEFINE1(name, ...) \
55 COMPAT_SYSCALL_DEFINEx(1, _##name, __VA_ARGS__)
56#define COMPAT_SYSCALL_DEFINE2(name, ...) \
57 COMPAT_SYSCALL_DEFINEx(2, _##name, __VA_ARGS__)
58#define COMPAT_SYSCALL_DEFINE3(name, ...) \
59 COMPAT_SYSCALL_DEFINEx(3, _##name, __VA_ARGS__)
60#define COMPAT_SYSCALL_DEFINE4(name, ...) \
61 COMPAT_SYSCALL_DEFINEx(4, _##name, __VA_ARGS__)
62#define COMPAT_SYSCALL_DEFINE5(name, ...) \
63 COMPAT_SYSCALL_DEFINEx(5, _##name, __VA_ARGS__)
64#define COMPAT_SYSCALL_DEFINE6(name, ...) \
65 COMPAT_SYSCALL_DEFINEx(6, _##name, __VA_ARGS__)
66
Dominik Brodowski5ac9efa2018-04-09 12:51:43 +020067/*
68 * The asmlinkage stub is aliased to a function named __se_compat_sys_*() which
69 * sign-extends 32-bit ints to longs whenever needed. The actual work is
70 * done within __do_compat_sys_*().
71 */
Dominik Brodowski7303e302018-04-05 11:53:03 +020072#ifndef COMPAT_SYSCALL_DEFINEx
Dominik Brodowski5ac9efa2018-04-09 12:51:43 +020073#define COMPAT_SYSCALL_DEFINEx(x, name, ...) \
74 asmlinkage long compat_sys##name(__MAP(x,__SC_DECL,__VA_ARGS__)); \
75 asmlinkage long compat_sys##name(__MAP(x,__SC_DECL,__VA_ARGS__)) \
76 __attribute__((alias(__stringify(__se_compat_sys##name)))); \
77 ALLOW_ERROR_INJECTION(compat_sys##name, ERRNO); \
78 static inline long __do_compat_sys##name(__MAP(x,__SC_DECL,__VA_ARGS__));\
79 asmlinkage long __se_compat_sys##name(__MAP(x,__SC_LONG,__VA_ARGS__)); \
80 asmlinkage long __se_compat_sys##name(__MAP(x,__SC_LONG,__VA_ARGS__)) \
81 { \
82 return __do_compat_sys##name(__MAP(x,__SC_DELOUSE,__VA_ARGS__));\
83 } \
84 static inline long __do_compat_sys##name(__MAP(x,__SC_DECL,__VA_ARGS__))
Dominik Brodowski7303e302018-04-05 11:53:03 +020085#endif /* COMPAT_SYSCALL_DEFINEx */
Al Viro46836612012-11-23 09:12:59 -050086
Deepa Dinamani5055c672018-03-13 21:03:24 -070087#ifdef CONFIG_COMPAT
88
Al Viro9b064fc2012-12-14 13:49:35 -050089#ifndef compat_user_stack_pointer
90#define compat_user_stack_pointer() current_user_stack_pointer()
91#endif
Al Viro90268432012-12-14 14:47:53 -050092#ifndef compat_sigaltstack /* we'll need that for MIPS */
93typedef struct compat_sigaltstack {
94 compat_uptr_t ss_sp;
95 int ss_flags;
96 compat_size_t ss_size;
97} compat_stack_t;
98#endif
Al Viro90268432012-12-14 14:47:53 -050099
Linus Torvalds1da177e2005-04-16 15:20:36 -0700100#define compat_jiffies_to_clock_t(x) \
101 (((unsigned long)(x) * COMPAT_USER_HZ) / HZ)
102
Stephen Rothwell202e5972005-09-06 15:16:40 -0700103typedef __compat_uid32_t compat_uid_t;
104typedef __compat_gid32_t compat_gid_t;
105
Heiko Carstens932602e2014-03-04 16:07:52 +0100106typedef compat_ulong_t compat_aio_context_t;
107
Christoph Hellwig5d0e5282010-03-10 15:21:13 -0800108struct compat_sel_arg_struct;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700109struct rusage;
110
Chris Metcalf4800a5b2011-05-17 14:41:06 -0400111struct compat_itimerspec {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700112 struct compat_timespec it_interval;
113 struct compat_timespec it_value;
114};
115
116struct compat_utimbuf {
117 compat_time_t actime;
118 compat_time_t modtime;
119};
120
121struct compat_itimerval {
122 struct compat_timeval it_interval;
123 struct compat_timeval it_value;
124};
125
Al Viro54ad9c42017-06-07 09:42:37 +0100126struct itimerval;
127int get_compat_itimerval(struct itimerval *, const struct compat_itimerval __user *);
128int put_compat_itimerval(struct compat_itimerval __user *, const struct itimerval *);
129
Linus Torvalds1da177e2005-04-16 15:20:36 -0700130struct compat_tms {
131 compat_clock_t tms_utime;
132 compat_clock_t tms_stime;
133 compat_clock_t tms_cutime;
134 compat_clock_t tms_cstime;
135};
136
Stephen Rothwell88959ea2006-03-26 01:37:27 -0800137struct compat_timex {
138 compat_uint_t modes;
139 compat_long_t offset;
140 compat_long_t freq;
141 compat_long_t maxerror;
142 compat_long_t esterror;
143 compat_int_t status;
144 compat_long_t constant;
145 compat_long_t precision;
146 compat_long_t tolerance;
147 struct compat_timeval time;
148 compat_long_t tick;
149 compat_long_t ppsfreq;
150 compat_long_t jitter;
151 compat_int_t shift;
152 compat_long_t stabil;
153 compat_long_t jitcnt;
154 compat_long_t calcnt;
155 compat_long_t errcnt;
156 compat_long_t stbcnt;
Roman Zippel153b5d02008-05-01 04:34:37 -0700157 compat_int_t tai;
Stephen Rothwell88959ea2006-03-26 01:37:27 -0800158
Chris Metcalf4800a5b2011-05-17 14:41:06 -0400159 compat_int_t:32; compat_int_t:32; compat_int_t:32; compat_int_t:32;
160 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;
Stephen Rothwell88959ea2006-03-26 01:37:27 -0800162};
163
Al Viro3a4d44b2017-06-07 09:42:34 +0100164struct timex;
165int compat_get_timex(struct timex *, const struct compat_timex __user *);
166int compat_put_timex(struct compat_timex __user *, const struct timex *);
167
Linus Torvalds1da177e2005-04-16 15:20:36 -0700168#define _COMPAT_NSIG_WORDS (_COMPAT_NSIG / _COMPAT_NSIG_BPW)
169
170typedef struct {
171 compat_sigset_word sig[_COMPAT_NSIG_WORDS];
172} compat_sigset_t;
173
Al Viro08d32fe2012-12-25 18:38:15 -0500174struct compat_sigaction {
David Howells2a148692013-03-19 14:00:53 +0000175#ifndef __ARCH_HAS_IRIX_SIGACTION
Al Viro08d32fe2012-12-25 18:38:15 -0500176 compat_uptr_t sa_handler;
177 compat_ulong_t sa_flags;
178#else
David Howells2a148692013-03-19 14:00:53 +0000179 compat_uint_t sa_flags;
Al Viro08d32fe2012-12-25 18:38:15 -0500180 compat_uptr_t sa_handler;
181#endif
182#ifdef __ARCH_HAS_SA_RESTORER
183 compat_uptr_t sa_restorer;
184#endif
185 compat_sigset_t sa_mask __packed;
186};
Al Viro08d32fe2012-12-25 18:38:15 -0500187
Al Virob713da62017-07-09 15:53:17 -0400188typedef union compat_sigval {
189 compat_int_t sival_int;
190 compat_uptr_t sival_ptr;
191} compat_sigval_t;
192
193typedef struct compat_siginfo {
194 int si_signo;
195#ifndef __ARCH_HAS_SWAPPED_SIGINFO
196 int si_errno;
197 int si_code;
198#else
199 int si_code;
200 int si_errno;
201#endif
202
203 union {
204 int _pad[128/sizeof(int) - 3];
205
206 /* kill() */
207 struct {
208 compat_pid_t _pid; /* sender's pid */
209 __compat_uid32_t _uid; /* sender's uid */
210 } _kill;
211
212 /* POSIX.1b timers */
213 struct {
214 compat_timer_t _tid; /* timer id */
215 int _overrun; /* overrun count */
216 compat_sigval_t _sigval; /* same as below */
217 } _timer;
218
219 /* POSIX.1b signals */
220 struct {
221 compat_pid_t _pid; /* sender's pid */
222 __compat_uid32_t _uid; /* sender's uid */
223 compat_sigval_t _sigval;
224 } _rt;
225
226 /* SIGCHLD */
227 struct {
228 compat_pid_t _pid; /* which child */
229 __compat_uid32_t _uid; /* sender's uid */
230 int _status; /* exit code */
231 compat_clock_t _utime;
232 compat_clock_t _stime;
233 } _sigchld;
234
235#ifdef CONFIG_X86_X32_ABI
236 /* SIGCHLD (x32 version) */
237 struct {
238 compat_pid_t _pid; /* which child */
239 __compat_uid32_t _uid; /* sender's uid */
240 int _status; /* exit code */
241 compat_s64 _utime;
242 compat_s64 _stime;
243 } _sigchld_x32;
244#endif
245
246 /* SIGILL, SIGFPE, SIGSEGV, SIGBUS, SIGTRAP, SIGEMT */
247 struct {
248 compat_uptr_t _addr; /* faulting insn/memory ref. */
249#ifdef __ARCH_SI_TRAPNO
250 int _trapno; /* TRAP # which caused the signal */
251#endif
Eric W. Biederman8420f712018-04-02 14:45:42 -0500252#define __COMPAT_ADDR_BND_PKEY_PAD (__alignof__(compat_uptr_t) < sizeof(short) ? \
253 sizeof(short) : __alignof__(compat_uptr_t))
Al Virob713da62017-07-09 15:53:17 -0400254 union {
Eric W. Biedermanb68a68d2017-07-31 10:08:59 -0500255 /*
256 * used when si_code=BUS_MCEERR_AR or
257 * used when si_code=BUS_MCEERR_AO
258 */
259 short int _addr_lsb; /* Valid LSB of the reported address. */
Al Virob713da62017-07-09 15:53:17 -0400260 /* used when si_code=SEGV_BNDERR */
261 struct {
Eric W. Biederman8420f712018-04-02 14:45:42 -0500262 char _dummy_bnd[__COMPAT_ADDR_BND_PKEY_PAD];
Al Virob713da62017-07-09 15:53:17 -0400263 compat_uptr_t _lower;
264 compat_uptr_t _upper;
265 } _addr_bnd;
266 /* used when si_code=SEGV_PKUERR */
Eric W. Biedermanb68a68d2017-07-31 10:08:59 -0500267 struct {
Eric W. Biederman8420f712018-04-02 14:45:42 -0500268 char _dummy_pkey[__COMPAT_ADDR_BND_PKEY_PAD];
Eric W. Biedermanb68a68d2017-07-31 10:08:59 -0500269 u32 _pkey;
270 } _addr_pkey;
Al Virob713da62017-07-09 15:53:17 -0400271 };
272 } _sigfault;
273
274 /* SIGPOLL */
275 struct {
276 compat_long_t _band; /* POLL_IN, POLL_OUT, POLL_MSG */
277 int _fd;
278 } _sigpoll;
279
280 struct {
281 compat_uptr_t _call_addr; /* calling user insn */
282 int _syscall; /* triggering system call number */
283 unsigned int _arch; /* AUDIT_ARCH_* of syscall */
284 } _sigsys;
285 } _sifields;
286} compat_siginfo_t;
287
H. Peter Anvin6684ba22012-02-19 17:38:00 -0800288/*
H. Peter Anvin6684ba22012-02-19 17:38:00 -0800289 * These functions operate on 32- or 64-bit specs depending on
H. Peter Anvin81993e82014-02-01 18:54:11 -0800290 * COMPAT_USE_64BIT_TIME, hence the void user pointer arguments.
H. Peter Anvin6684ba22012-02-19 17:38:00 -0800291 */
292extern int compat_get_timespec(struct timespec *, const void __user *);
293extern int compat_put_timespec(const struct timespec *, void __user *);
294extern int compat_get_timeval(struct timeval *, const void __user *);
295extern int compat_put_timeval(const struct timeval *, void __user *);
Deepa Dinamanif59dd9c2017-06-24 11:45:02 -0700296extern int compat_get_timespec64(struct timespec64 *, const void __user *);
297extern int compat_put_timespec64(const struct timespec64 *, void __user *);
Deepa Dinamanid5b7ffb2017-06-24 11:45:03 -0700298extern int get_compat_itimerspec64(struct itimerspec64 *its,
299 const struct compat_itimerspec __user *uits);
300extern int put_compat_itimerspec64(const struct itimerspec64 *its,
301 struct compat_itimerspec __user *uits);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700302
303struct compat_iovec {
304 compat_uptr_t iov_base;
305 compat_size_t iov_len;
306};
307
308struct compat_rlimit {
309 compat_ulong_t rlim_cur;
310 compat_ulong_t rlim_max;
311};
312
313struct compat_rusage {
314 struct compat_timeval ru_utime;
315 struct compat_timeval ru_stime;
316 compat_long_t ru_maxrss;
317 compat_long_t ru_ixrss;
318 compat_long_t ru_idrss;
319 compat_long_t ru_isrss;
320 compat_long_t ru_minflt;
321 compat_long_t ru_majflt;
322 compat_long_t ru_nswap;
323 compat_long_t ru_inblock;
324 compat_long_t ru_oublock;
325 compat_long_t ru_msgsnd;
326 compat_long_t ru_msgrcv;
327 compat_long_t ru_nsignals;
328 compat_long_t ru_nvcsw;
329 compat_long_t ru_nivcsw;
330};
331
Chris Metcalf4800a5b2011-05-17 14:41:06 -0400332extern int put_compat_rusage(const struct rusage *,
333 struct compat_rusage __user *);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700334
335struct compat_siginfo;
336
Linus Torvalds1da177e2005-04-16 15:20:36 -0700337struct compat_dirent {
338 u32 d_ino;
339 compat_off_t d_off;
340 u16 d_reclen;
341 char d_name[256];
342};
343
Christoph Hellwig2b1c6bd2008-11-28 10:09:09 +0100344struct 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
Linus Torvalds1da177e2005-04-16 15:20:36 -0700351#define COMPAT_SIGEV_PAD_SIZE ((SIGEV_MAX_SIZE/sizeof(int)) - 3)
352
353typedef 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
Arnd Bergmann2dceba12009-11-06 08:09:03 +0000368struct 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
Chris Metcalf4800a5b2011-05-17 14:41:06 -0400377struct compat_if_settings {
Arnd Bergmann7a50a242009-11-08 20:57:03 -0800378 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
Arnd Bergmann2dceba12009-11-06 08:09:03 +0000383struct compat_ifreq {
Arnd Bergmann7a50a242009-11-08 20:57:03 -0800384 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 */
Arnd Bergmann2dceba12009-11-06 08:09:03 +0000398 char ifru_newname[IFNAMSIZ];
Arnd Bergmann7a50a242009-11-08 20:57:03 -0800399 compat_caddr_t ifru_data;
400 struct compat_if_settings ifru_settings;
401 } ifr_ifru;
Arnd Bergmann2dceba12009-11-06 08:09:03 +0000402};
403
404struct compat_ifconf {
Chris Metcalf4800a5b2011-05-17 14:41:06 -0400405 compat_int_t ifc_len; /* size of buffer */
406 compat_caddr_t ifcbuf;
Arnd Bergmann2dceba12009-11-06 08:09:03 +0000407};
408
Ingo Molnar34f192c2006-03-27 01:16:24 -0800409struct compat_robust_list {
410 compat_uptr_t next;
411};
412
413struct 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
Al Viro495dfbf2012-12-25 19:09:45 -0500419#ifdef CONFIG_COMPAT_OLD_SIGACTION
420struct 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
Stephan Muellerf1c316a2016-08-19 20:39:09 +0200428struct compat_keyctl_kdf_params {
429 compat_uptr_t hashname;
430 compat_uptr_t otherinfo;
431 __u32 otherinfolen;
432 __u32 __spare[8];
433};
434
Chris Metcalfbe84cb42011-05-09 13:12:30 -0400435struct compat_statfs;
436struct compat_statfs64;
437struct compat_old_linux_dirent;
438struct compat_linux_dirent;
439struct linux_dirent64;
440struct compat_msghdr;
441struct compat_mmsghdr;
442struct compat_sysinfo;
443struct compat_sysctl_args;
444struct compat_kexec_segment;
445struct compat_mq_attr;
Chris Metcalf48b25c42012-03-15 13:13:38 -0400446struct compat_msgbuf;
Chris Metcalfbe84cb42011-05-09 13:12:30 -0400447
Ingo Molnar34f192c2006-03-27 01:16:24 -0800448extern void compat_exit_robust_list(struct task_struct *curr);
449
Linus Torvalds1da177e2005-04-16 15:20:36 -0700450#define BITS_PER_COMPAT_LONG (8*sizeof(compat_long_t))
451
Al Viro1e1fc132017-05-30 00:29:38 -0400452#define BITS_TO_COMPAT_LONGS(bits) DIV_ROUND_UP(bits, BITS_PER_COMPAT_LONG)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700453
Stephen Rothwell5fa38392006-10-28 10:38:46 -0700454long compat_get_bitmap(unsigned long *mask, const compat_ulong_t __user *umask,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700455 unsigned long bitmap_size);
456long compat_put_bitmap(compat_ulong_t __user *umask, unsigned long *mask,
457 unsigned long bitmap_size);
Eric W. Biederman212a36a2017-07-31 17:15:31 -0500458int copy_siginfo_from_user32(siginfo_t *to, const struct compat_siginfo __user *from);
Al Viroce395962013-10-13 17:23:53 -0400459int copy_siginfo_to_user32(struct compat_siginfo __user *to, const siginfo_t *from);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700460int get_compat_sigevent(struct sigevent *event,
461 const struct compat_sigevent __user *u_event);
462
Andrew Morton643a6542006-02-11 17:55:52 -0800463static inline int compat_timeval_compare(struct compat_timeval *lhs,
464 struct compat_timeval *rhs)
465{
466 if (lhs->tv_sec < rhs->tv_sec)
467 return -1;
468 if (lhs->tv_sec > rhs->tv_sec)
469 return 1;
470 return lhs->tv_usec - rhs->tv_usec;
471}
472
473static inline int compat_timespec_compare(struct compat_timespec *lhs,
474 struct compat_timespec *rhs)
475{
476 if (lhs->tv_sec < rhs->tv_sec)
477 return -1;
478 if (lhs->tv_sec > rhs->tv_sec)
479 return 1;
480 return lhs->tv_nsec - rhs->tv_nsec;
481}
482
Al Viro3968cf62017-09-03 21:45:17 -0400483extern int get_compat_sigset(sigset_t *set, const compat_sigset_t __user *compat);
Matt Redfearnfde9fc72018-02-19 16:55:06 +0000484
485/*
486 * Defined inline such that size can be compile time constant, which avoids
487 * CONFIG_HARDENED_USERCOPY complaining about copies from task_struct
488 */
489static inline int
490put_compat_sigset(compat_sigset_t __user *compat, const sigset_t *set,
491 unsigned int size)
492{
493 /* size <= sizeof(compat_sigset_t) <= sizeof(sigset_t) */
494#ifdef __BIG_ENDIAN
495 compat_sigset_t v;
496 switch (_NSIG_WORDS) {
497 case 4: v.sig[7] = (set->sig[3] >> 32); v.sig[6] = set->sig[3];
498 case 3: v.sig[5] = (set->sig[2] >> 32); v.sig[4] = set->sig[2];
499 case 2: v.sig[3] = (set->sig[1] >> 32); v.sig[2] = set->sig[1];
500 case 1: v.sig[1] = (set->sig[0] >> 32); v.sig[0] = set->sig[0];
501 }
502 return copy_to_user(compat, &v, size) ? -EFAULT : 0;
503#else
504 return copy_to_user(compat, set, size) ? -EFAULT : 0;
505#endif
506}
Andi Kleenbebfa102006-06-26 13:56:52 +0200507
Roland McGrath032d82d2008-01-30 13:31:47 +0100508extern int compat_ptrace_request(struct task_struct *child,
509 compat_long_t request,
510 compat_ulong_t addr, compat_ulong_t data);
511
Roland McGrathc269f192008-01-30 13:31:48 +0100512extern long compat_arch_ptrace(struct task_struct *child, compat_long_t request,
513 compat_ulong_t addr, compat_ulong_t data);
Roland McGrathc269f192008-01-30 13:31:48 +0100514
Al Viro35280bd2013-02-24 14:52:17 -0500515struct epoll_event; /* fortunately, this one is fixed-layout */
Heiko Carstens4c696ba2009-01-14 14:13:53 +0100516
Jeff Moyerb8373362010-05-26 14:44:25 -0700517extern ssize_t compat_rw_copy_check_uvector(int type,
Chris Metcalf4800a5b2011-05-17 14:41:06 -0400518 const struct compat_iovec __user *uvector,
519 unsigned long nr_segs,
Jeff Moyerb8373362010-05-26 14:44:25 -0700520 unsigned long fast_segs, struct iovec *fast_pointer,
Christopher Yeohac34ebb2012-05-31 16:26:42 -0700521 struct iovec **ret_pointer);
H. Peter Anvinc41d68a2010-09-07 16:16:18 -0700522
523extern void __user *compat_alloc_user_space(unsigned long len);
524
Al Viro90268432012-12-14 14:47:53 -0500525int compat_restore_altstack(const compat_stack_t __user *uss);
Al Viroc40702c2012-11-20 14:24:26 -0500526int __compat_save_altstack(compat_stack_t __user *, unsigned long);
Al Virobd1c149a2013-09-01 20:35:01 +0100527#define compat_save_altstack_ex(uss, sp) do { \
528 compat_stack_t __user *__uss = uss; \
529 struct task_struct *t = current; \
530 put_user_ex(ptr_to_compat((void __user *)t->sas_ss_sp), &__uss->ss_sp); \
Stas Sergeev441398d2017-02-27 14:27:25 -0800531 put_user_ex(t->sas_ss_flags, &__uss->ss_flags); \
Al Virobd1c149a2013-09-01 20:35:01 +0100532 put_user_ex(t->sas_ss_size, &__uss->ss_size); \
Stas Sergeev441398d2017-02-27 14:27:25 -0800533 if (t->sas_ss_flags & SS_AUTODISARM) \
534 sas_ss_reset(t); \
Al Virobd1c149a2013-09-01 20:35:01 +0100535} while (0);
Catalin Marinas8f9c0112012-09-19 12:01:52 +0100536
Dominik Brodowskic679a082018-03-25 23:04:48 +0200537/*
538 * These syscall function prototypes are kept in the same order as
Dominik Brodowski3e2052e2018-03-22 14:09:17 +0100539 * include/uapi/asm-generic/unistd.h. Deprecated or obsolete system calls
540 * go below.
Dominik Brodowskic679a082018-03-25 23:04:48 +0200541 *
542 * Please note that these prototypes here are only provided for information
543 * purposes, for static analysis, and for linking from the syscall table.
544 * These functions should not be called elsewhere from kernel code.
Dominik Brodowski7303e302018-04-05 11:53:03 +0200545 *
546 * As the syscall calling convention may be different from the default
547 * for architectures overriding the syscall calling convention, do not
548 * include the prototypes if CONFIG_ARCH_HAS_SYSCALL_WRAPPER is enabled.
Dominik Brodowskic679a082018-03-25 23:04:48 +0200549 */
Dominik Brodowski7303e302018-04-05 11:53:03 +0200550#ifndef CONFIG_ARCH_HAS_SYSCALL_WRAPPER
Dominik Brodowskic679a082018-03-25 23:04:48 +0200551asmlinkage long compat_sys_io_setup(unsigned nr_reqs, u32 __user *ctx32p);
552asmlinkage long compat_sys_io_submit(compat_aio_context_t ctx_id, int nr,
553 u32 __user *iocb);
554asmlinkage long compat_sys_io_getevents(compat_aio_context_t ctx_id,
555 compat_long_t min_nr,
556 compat_long_t nr,
557 struct io_event __user *events,
558 struct compat_timespec __user *timeout);
559
560/* fs/cookies.c */
561asmlinkage long compat_sys_lookup_dcookie(u32, u32, char __user *, compat_size_t);
562
563/* fs/eventpoll.c */
564asmlinkage long compat_sys_epoll_pwait(int epfd,
565 struct epoll_event __user *events,
566 int maxevents, int timeout,
567 const compat_sigset_t __user *sigmask,
568 compat_size_t sigsetsize);
569
570/* fs/fcntl.c */
571asmlinkage long compat_sys_fcntl(unsigned int fd, unsigned int cmd,
572 compat_ulong_t arg);
573asmlinkage long compat_sys_fcntl64(unsigned int fd, unsigned int cmd,
574 compat_ulong_t arg);
575
576/* fs/ioctl.c */
577asmlinkage long compat_sys_ioctl(unsigned int fd, unsigned int cmd,
578 compat_ulong_t arg);
579
580/* fs/namespace.c */
581asmlinkage long compat_sys_mount(const char __user *dev_name,
582 const char __user *dir_name,
583 const char __user *type, compat_ulong_t flags,
584 const void __user *data);
585
586/* fs/open.c */
587asmlinkage long compat_sys_statfs(const char __user *pathname,
588 struct compat_statfs __user *buf);
589asmlinkage long compat_sys_statfs64(const char __user *pathname,
590 compat_size_t sz,
591 struct compat_statfs64 __user *buf);
592asmlinkage long compat_sys_fstatfs(unsigned int fd,
593 struct compat_statfs __user *buf);
594asmlinkage long compat_sys_fstatfs64(unsigned int fd, compat_size_t sz,
595 struct compat_statfs64 __user *buf);
596asmlinkage long compat_sys_truncate(const char __user *, compat_off_t);
597asmlinkage long compat_sys_ftruncate(unsigned int, compat_ulong_t);
598/* No generic prototype for truncate64, ftruncate64, fallocate */
599asmlinkage long compat_sys_openat(int dfd, const char __user *filename,
600 int flags, umode_t mode);
601
602/* fs/readdir.c */
603asmlinkage long compat_sys_getdents(unsigned int fd,
604 struct compat_linux_dirent __user *dirent,
605 unsigned int count);
606
607/* fs/read_write.c */
608asmlinkage long compat_sys_lseek(unsigned int, compat_off_t, unsigned int);
609asmlinkage ssize_t compat_sys_readv(compat_ulong_t fd,
610 const struct compat_iovec __user *vec, compat_ulong_t vlen);
611asmlinkage ssize_t compat_sys_writev(compat_ulong_t fd,
612 const struct compat_iovec __user *vec, compat_ulong_t vlen);
613/* No generic prototype for pread64 and pwrite64 */
614asmlinkage ssize_t compat_sys_preadv(compat_ulong_t fd,
615 const struct compat_iovec __user *vec,
616 compat_ulong_t vlen, u32 pos_low, u32 pos_high);
617asmlinkage ssize_t compat_sys_pwritev(compat_ulong_t fd,
618 const struct compat_iovec __user *vec,
619 compat_ulong_t vlen, u32 pos_low, u32 pos_high);
620#ifdef __ARCH_WANT_COMPAT_SYS_PREADV64
621asmlinkage long compat_sys_preadv64(unsigned long fd,
622 const struct compat_iovec __user *vec,
623 unsigned long vlen, loff_t pos);
624#endif
625
626#ifdef __ARCH_WANT_COMPAT_SYS_PWRITEV64
627asmlinkage long compat_sys_pwritev64(unsigned long fd,
628 const struct compat_iovec __user *vec,
629 unsigned long vlen, loff_t pos);
630#endif
631
632/* fs/sendfile.c */
633asmlinkage long compat_sys_sendfile(int out_fd, int in_fd,
634 compat_off_t __user *offset, compat_size_t count);
635asmlinkage long compat_sys_sendfile64(int out_fd, int in_fd,
636 compat_loff_t __user *offset, compat_size_t count);
637
638/* fs/select.c */
639asmlinkage long compat_sys_pselect6(int n, compat_ulong_t __user *inp,
640 compat_ulong_t __user *outp,
641 compat_ulong_t __user *exp,
642 struct compat_timespec __user *tsp,
643 void __user *sig);
644asmlinkage long compat_sys_ppoll(struct pollfd __user *ufds,
645 unsigned int nfds,
646 struct compat_timespec __user *tsp,
647 const compat_sigset_t __user *sigmask,
648 compat_size_t sigsetsize);
649
650/* fs/signalfd.c */
651asmlinkage long compat_sys_signalfd4(int ufd,
652 const compat_sigset_t __user *sigmask,
653 compat_size_t sigsetsize, int flags);
654
655/* fs/splice.c */
656asmlinkage long compat_sys_vmsplice(int fd, const struct compat_iovec __user *,
657 unsigned int nr_segs, unsigned int flags);
658
659/* fs/stat.c */
660asmlinkage long compat_sys_newfstatat(unsigned int dfd,
661 const char __user *filename,
662 struct compat_stat __user *statbuf,
663 int flag);
664asmlinkage long compat_sys_newfstat(unsigned int fd,
665 struct compat_stat __user *statbuf);
666
667/* fs/sync.c: No generic prototype for sync_file_range and sync_file_range2 */
668
669/* fs/timerfd.c */
670asmlinkage long compat_sys_timerfd_gettime(int ufd,
671 struct compat_itimerspec __user *otmr);
672asmlinkage long compat_sys_timerfd_settime(int ufd, int flags,
673 const struct compat_itimerspec __user *utmr,
674 struct compat_itimerspec __user *otmr);
675
676/* fs/utimes.c */
677asmlinkage long compat_sys_utimensat(unsigned int dfd,
678 const char __user *filename,
679 struct compat_timespec __user *t,
680 int flags);
681
682/* kernel/exit.c */
683asmlinkage long compat_sys_waitid(int, compat_pid_t,
684 struct compat_siginfo __user *, int,
685 struct compat_rusage __user *);
686
687
688
689/* kernel/futex.c */
690asmlinkage long compat_sys_futex(u32 __user *uaddr, int op, u32 val,
691 struct compat_timespec __user *utime, u32 __user *uaddr2,
692 u32 val3);
693asmlinkage long
694compat_sys_set_robust_list(struct compat_robust_list_head __user *head,
695 compat_size_t len);
696asmlinkage long
697compat_sys_get_robust_list(int pid, compat_uptr_t __user *head_ptr,
698 compat_size_t __user *len_ptr);
699
700/* kernel/hrtimer.c */
701asmlinkage long compat_sys_nanosleep(struct compat_timespec __user *rqtp,
702 struct compat_timespec __user *rmtp);
703
704/* kernel/itimer.c */
705asmlinkage long compat_sys_getitimer(int which,
706 struct compat_itimerval __user *it);
707asmlinkage long compat_sys_setitimer(int which,
708 struct compat_itimerval __user *in,
709 struct compat_itimerval __user *out);
710
711/* kernel/kexec.c */
712asmlinkage long compat_sys_kexec_load(compat_ulong_t entry,
713 compat_ulong_t nr_segments,
714 struct compat_kexec_segment __user *,
715 compat_ulong_t flags);
716
717/* kernel/posix-timers.c */
718asmlinkage long compat_sys_timer_create(clockid_t which_clock,
719 struct compat_sigevent __user *timer_event_spec,
720 timer_t __user *created_timer_id);
721asmlinkage long compat_sys_timer_gettime(timer_t timer_id,
722 struct compat_itimerspec __user *setting);
723asmlinkage long compat_sys_timer_settime(timer_t timer_id, int flags,
724 struct compat_itimerspec __user *new,
725 struct compat_itimerspec __user *old);
726asmlinkage long compat_sys_clock_settime(clockid_t which_clock,
727 struct compat_timespec __user *tp);
728asmlinkage long compat_sys_clock_gettime(clockid_t which_clock,
729 struct compat_timespec __user *tp);
730asmlinkage long compat_sys_clock_getres(clockid_t which_clock,
731 struct compat_timespec __user *tp);
732asmlinkage long compat_sys_clock_nanosleep(clockid_t which_clock, int flags,
733 struct compat_timespec __user *rqtp,
734 struct compat_timespec __user *rmtp);
735
736/* kernel/ptrace.c */
737asmlinkage long compat_sys_ptrace(compat_long_t request, compat_long_t pid,
738 compat_long_t addr, compat_long_t data);
739
740/* kernel/sched/core.c */
741asmlinkage long compat_sys_sched_setaffinity(compat_pid_t pid,
742 unsigned int len,
743 compat_ulong_t __user *user_mask_ptr);
744asmlinkage long compat_sys_sched_getaffinity(compat_pid_t pid,
745 unsigned int len,
746 compat_ulong_t __user *user_mask_ptr);
Catalin Marinas0ad50c32012-12-17 16:01:45 -0800747asmlinkage long compat_sys_sched_rr_get_interval(compat_pid_t pid,
748 struct compat_timespec __user *interval);
749
Dominik Brodowskic679a082018-03-25 23:04:48 +0200750/* kernel/signal.c */
751asmlinkage long compat_sys_sigaltstack(const compat_stack_t __user *uss_ptr,
752 compat_stack_t __user *uoss_ptr);
753asmlinkage long compat_sys_rt_sigsuspend(compat_sigset_t __user *unewset,
754 compat_size_t sigsetsize);
755#ifndef CONFIG_ODD_RT_SIGACTION
756asmlinkage long compat_sys_rt_sigaction(int,
757 const struct compat_sigaction __user *,
758 struct compat_sigaction __user *,
759 compat_size_t);
760#endif
761asmlinkage long compat_sys_rt_sigprocmask(int how, compat_sigset_t __user *set,
762 compat_sigset_t __user *oset,
763 compat_size_t sigsetsize);
764asmlinkage long compat_sys_rt_sigpending(compat_sigset_t __user *uset,
765 compat_size_t sigsetsize);
766asmlinkage long compat_sys_rt_sigtimedwait(compat_sigset_t __user *uthese,
767 struct compat_siginfo __user *uinfo,
768 struct compat_timespec __user *uts, compat_size_t sigsetsize);
769asmlinkage long compat_sys_rt_sigqueueinfo(compat_pid_t pid, int sig,
770 struct compat_siginfo __user *uinfo);
771/* No generic prototype for rt_sigreturn */
772
773/* kernel/sys.c */
774asmlinkage long compat_sys_times(struct compat_tms __user *tbuf);
775asmlinkage long compat_sys_getrlimit(unsigned int resource,
776 struct compat_rlimit __user *rlim);
777asmlinkage long compat_sys_setrlimit(unsigned int resource,
778 struct compat_rlimit __user *rlim);
779asmlinkage long compat_sys_getrusage(int who, struct compat_rusage __user *ru);
780
781/* kernel/time.c */
782asmlinkage long compat_sys_gettimeofday(struct compat_timeval __user *tv,
783 struct timezone __user *tz);
784asmlinkage long compat_sys_settimeofday(struct compat_timeval __user *tv,
785 struct timezone __user *tz);
786asmlinkage long compat_sys_adjtimex(struct compat_timex __user *utp);
787
788/* kernel/timer.c */
789asmlinkage long compat_sys_sysinfo(struct compat_sysinfo __user *info);
790
791/* ipc/mqueue.c */
792asmlinkage long compat_sys_mq_open(const char __user *u_name,
793 int oflag, compat_mode_t mode,
794 struct compat_mq_attr __user *u_attr);
795asmlinkage long compat_sys_mq_timedsend(mqd_t mqdes,
796 const char __user *u_msg_ptr,
797 compat_size_t msg_len, unsigned int msg_prio,
798 const struct compat_timespec __user *u_abs_timeout);
799asmlinkage ssize_t compat_sys_mq_timedreceive(mqd_t mqdes,
800 char __user *u_msg_ptr,
801 compat_size_t msg_len, unsigned int __user *u_msg_prio,
802 const struct compat_timespec __user *u_abs_timeout);
803asmlinkage long compat_sys_mq_notify(mqd_t mqdes,
804 const struct compat_sigevent __user *u_notification);
805asmlinkage long compat_sys_mq_getsetattr(mqd_t mqdes,
806 const struct compat_mq_attr __user *u_mqstat,
807 struct compat_mq_attr __user *u_omqstat);
808
809/* ipc/msg.c */
810asmlinkage long compat_sys_msgctl(int first, int second, void __user *uptr);
811asmlinkage long compat_sys_msgrcv(int msqid, compat_uptr_t msgp,
812 compat_ssize_t msgsz, compat_long_t msgtyp, int msgflg);
813asmlinkage long compat_sys_msgsnd(int msqid, compat_uptr_t msgp,
814 compat_ssize_t msgsz, int msgflg);
815
816/* ipc/sem.c */
817asmlinkage long compat_sys_semctl(int semid, int semnum, int cmd, int arg);
818asmlinkage long compat_sys_semtimedop(int semid, struct sembuf __user *tsems,
819 unsigned nsems, const struct compat_timespec __user *timeout);
820
821/* ipc/shm.c */
822asmlinkage long compat_sys_shmctl(int first, int second, void __user *uptr);
823asmlinkage long compat_sys_shmat(int shmid, compat_uptr_t shmaddr, int shmflg);
824
825/* net/socket.c */
826asmlinkage long compat_sys_recvfrom(int fd, void __user *buf, compat_size_t len,
827 unsigned flags, struct sockaddr __user *addr,
828 int __user *addrlen);
829asmlinkage long compat_sys_setsockopt(int fd, int level, int optname,
830 char __user *optval, unsigned int optlen);
831asmlinkage long compat_sys_getsockopt(int fd, int level, int optname,
832 char __user *optval, int __user *optlen);
833asmlinkage long compat_sys_sendmsg(int fd, struct compat_msghdr __user *msg,
834 unsigned flags);
835asmlinkage long compat_sys_recvmsg(int fd, struct compat_msghdr __user *msg,
836 unsigned int flags);
837
838/* mm/filemap.c: No generic prototype for readahead */
839
840/* security/keys/keyctl.c */
841asmlinkage long compat_sys_keyctl(u32 option,
842 u32 arg2, u32 arg3, u32 arg4, u32 arg5);
843
844/* arch/example/kernel/sys_example.c */
845asmlinkage long compat_sys_execve(const char __user *filename, const compat_uptr_t __user *argv,
846 const compat_uptr_t __user *envp);
847
848/* mm/fadvise.c: No generic prototype for fadvise64_64 */
849
850/* mm/, CONFIG_MMU only */
851asmlinkage long compat_sys_mbind(compat_ulong_t start, compat_ulong_t len,
852 compat_ulong_t mode,
853 compat_ulong_t __user *nmask,
854 compat_ulong_t maxnode, compat_ulong_t flags);
855asmlinkage long compat_sys_get_mempolicy(int __user *policy,
856 compat_ulong_t __user *nmask,
857 compat_ulong_t maxnode,
858 compat_ulong_t addr,
859 compat_ulong_t flags);
860asmlinkage long compat_sys_set_mempolicy(int mode, compat_ulong_t __user *nmask,
861 compat_ulong_t maxnode);
862asmlinkage long compat_sys_migrate_pages(compat_pid_t pid,
863 compat_ulong_t maxnode, const compat_ulong_t __user *old_nodes,
864 const compat_ulong_t __user *new_nodes);
865asmlinkage long compat_sys_move_pages(pid_t pid, compat_ulong_t nr_pages,
866 __u32 __user *pages,
867 const int __user *nodes,
868 int __user *status,
869 int flags);
870
871asmlinkage long compat_sys_rt_tgsigqueueinfo(compat_pid_t tgid,
872 compat_pid_t pid, int sig,
873 struct compat_siginfo __user *uinfo);
874asmlinkage long compat_sys_recvmmsg(int fd, struct compat_mmsghdr __user *mmsg,
875 unsigned vlen, unsigned int flags,
876 struct compat_timespec __user *timeout);
877asmlinkage long compat_sys_wait4(compat_pid_t pid,
878 compat_uint_t __user *stat_addr, int options,
879 struct compat_rusage __user *ru);
Al Viro91c2e0b2013-03-05 20:10:59 -0500880asmlinkage long compat_sys_fanotify_mark(int, unsigned int, __u32, __u32,
881 int, const char __user *);
Dominik Brodowskic679a082018-03-25 23:04:48 +0200882asmlinkage long compat_sys_open_by_handle_at(int mountdirfd,
883 struct file_handle __user *handle,
884 int flags);
885asmlinkage long compat_sys_clock_adjtime(clockid_t which_clock,
886 struct compat_timex __user *tp);
887asmlinkage long compat_sys_sendmmsg(int fd, struct compat_mmsghdr __user *mmsg,
888 unsigned vlen, unsigned int flags);
889asmlinkage ssize_t compat_sys_process_vm_readv(compat_pid_t pid,
890 const struct compat_iovec __user *lvec,
891 compat_ulong_t liovcnt, const struct compat_iovec __user *rvec,
892 compat_ulong_t riovcnt, compat_ulong_t flags);
893asmlinkage ssize_t compat_sys_process_vm_writev(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);
897asmlinkage long compat_sys_execveat(int dfd, const char __user *filename,
898 const compat_uptr_t __user *argv,
899 const compat_uptr_t __user *envp, int flags);
900asmlinkage ssize_t compat_sys_preadv2(compat_ulong_t fd,
901 const struct compat_iovec __user *vec,
902 compat_ulong_t vlen, u32 pos_low, u32 pos_high, rwf_t flags);
903asmlinkage ssize_t compat_sys_pwritev2(compat_ulong_t fd,
904 const struct compat_iovec __user *vec,
905 compat_ulong_t vlen, u32 pos_low, u32 pos_high, rwf_t flags);
906#ifdef __ARCH_WANT_COMPAT_SYS_PREADV64V2
907asmlinkage long compat_sys_readv64v2(unsigned long fd,
908 const struct compat_iovec __user *vec,
909 unsigned long vlen, loff_t pos, rwf_t flags);
910#endif
Andy Lutomirski5180e3e2016-03-22 14:24:43 -0700911
Dominik Brodowskic679a082018-03-25 23:04:48 +0200912#ifdef __ARCH_WANT_COMPAT_SYS_PWRITEV64V2
913asmlinkage long compat_sys_pwritev64v2(unsigned long fd,
914 const struct compat_iovec __user *vec,
915 unsigned long vlen, loff_t pos, rwf_t flags);
916#endif
917
918
919/*
Dominik Brodowskic679a082018-03-25 23:04:48 +0200920 * Deprecated system calls which are still defined in
921 * include/uapi/asm-generic/unistd.h and wanted by >= 1 arch
922 */
923
924/* __ARCH_WANT_SYSCALL_NO_AT */
925asmlinkage long compat_sys_open(const char __user *filename, int flags,
926 umode_t mode);
927asmlinkage long compat_sys_utimes(const char __user *filename,
928 struct compat_timeval __user *t);
929
930/* __ARCH_WANT_SYSCALL_NO_FLAGS */
931asmlinkage long compat_sys_signalfd(int ufd,
932 const compat_sigset_t __user *sigmask,
933 compat_size_t sigsetsize);
934
935/* __ARCH_WANT_SYSCALL_OFF_T */
936asmlinkage long compat_sys_newstat(const char __user *filename,
937 struct compat_stat __user *statbuf);
938asmlinkage long compat_sys_newlstat(const char __user *filename,
939 struct compat_stat __user *statbuf);
940
941/* __ARCH_WANT_SYSCALL_DEPRECATED */
942asmlinkage long compat_sys_time(compat_time_t __user *tloc);
943asmlinkage long compat_sys_utime(const char __user *filename,
944 struct compat_utimbuf __user *t);
945asmlinkage long compat_sys_futimesat(unsigned int dfd,
946 const char __user *filename,
947 struct compat_timeval __user *t);
948asmlinkage long compat_sys_select(int n, compat_ulong_t __user *inp,
949 compat_ulong_t __user *outp, compat_ulong_t __user *exp,
950 struct compat_timeval __user *tvp);
951asmlinkage long compat_sys_ustat(unsigned dev, struct compat_ustat __user *u32);
952asmlinkage long compat_sys_recv(int fd, void __user *buf, compat_size_t len,
953 unsigned flags);
954asmlinkage long compat_sys_sysctl(struct compat_sysctl_args __user *args);
955
956/* obsolete: fs/readdir.c */
957asmlinkage long compat_sys_old_readdir(unsigned int fd,
958 struct compat_old_linux_dirent __user *,
959 unsigned int count);
960
961/* obsolete: fs/select.c */
962asmlinkage long compat_sys_old_select(struct compat_sel_arg_struct __user *arg);
963
964/* obsolete: ipc */
965asmlinkage long compat_sys_ipc(u32, int, int, u32, compat_uptr_t, u32);
966
967/* obsolete: kernel/signal.c */
968#ifdef __ARCH_WANT_SYS_SIGPENDING
969asmlinkage long compat_sys_sigpending(compat_old_sigset_t __user *set);
970#endif
971
972#ifdef __ARCH_WANT_SYS_SIGPROCMASK
973asmlinkage long compat_sys_sigprocmask(int how, compat_old_sigset_t __user *nset,
974 compat_old_sigset_t __user *oset);
975#endif
976#ifdef CONFIG_COMPAT_OLD_SIGACTION
977asmlinkage long compat_sys_sigaction(int sig,
978 const struct compat_old_sigaction __user *act,
979 struct compat_old_sigaction __user *oact);
980#endif
981
982/* obsolete: kernel/time/time.c */
983asmlinkage long compat_sys_stime(compat_time_t __user *tptr);
984
985/* obsolete: net/socket.c */
986asmlinkage long compat_sys_socketcall(int call, u32 __user *args);
987
Dominik Brodowski7303e302018-04-05 11:53:03 +0200988#endif /* CONFIG_ARCH_HAS_SYSCALL_WRAPPER */
989
Dominik Brodowskic679a082018-03-25 23:04:48 +0200990
Andy Lutomirski5180e3e2016-03-22 14:24:43 -0700991/*
992 * For most but not all architectures, "am I in a compat syscall?" and
993 * "am I a compat task?" are the same question. For architectures on which
994 * they aren't the same question, arch code can override in_compat_syscall.
995 */
996
997#ifndef in_compat_syscall
998static inline bool in_compat_syscall(void) { return is_compat_task(); }
999#endif
1000
Frederic Weisbeckercd19c362017-01-31 04:09:27 +01001001/**
1002 * ns_to_compat_timeval - Compat version of ns_to_timeval
1003 * @nsec: the nanoseconds value to be converted
1004 *
1005 * Returns the compat_timeval representation of the nsec parameter.
1006 */
1007static inline struct compat_timeval ns_to_compat_timeval(s64 nsec)
1008{
1009 struct timeval tv;
1010 struct compat_timeval ctv;
1011
1012 tv = ns_to_timeval(nsec);
1013 ctv.tv_sec = tv.tv_sec;
1014 ctv.tv_usec = tv.tv_usec;
1015
1016 return ctv;
1017}
1018
1019#else /* !CONFIG_COMPAT */
Linus Torvalds3c761ea2012-02-26 09:44:55 -08001020
1021#define is_compat_task() (0)
Deepa Dinamani5055c672018-03-13 21:03:24 -07001022#ifndef in_compat_syscall
Andy Lutomirski5180e3e2016-03-22 14:24:43 -07001023static inline bool in_compat_syscall(void) { return false; }
Deepa Dinamani5055c672018-03-13 21:03:24 -07001024#endif
Linus Torvalds3c761ea2012-02-26 09:44:55 -08001025
Linus Torvalds1da177e2005-04-16 15:20:36 -07001026#endif /* CONFIG_COMPAT */
Andy Lutomirski5180e3e2016-03-22 14:24:43 -07001027
Linus Torvalds1da177e2005-04-16 15:20:36 -07001028#endif /* _LINUX_COMPAT_H */