compat.h 34 KB

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