compat.h 30 KB

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