compat.h 34 KB

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