compat.h 30 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934
  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/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. __diag_push(); \
  66. __diag_ignore(GCC, 8, "-Wattribute-alias", \
  67. "Type aliasing is used to sanitize syscall arguments");\
  68. asmlinkage long compat_sys##name(__MAP(x,__SC_DECL,__VA_ARGS__)); \
  69. asmlinkage long compat_sys##name(__MAP(x,__SC_DECL,__VA_ARGS__)) \
  70. __attribute__((alias(__stringify(__se_compat_sys##name)))); \
  71. ALLOW_ERROR_INJECTION(compat_sys##name, ERRNO); \
  72. static inline long __do_compat_sys##name(__MAP(x,__SC_DECL,__VA_ARGS__));\
  73. asmlinkage long __se_compat_sys##name(__MAP(x,__SC_LONG,__VA_ARGS__)); \
  74. asmlinkage long __se_compat_sys##name(__MAP(x,__SC_LONG,__VA_ARGS__)) \
  75. { \
  76. long ret = __do_compat_sys##name(__MAP(x,__SC_DELOUSE,__VA_ARGS__));\
  77. __MAP(x,__SC_TEST,__VA_ARGS__); \
  78. return ret; \
  79. } \
  80. __diag_pop(); \
  81. static inline long __do_compat_sys##name(__MAP(x,__SC_DECL,__VA_ARGS__))
  82. #endif /* COMPAT_SYSCALL_DEFINEx */
  83. struct compat_iovec {
  84. compat_uptr_t iov_base;
  85. compat_size_t iov_len;
  86. };
  87. #ifdef CONFIG_COMPAT
  88. #ifndef compat_user_stack_pointer
  89. #define compat_user_stack_pointer() current_user_stack_pointer()
  90. #endif
  91. #ifndef compat_sigaltstack /* we'll need that for MIPS */
  92. typedef struct compat_sigaltstack {
  93. compat_uptr_t ss_sp;
  94. int ss_flags;
  95. compat_size_t ss_size;
  96. } compat_stack_t;
  97. #endif
  98. #ifndef COMPAT_MINSIGSTKSZ
  99. #define COMPAT_MINSIGSTKSZ MINSIGSTKSZ
  100. #endif
  101. #define compat_jiffies_to_clock_t(x) \
  102. (((unsigned long)(x) * COMPAT_USER_HZ) / HZ)
  103. typedef __compat_uid32_t compat_uid_t;
  104. typedef __compat_gid32_t compat_gid_t;
  105. struct compat_sel_arg_struct;
  106. struct rusage;
  107. struct old_itimerval32;
  108. struct compat_tms {
  109. compat_clock_t tms_utime;
  110. compat_clock_t tms_stime;
  111. compat_clock_t tms_cutime;
  112. compat_clock_t tms_cstime;
  113. };
  114. #define _COMPAT_NSIG_WORDS (_COMPAT_NSIG / _COMPAT_NSIG_BPW)
  115. typedef struct {
  116. compat_sigset_word sig[_COMPAT_NSIG_WORDS];
  117. } compat_sigset_t;
  118. int set_compat_user_sigmask(const compat_sigset_t __user *umask,
  119. size_t sigsetsize);
  120. struct compat_sigaction {
  121. #ifndef __ARCH_HAS_IRIX_SIGACTION
  122. compat_uptr_t sa_handler;
  123. compat_ulong_t sa_flags;
  124. #else
  125. compat_uint_t sa_flags;
  126. compat_uptr_t sa_handler;
  127. #endif
  128. #ifdef __ARCH_HAS_SA_RESTORER
  129. compat_uptr_t sa_restorer;
  130. #endif
  131. compat_sigset_t sa_mask __packed;
  132. };
  133. typedef union compat_sigval {
  134. compat_int_t sival_int;
  135. compat_uptr_t sival_ptr;
  136. } compat_sigval_t;
  137. typedef struct compat_siginfo {
  138. int si_signo;
  139. #ifndef __ARCH_HAS_SWAPPED_SIGINFO
  140. int si_errno;
  141. int si_code;
  142. #else
  143. int si_code;
  144. int si_errno;
  145. #endif
  146. union {
  147. int _pad[128/sizeof(int) - 3];
  148. /* kill() */
  149. struct {
  150. compat_pid_t _pid; /* sender's pid */
  151. __compat_uid32_t _uid; /* sender's uid */
  152. } _kill;
  153. /* POSIX.1b timers */
  154. struct {
  155. compat_timer_t _tid; /* timer id */
  156. int _overrun; /* overrun count */
  157. compat_sigval_t _sigval; /* same as below */
  158. } _timer;
  159. /* POSIX.1b signals */
  160. struct {
  161. compat_pid_t _pid; /* sender's pid */
  162. __compat_uid32_t _uid; /* sender's uid */
  163. compat_sigval_t _sigval;
  164. } _rt;
  165. /* SIGCHLD */
  166. struct {
  167. compat_pid_t _pid; /* which child */
  168. __compat_uid32_t _uid; /* sender's uid */
  169. int _status; /* exit code */
  170. compat_clock_t _utime;
  171. compat_clock_t _stime;
  172. } _sigchld;
  173. #ifdef CONFIG_X86_X32_ABI
  174. /* SIGCHLD (x32 version) */
  175. struct {
  176. compat_pid_t _pid; /* which child */
  177. __compat_uid32_t _uid; /* sender's uid */
  178. int _status; /* exit code */
  179. compat_s64 _utime;
  180. compat_s64 _stime;
  181. } _sigchld_x32;
  182. #endif
  183. /* SIGILL, SIGFPE, SIGSEGV, SIGBUS, SIGTRAP, SIGEMT */
  184. struct {
  185. compat_uptr_t _addr; /* faulting insn/memory ref. */
  186. #ifdef __ARCH_SI_TRAPNO
  187. int _trapno; /* TRAP # which caused the signal */
  188. #endif
  189. #define __COMPAT_ADDR_BND_PKEY_PAD (__alignof__(compat_uptr_t) < sizeof(short) ? \
  190. sizeof(short) : __alignof__(compat_uptr_t))
  191. union {
  192. /*
  193. * used when si_code=BUS_MCEERR_AR or
  194. * used when si_code=BUS_MCEERR_AO
  195. */
  196. short int _addr_lsb; /* Valid LSB of the reported address. */
  197. /* used when si_code=SEGV_BNDERR */
  198. struct {
  199. char _dummy_bnd[__COMPAT_ADDR_BND_PKEY_PAD];
  200. compat_uptr_t _lower;
  201. compat_uptr_t _upper;
  202. } _addr_bnd;
  203. /* used when si_code=SEGV_PKUERR */
  204. struct {
  205. char _dummy_pkey[__COMPAT_ADDR_BND_PKEY_PAD];
  206. u32 _pkey;
  207. } _addr_pkey;
  208. };
  209. } _sigfault;
  210. /* SIGPOLL */
  211. struct {
  212. compat_long_t _band; /* POLL_IN, POLL_OUT, POLL_MSG */
  213. int _fd;
  214. } _sigpoll;
  215. struct {
  216. compat_uptr_t _call_addr; /* calling user insn */
  217. int _syscall; /* triggering system call number */
  218. unsigned int _arch; /* AUDIT_ARCH_* of syscall */
  219. } _sigsys;
  220. } _sifields;
  221. } compat_siginfo_t;
  222. struct compat_rlimit {
  223. compat_ulong_t rlim_cur;
  224. compat_ulong_t rlim_max;
  225. };
  226. struct compat_rusage {
  227. struct old_timeval32 ru_utime;
  228. struct old_timeval32 ru_stime;
  229. compat_long_t ru_maxrss;
  230. compat_long_t ru_ixrss;
  231. compat_long_t ru_idrss;
  232. compat_long_t ru_isrss;
  233. compat_long_t ru_minflt;
  234. compat_long_t ru_majflt;
  235. compat_long_t ru_nswap;
  236. compat_long_t ru_inblock;
  237. compat_long_t ru_oublock;
  238. compat_long_t ru_msgsnd;
  239. compat_long_t ru_msgrcv;
  240. compat_long_t ru_nsignals;
  241. compat_long_t ru_nvcsw;
  242. compat_long_t ru_nivcsw;
  243. };
  244. extern int put_compat_rusage(const struct rusage *,
  245. struct compat_rusage __user *);
  246. struct compat_siginfo;
  247. struct __compat_aio_sigset;
  248. struct compat_dirent {
  249. u32 d_ino;
  250. compat_off_t d_off;
  251. u16 d_reclen;
  252. char d_name[256];
  253. };
  254. struct compat_ustat {
  255. compat_daddr_t f_tfree;
  256. compat_ino_t f_tinode;
  257. char f_fname[6];
  258. char f_fpack[6];
  259. };
  260. #define COMPAT_SIGEV_PAD_SIZE ((SIGEV_MAX_SIZE/sizeof(int)) - 3)
  261. typedef struct compat_sigevent {
  262. compat_sigval_t sigev_value;
  263. compat_int_t sigev_signo;
  264. compat_int_t sigev_notify;
  265. union {
  266. compat_int_t _pad[COMPAT_SIGEV_PAD_SIZE];
  267. compat_int_t _tid;
  268. struct {
  269. compat_uptr_t _function;
  270. compat_uptr_t _attribute;
  271. } _sigev_thread;
  272. } _sigev_un;
  273. } compat_sigevent_t;
  274. struct compat_ifmap {
  275. compat_ulong_t mem_start;
  276. compat_ulong_t mem_end;
  277. unsigned short base_addr;
  278. unsigned char irq;
  279. unsigned char dma;
  280. unsigned char port;
  281. };
  282. struct compat_if_settings {
  283. unsigned int type; /* Type of physical device or protocol */
  284. unsigned int size; /* Size of the data allocated by the caller */
  285. compat_uptr_t ifs_ifsu; /* union of pointers */
  286. };
  287. struct compat_ifreq {
  288. union {
  289. char ifrn_name[IFNAMSIZ]; /* if name, e.g. "en0" */
  290. } ifr_ifrn;
  291. union {
  292. struct sockaddr ifru_addr;
  293. struct sockaddr ifru_dstaddr;
  294. struct sockaddr ifru_broadaddr;
  295. struct sockaddr ifru_netmask;
  296. struct sockaddr ifru_hwaddr;
  297. short ifru_flags;
  298. compat_int_t ifru_ivalue;
  299. compat_int_t ifru_mtu;
  300. struct compat_ifmap ifru_map;
  301. char ifru_slave[IFNAMSIZ]; /* Just fits the size */
  302. char ifru_newname[IFNAMSIZ];
  303. compat_caddr_t ifru_data;
  304. struct compat_if_settings ifru_settings;
  305. } ifr_ifru;
  306. };
  307. struct compat_ifconf {
  308. compat_int_t ifc_len; /* size of buffer */
  309. compat_caddr_t ifcbuf;
  310. };
  311. struct compat_robust_list {
  312. compat_uptr_t next;
  313. };
  314. struct compat_robust_list_head {
  315. struct compat_robust_list list;
  316. compat_long_t futex_offset;
  317. compat_uptr_t list_op_pending;
  318. };
  319. #ifdef CONFIG_COMPAT_OLD_SIGACTION
  320. struct compat_old_sigaction {
  321. compat_uptr_t sa_handler;
  322. compat_old_sigset_t sa_mask;
  323. compat_ulong_t sa_flags;
  324. compat_uptr_t sa_restorer;
  325. };
  326. #endif
  327. struct compat_keyctl_kdf_params {
  328. compat_uptr_t hashname;
  329. compat_uptr_t otherinfo;
  330. __u32 otherinfolen;
  331. __u32 __spare[8];
  332. };
  333. struct compat_statfs;
  334. struct compat_statfs64;
  335. struct compat_old_linux_dirent;
  336. struct compat_linux_dirent;
  337. struct linux_dirent64;
  338. struct compat_msghdr;
  339. struct compat_mmsghdr;
  340. struct compat_sysinfo;
  341. struct compat_sysctl_args;
  342. struct compat_kexec_segment;
  343. struct compat_mq_attr;
  344. struct compat_msgbuf;
  345. #define BITS_PER_COMPAT_LONG (8*sizeof(compat_long_t))
  346. #define BITS_TO_COMPAT_LONGS(bits) DIV_ROUND_UP(bits, BITS_PER_COMPAT_LONG)
  347. long compat_get_bitmap(unsigned long *mask, const compat_ulong_t __user *umask,
  348. unsigned long bitmap_size);
  349. long compat_put_bitmap(compat_ulong_t __user *umask, unsigned long *mask,
  350. unsigned long bitmap_size);
  351. void copy_siginfo_to_external32(struct compat_siginfo *to,
  352. const struct kernel_siginfo *from);
  353. int copy_siginfo_from_user32(kernel_siginfo_t *to,
  354. const struct compat_siginfo __user *from);
  355. int __copy_siginfo_to_user32(struct compat_siginfo __user *to,
  356. const kernel_siginfo_t *from);
  357. #ifndef copy_siginfo_to_user32
  358. #define copy_siginfo_to_user32 __copy_siginfo_to_user32
  359. #endif
  360. int get_compat_sigevent(struct sigevent *event,
  361. const struct compat_sigevent __user *u_event);
  362. extern int get_compat_sigset(sigset_t *set, const compat_sigset_t __user *compat);
  363. /*
  364. * Defined inline such that size can be compile time constant, which avoids
  365. * CONFIG_HARDENED_USERCOPY complaining about copies from task_struct
  366. */
  367. static inline int
  368. put_compat_sigset(compat_sigset_t __user *compat, const sigset_t *set,
  369. unsigned int size)
  370. {
  371. /* size <= sizeof(compat_sigset_t) <= sizeof(sigset_t) */
  372. #ifdef __BIG_ENDIAN
  373. compat_sigset_t v;
  374. switch (_NSIG_WORDS) {
  375. case 4: v.sig[7] = (set->sig[3] >> 32); v.sig[6] = set->sig[3];
  376. fallthrough;
  377. case 3: v.sig[5] = (set->sig[2] >> 32); v.sig[4] = set->sig[2];
  378. fallthrough;
  379. case 2: v.sig[3] = (set->sig[1] >> 32); v.sig[2] = set->sig[1];
  380. fallthrough;
  381. case 1: v.sig[1] = (set->sig[0] >> 32); v.sig[0] = set->sig[0];
  382. }
  383. return copy_to_user(compat, &v, size) ? -EFAULT : 0;
  384. #else
  385. return copy_to_user(compat, set, size) ? -EFAULT : 0;
  386. #endif
  387. }
  388. extern int compat_ptrace_request(struct task_struct *child,
  389. compat_long_t request,
  390. compat_ulong_t addr, compat_ulong_t data);
  391. extern long compat_arch_ptrace(struct task_struct *child, compat_long_t request,
  392. compat_ulong_t addr, compat_ulong_t data);
  393. struct epoll_event; /* fortunately, this one is fixed-layout */
  394. extern void __user *compat_alloc_user_space(unsigned long len);
  395. int compat_restore_altstack(const compat_stack_t __user *uss);
  396. int __compat_save_altstack(compat_stack_t __user *, unsigned long);
  397. #define unsafe_compat_save_altstack(uss, sp, label) do { \
  398. compat_stack_t __user *__uss = uss; \
  399. struct task_struct *t = current; \
  400. unsafe_put_user(ptr_to_compat((void __user *)t->sas_ss_sp), \
  401. &__uss->ss_sp, label); \
  402. unsafe_put_user(t->sas_ss_flags, &__uss->ss_flags, label); \
  403. unsafe_put_user(t->sas_ss_size, &__uss->ss_size, label); \
  404. if (t->sas_ss_flags & SS_AUTODISARM) \
  405. sas_ss_reset(t); \
  406. } while (0);
  407. /*
  408. * These syscall function prototypes are kept in the same order as
  409. * include/uapi/asm-generic/unistd.h. Deprecated or obsolete system calls
  410. * go below.
  411. *
  412. * Please note that these prototypes here are only provided for information
  413. * purposes, for static analysis, and for linking from the syscall table.
  414. * These functions should not be called elsewhere from kernel code.
  415. *
  416. * As the syscall calling convention may be different from the default
  417. * for architectures overriding the syscall calling convention, do not
  418. * include the prototypes if CONFIG_ARCH_HAS_SYSCALL_WRAPPER is enabled.
  419. */
  420. #ifndef CONFIG_ARCH_HAS_SYSCALL_WRAPPER
  421. asmlinkage long compat_sys_io_setup(unsigned nr_reqs, u32 __user *ctx32p);
  422. asmlinkage long compat_sys_io_submit(compat_aio_context_t ctx_id, int nr,
  423. u32 __user *iocb);
  424. asmlinkage long compat_sys_io_pgetevents(compat_aio_context_t ctx_id,
  425. compat_long_t min_nr,
  426. compat_long_t nr,
  427. struct io_event __user *events,
  428. struct old_timespec32 __user *timeout,
  429. const struct __compat_aio_sigset __user *usig);
  430. asmlinkage long compat_sys_io_pgetevents_time64(compat_aio_context_t ctx_id,
  431. compat_long_t min_nr,
  432. compat_long_t nr,
  433. struct io_event __user *events,
  434. struct __kernel_timespec __user *timeout,
  435. const struct __compat_aio_sigset __user *usig);
  436. /* fs/cookies.c */
  437. asmlinkage long compat_sys_lookup_dcookie(u32, u32, char __user *, compat_size_t);
  438. /* fs/eventpoll.c */
  439. asmlinkage long compat_sys_epoll_pwait(int epfd,
  440. struct epoll_event __user *events,
  441. int maxevents, int timeout,
  442. const compat_sigset_t __user *sigmask,
  443. compat_size_t sigsetsize);
  444. /* fs/fcntl.c */
  445. asmlinkage long compat_sys_fcntl(unsigned int fd, unsigned int cmd,
  446. compat_ulong_t arg);
  447. asmlinkage long compat_sys_fcntl64(unsigned int fd, unsigned int cmd,
  448. compat_ulong_t arg);
  449. /* fs/ioctl.c */
  450. asmlinkage long compat_sys_ioctl(unsigned int fd, unsigned int cmd,
  451. compat_ulong_t arg);
  452. /* fs/open.c */
  453. asmlinkage long compat_sys_statfs(const char __user *pathname,
  454. struct compat_statfs __user *buf);
  455. asmlinkage long compat_sys_statfs64(const char __user *pathname,
  456. compat_size_t sz,
  457. struct compat_statfs64 __user *buf);
  458. asmlinkage long compat_sys_fstatfs(unsigned int fd,
  459. struct compat_statfs __user *buf);
  460. asmlinkage long compat_sys_fstatfs64(unsigned int fd, compat_size_t sz,
  461. struct compat_statfs64 __user *buf);
  462. asmlinkage long compat_sys_truncate(const char __user *, compat_off_t);
  463. asmlinkage long compat_sys_ftruncate(unsigned int, compat_ulong_t);
  464. /* No generic prototype for truncate64, ftruncate64, fallocate */
  465. asmlinkage long compat_sys_openat(int dfd, const char __user *filename,
  466. int flags, umode_t mode);
  467. /* fs/readdir.c */
  468. asmlinkage long compat_sys_getdents(unsigned int fd,
  469. struct compat_linux_dirent __user *dirent,
  470. unsigned int count);
  471. /* fs/read_write.c */
  472. asmlinkage long compat_sys_lseek(unsigned int, compat_off_t, unsigned int);
  473. /* No generic prototype for pread64 and pwrite64 */
  474. asmlinkage ssize_t compat_sys_preadv(compat_ulong_t fd,
  475. const struct iovec __user *vec,
  476. compat_ulong_t vlen, u32 pos_low, u32 pos_high);
  477. asmlinkage ssize_t compat_sys_pwritev(compat_ulong_t fd,
  478. const struct iovec __user *vec,
  479. compat_ulong_t vlen, u32 pos_low, u32 pos_high);
  480. #ifdef __ARCH_WANT_COMPAT_SYS_PREADV64
  481. asmlinkage long compat_sys_preadv64(unsigned long fd,
  482. const struct iovec __user *vec,
  483. unsigned long vlen, loff_t pos);
  484. #endif
  485. #ifdef __ARCH_WANT_COMPAT_SYS_PWRITEV64
  486. asmlinkage long compat_sys_pwritev64(unsigned long fd,
  487. const struct iovec __user *vec,
  488. unsigned long vlen, loff_t pos);
  489. #endif
  490. /* fs/sendfile.c */
  491. asmlinkage long compat_sys_sendfile(int out_fd, int in_fd,
  492. compat_off_t __user *offset, compat_size_t count);
  493. asmlinkage long compat_sys_sendfile64(int out_fd, int in_fd,
  494. compat_loff_t __user *offset, compat_size_t count);
  495. /* fs/select.c */
  496. asmlinkage long compat_sys_pselect6_time32(int n, compat_ulong_t __user *inp,
  497. compat_ulong_t __user *outp,
  498. compat_ulong_t __user *exp,
  499. struct old_timespec32 __user *tsp,
  500. void __user *sig);
  501. asmlinkage long compat_sys_pselect6_time64(int n, compat_ulong_t __user *inp,
  502. compat_ulong_t __user *outp,
  503. compat_ulong_t __user *exp,
  504. struct __kernel_timespec __user *tsp,
  505. void __user *sig);
  506. asmlinkage long compat_sys_ppoll_time32(struct pollfd __user *ufds,
  507. unsigned int nfds,
  508. struct old_timespec32 __user *tsp,
  509. const compat_sigset_t __user *sigmask,
  510. compat_size_t sigsetsize);
  511. asmlinkage long compat_sys_ppoll_time64(struct pollfd __user *ufds,
  512. unsigned int nfds,
  513. struct __kernel_timespec __user *tsp,
  514. const compat_sigset_t __user *sigmask,
  515. compat_size_t sigsetsize);
  516. /* fs/signalfd.c */
  517. asmlinkage long compat_sys_signalfd4(int ufd,
  518. const compat_sigset_t __user *sigmask,
  519. compat_size_t sigsetsize, int flags);
  520. /* fs/stat.c */
  521. asmlinkage long compat_sys_newfstatat(unsigned int dfd,
  522. const char __user *filename,
  523. struct compat_stat __user *statbuf,
  524. int flag);
  525. asmlinkage long compat_sys_newfstat(unsigned int fd,
  526. struct compat_stat __user *statbuf);
  527. /* fs/sync.c: No generic prototype for sync_file_range and sync_file_range2 */
  528. /* kernel/exit.c */
  529. asmlinkage long compat_sys_waitid(int, compat_pid_t,
  530. struct compat_siginfo __user *, int,
  531. struct compat_rusage __user *);
  532. /* kernel/futex.c */
  533. asmlinkage long
  534. compat_sys_set_robust_list(struct compat_robust_list_head __user *head,
  535. compat_size_t len);
  536. asmlinkage long
  537. compat_sys_get_robust_list(int pid, compat_uptr_t __user *head_ptr,
  538. compat_size_t __user *len_ptr);
  539. /* kernel/itimer.c */
  540. asmlinkage long compat_sys_getitimer(int which,
  541. struct old_itimerval32 __user *it);
  542. asmlinkage long compat_sys_setitimer(int which,
  543. struct old_itimerval32 __user *in,
  544. struct old_itimerval32 __user *out);
  545. /* kernel/kexec.c */
  546. asmlinkage long compat_sys_kexec_load(compat_ulong_t entry,
  547. compat_ulong_t nr_segments,
  548. struct compat_kexec_segment __user *,
  549. compat_ulong_t flags);
  550. /* kernel/posix-timers.c */
  551. asmlinkage long compat_sys_timer_create(clockid_t which_clock,
  552. struct compat_sigevent __user *timer_event_spec,
  553. timer_t __user *created_timer_id);
  554. /* kernel/ptrace.c */
  555. asmlinkage long compat_sys_ptrace(compat_long_t request, compat_long_t pid,
  556. compat_long_t addr, compat_long_t data);
  557. /* kernel/sched/core.c */
  558. asmlinkage long compat_sys_sched_setaffinity(compat_pid_t pid,
  559. unsigned int len,
  560. compat_ulong_t __user *user_mask_ptr);
  561. asmlinkage long compat_sys_sched_getaffinity(compat_pid_t pid,
  562. unsigned int len,
  563. compat_ulong_t __user *user_mask_ptr);
  564. /* kernel/signal.c */
  565. asmlinkage long compat_sys_sigaltstack(const compat_stack_t __user *uss_ptr,
  566. compat_stack_t __user *uoss_ptr);
  567. asmlinkage long compat_sys_rt_sigsuspend(compat_sigset_t __user *unewset,
  568. compat_size_t sigsetsize);
  569. #ifndef CONFIG_ODD_RT_SIGACTION
  570. asmlinkage long compat_sys_rt_sigaction(int,
  571. const struct compat_sigaction __user *,
  572. struct compat_sigaction __user *,
  573. compat_size_t);
  574. #endif
  575. asmlinkage long compat_sys_rt_sigprocmask(int how, compat_sigset_t __user *set,
  576. compat_sigset_t __user *oset,
  577. compat_size_t sigsetsize);
  578. asmlinkage long compat_sys_rt_sigpending(compat_sigset_t __user *uset,
  579. compat_size_t sigsetsize);
  580. asmlinkage long compat_sys_rt_sigtimedwait_time32(compat_sigset_t __user *uthese,
  581. struct compat_siginfo __user *uinfo,
  582. struct old_timespec32 __user *uts, compat_size_t sigsetsize);
  583. asmlinkage long compat_sys_rt_sigtimedwait_time64(compat_sigset_t __user *uthese,
  584. struct compat_siginfo __user *uinfo,
  585. struct __kernel_timespec __user *uts, compat_size_t sigsetsize);
  586. asmlinkage long compat_sys_rt_sigqueueinfo(compat_pid_t pid, int sig,
  587. struct compat_siginfo __user *uinfo);
  588. /* No generic prototype for rt_sigreturn */
  589. /* kernel/sys.c */
  590. asmlinkage long compat_sys_times(struct compat_tms __user *tbuf);
  591. asmlinkage long compat_sys_getrlimit(unsigned int resource,
  592. struct compat_rlimit __user *rlim);
  593. asmlinkage long compat_sys_setrlimit(unsigned int resource,
  594. struct compat_rlimit __user *rlim);
  595. asmlinkage long compat_sys_getrusage(int who, struct compat_rusage __user *ru);
  596. /* kernel/time.c */
  597. asmlinkage long compat_sys_gettimeofday(struct old_timeval32 __user *tv,
  598. struct timezone __user *tz);
  599. asmlinkage long compat_sys_settimeofday(struct old_timeval32 __user *tv,
  600. struct timezone __user *tz);
  601. /* kernel/timer.c */
  602. asmlinkage long compat_sys_sysinfo(struct compat_sysinfo __user *info);
  603. /* ipc/mqueue.c */
  604. asmlinkage long compat_sys_mq_open(const char __user *u_name,
  605. int oflag, compat_mode_t mode,
  606. struct compat_mq_attr __user *u_attr);
  607. asmlinkage long compat_sys_mq_notify(mqd_t mqdes,
  608. const struct compat_sigevent __user *u_notification);
  609. asmlinkage long compat_sys_mq_getsetattr(mqd_t mqdes,
  610. const struct compat_mq_attr __user *u_mqstat,
  611. struct compat_mq_attr __user *u_omqstat);
  612. /* ipc/msg.c */
  613. asmlinkage long compat_sys_msgctl(int first, int second, void __user *uptr);
  614. asmlinkage long compat_sys_msgrcv(int msqid, compat_uptr_t msgp,
  615. compat_ssize_t msgsz, compat_long_t msgtyp, int msgflg);
  616. asmlinkage long compat_sys_msgsnd(int msqid, compat_uptr_t msgp,
  617. compat_ssize_t msgsz, int msgflg);
  618. /* ipc/sem.c */
  619. asmlinkage long compat_sys_semctl(int semid, int semnum, int cmd, int arg);
  620. /* ipc/shm.c */
  621. asmlinkage long compat_sys_shmctl(int first, int second, void __user *uptr);
  622. asmlinkage long compat_sys_shmat(int shmid, compat_uptr_t shmaddr, int shmflg);
  623. /* net/socket.c */
  624. asmlinkage long compat_sys_recvfrom(int fd, void __user *buf, compat_size_t len,
  625. unsigned flags, struct sockaddr __user *addr,
  626. int __user *addrlen);
  627. asmlinkage long compat_sys_sendmsg(int fd, struct compat_msghdr __user *msg,
  628. unsigned flags);
  629. asmlinkage long compat_sys_recvmsg(int fd, struct compat_msghdr __user *msg,
  630. unsigned int flags);
  631. /* mm/filemap.c: No generic prototype for readahead */
  632. /* security/keys/keyctl.c */
  633. asmlinkage long compat_sys_keyctl(u32 option,
  634. u32 arg2, u32 arg3, u32 arg4, u32 arg5);
  635. /* arch/example/kernel/sys_example.c */
  636. asmlinkage long compat_sys_execve(const char __user *filename, const compat_uptr_t __user *argv,
  637. const compat_uptr_t __user *envp);
  638. /* mm/fadvise.c: No generic prototype for fadvise64_64 */
  639. /* mm/, CONFIG_MMU only */
  640. asmlinkage long compat_sys_mbind(compat_ulong_t start, compat_ulong_t len,
  641. compat_ulong_t mode,
  642. compat_ulong_t __user *nmask,
  643. compat_ulong_t maxnode, compat_ulong_t flags);
  644. asmlinkage long compat_sys_get_mempolicy(int __user *policy,
  645. compat_ulong_t __user *nmask,
  646. compat_ulong_t maxnode,
  647. compat_ulong_t addr,
  648. compat_ulong_t flags);
  649. asmlinkage long compat_sys_set_mempolicy(int mode, compat_ulong_t __user *nmask,
  650. compat_ulong_t maxnode);
  651. asmlinkage long compat_sys_migrate_pages(compat_pid_t pid,
  652. compat_ulong_t maxnode, const compat_ulong_t __user *old_nodes,
  653. const compat_ulong_t __user *new_nodes);
  654. asmlinkage long compat_sys_move_pages(pid_t pid, compat_ulong_t nr_pages,
  655. __u32 __user *pages,
  656. const int __user *nodes,
  657. int __user *status,
  658. int flags);
  659. asmlinkage long compat_sys_rt_tgsigqueueinfo(compat_pid_t tgid,
  660. compat_pid_t pid, int sig,
  661. struct compat_siginfo __user *uinfo);
  662. asmlinkage long compat_sys_recvmmsg_time64(int fd, struct compat_mmsghdr __user *mmsg,
  663. unsigned vlen, unsigned int flags,
  664. struct __kernel_timespec __user *timeout);
  665. asmlinkage long compat_sys_recvmmsg_time32(int fd, struct compat_mmsghdr __user *mmsg,
  666. unsigned vlen, unsigned int flags,
  667. struct old_timespec32 __user *timeout);
  668. asmlinkage long compat_sys_wait4(compat_pid_t pid,
  669. compat_uint_t __user *stat_addr, int options,
  670. struct compat_rusage __user *ru);
  671. asmlinkage long compat_sys_fanotify_mark(int, unsigned int, __u32, __u32,
  672. int, const char __user *);
  673. asmlinkage long compat_sys_open_by_handle_at(int mountdirfd,
  674. struct file_handle __user *handle,
  675. int flags);
  676. asmlinkage long compat_sys_sendmmsg(int fd, struct compat_mmsghdr __user *mmsg,
  677. unsigned vlen, unsigned int flags);
  678. asmlinkage long compat_sys_execveat(int dfd, const char __user *filename,
  679. const compat_uptr_t __user *argv,
  680. const compat_uptr_t __user *envp, int flags);
  681. asmlinkage ssize_t compat_sys_preadv2(compat_ulong_t fd,
  682. const struct iovec __user *vec,
  683. compat_ulong_t vlen, u32 pos_low, u32 pos_high, rwf_t flags);
  684. asmlinkage ssize_t compat_sys_pwritev2(compat_ulong_t fd,
  685. const struct iovec __user *vec,
  686. compat_ulong_t vlen, u32 pos_low, u32 pos_high, rwf_t flags);
  687. #ifdef __ARCH_WANT_COMPAT_SYS_PREADV64V2
  688. asmlinkage long compat_sys_preadv64v2(unsigned long fd,
  689. const struct iovec __user *vec,
  690. unsigned long vlen, loff_t pos, rwf_t flags);
  691. #endif
  692. #ifdef __ARCH_WANT_COMPAT_SYS_PWRITEV64V2
  693. asmlinkage long compat_sys_pwritev64v2(unsigned long fd,
  694. const struct iovec __user *vec,
  695. unsigned long vlen, loff_t pos, rwf_t flags);
  696. #endif
  697. /*
  698. * Deprecated system calls which are still defined in
  699. * include/uapi/asm-generic/unistd.h and wanted by >= 1 arch
  700. */
  701. /* __ARCH_WANT_SYSCALL_NO_AT */
  702. asmlinkage long compat_sys_open(const char __user *filename, int flags,
  703. umode_t mode);
  704. /* __ARCH_WANT_SYSCALL_NO_FLAGS */
  705. asmlinkage long compat_sys_signalfd(int ufd,
  706. const compat_sigset_t __user *sigmask,
  707. compat_size_t sigsetsize);
  708. /* __ARCH_WANT_SYSCALL_OFF_T */
  709. asmlinkage long compat_sys_newstat(const char __user *filename,
  710. struct compat_stat __user *statbuf);
  711. asmlinkage long compat_sys_newlstat(const char __user *filename,
  712. struct compat_stat __user *statbuf);
  713. /* __ARCH_WANT_SYSCALL_DEPRECATED */
  714. asmlinkage long compat_sys_select(int n, compat_ulong_t __user *inp,
  715. compat_ulong_t __user *outp, compat_ulong_t __user *exp,
  716. struct old_timeval32 __user *tvp);
  717. asmlinkage long compat_sys_ustat(unsigned dev, struct compat_ustat __user *u32);
  718. asmlinkage long compat_sys_recv(int fd, void __user *buf, compat_size_t len,
  719. unsigned flags);
  720. /* obsolete: fs/readdir.c */
  721. asmlinkage long compat_sys_old_readdir(unsigned int fd,
  722. struct compat_old_linux_dirent __user *,
  723. unsigned int count);
  724. /* obsolete: fs/select.c */
  725. asmlinkage long compat_sys_old_select(struct compat_sel_arg_struct __user *arg);
  726. /* obsolete: ipc */
  727. asmlinkage long compat_sys_ipc(u32, int, int, u32, compat_uptr_t, u32);
  728. /* obsolete: kernel/signal.c */
  729. #ifdef __ARCH_WANT_SYS_SIGPENDING
  730. asmlinkage long compat_sys_sigpending(compat_old_sigset_t __user *set);
  731. #endif
  732. #ifdef __ARCH_WANT_SYS_SIGPROCMASK
  733. asmlinkage long compat_sys_sigprocmask(int how, compat_old_sigset_t __user *nset,
  734. compat_old_sigset_t __user *oset);
  735. #endif
  736. #ifdef CONFIG_COMPAT_OLD_SIGACTION
  737. asmlinkage long compat_sys_sigaction(int sig,
  738. const struct compat_old_sigaction __user *act,
  739. struct compat_old_sigaction __user *oact);
  740. #endif
  741. /* obsolete: net/socket.c */
  742. asmlinkage long compat_sys_socketcall(int call, u32 __user *args);
  743. #endif /* CONFIG_ARCH_HAS_SYSCALL_WRAPPER */
  744. /*
  745. * For most but not all architectures, "am I in a compat syscall?" and
  746. * "am I a compat task?" are the same question. For architectures on which
  747. * they aren't the same question, arch code can override in_compat_syscall.
  748. */
  749. #ifndef in_compat_syscall
  750. static inline bool in_compat_syscall(void) { return is_compat_task(); }
  751. #endif
  752. /**
  753. * ns_to_old_timeval32 - Compat version of ns_to_timeval
  754. * @nsec: the nanoseconds value to be converted
  755. *
  756. * Returns the old_timeval32 representation of the nsec parameter.
  757. */
  758. static inline struct old_timeval32 ns_to_old_timeval32(s64 nsec)
  759. {
  760. struct __kernel_old_timeval tv;
  761. struct old_timeval32 ctv;
  762. tv = ns_to_kernel_old_timeval(nsec);
  763. ctv.tv_sec = tv.tv_sec;
  764. ctv.tv_usec = tv.tv_usec;
  765. return ctv;
  766. }
  767. /*
  768. * Kernel code should not call compat syscalls (i.e., compat_sys_xyzyyz())
  769. * directly. Instead, use one of the functions which work equivalently, such
  770. * as the kcompat_sys_xyzyyz() functions prototyped below.
  771. */
  772. int kcompat_sys_statfs64(const char __user * pathname, compat_size_t sz,
  773. struct compat_statfs64 __user * buf);
  774. int kcompat_sys_fstatfs64(unsigned int fd, compat_size_t sz,
  775. struct compat_statfs64 __user * buf);
  776. #else /* !CONFIG_COMPAT */
  777. #define is_compat_task() (0)
  778. /* Ensure no one redefines in_compat_syscall() under !CONFIG_COMPAT */
  779. #define in_compat_syscall in_compat_syscall
  780. static inline bool in_compat_syscall(void) { return false; }
  781. #endif /* CONFIG_COMPAT */
  782. /*
  783. * Some legacy ABIs like the i386 one use less than natural alignment for 64-bit
  784. * types, and will need special compat treatment for that. Most architectures
  785. * don't need that special handling even for compat syscalls.
  786. */
  787. #ifndef compat_need_64bit_alignment_fixup
  788. #define compat_need_64bit_alignment_fixup() false
  789. #endif
  790. /*
  791. * A pointer passed in from user mode. This should not
  792. * be used for syscall parameters, just declare them
  793. * as pointers because the syscall entry code will have
  794. * appropriately converted them already.
  795. */
  796. #ifndef compat_ptr
  797. static inline void __user *compat_ptr(compat_uptr_t uptr)
  798. {
  799. return (void __user *)(unsigned long)uptr;
  800. }
  801. #endif
  802. static inline compat_uptr_t ptr_to_compat(void __user *uptr)
  803. {
  804. return (u32)(unsigned long)uptr;
  805. }
  806. #endif /* _LINUX_COMPAT_H */