compat.h 34 KB

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