compat.h 33 KB

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