compat.h 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367
  1. #ifndef _LINUX_COMPAT_H
  2. #define _LINUX_COMPAT_H
  3. /*
  4. * These are the type definitions for the architecture specific
  5. * syscall compatibility layer.
  6. */
  7. #ifdef CONFIG_COMPAT
  8. #include <linux/stat.h>
  9. #include <linux/param.h> /* for HZ */
  10. #include <linux/sem.h>
  11. #include <linux/socket.h>
  12. #include <linux/if.h>
  13. #include <asm/compat.h>
  14. #include <asm/siginfo.h>
  15. #include <asm/signal.h>
  16. #define compat_jiffies_to_clock_t(x) \
  17. (((unsigned long)(x) * COMPAT_USER_HZ) / HZ)
  18. typedef __compat_uid32_t compat_uid_t;
  19. typedef __compat_gid32_t compat_gid_t;
  20. struct compat_sel_arg_struct;
  21. struct rusage;
  22. struct compat_itimerspec {
  23. struct compat_timespec it_interval;
  24. struct compat_timespec it_value;
  25. };
  26. struct compat_utimbuf {
  27. compat_time_t actime;
  28. compat_time_t modtime;
  29. };
  30. struct compat_itimerval {
  31. struct compat_timeval it_interval;
  32. struct compat_timeval it_value;
  33. };
  34. struct compat_tms {
  35. compat_clock_t tms_utime;
  36. compat_clock_t tms_stime;
  37. compat_clock_t tms_cutime;
  38. compat_clock_t tms_cstime;
  39. };
  40. struct compat_timex {
  41. compat_uint_t modes;
  42. compat_long_t offset;
  43. compat_long_t freq;
  44. compat_long_t maxerror;
  45. compat_long_t esterror;
  46. compat_int_t status;
  47. compat_long_t constant;
  48. compat_long_t precision;
  49. compat_long_t tolerance;
  50. struct compat_timeval time;
  51. compat_long_t tick;
  52. compat_long_t ppsfreq;
  53. compat_long_t jitter;
  54. compat_int_t shift;
  55. compat_long_t stabil;
  56. compat_long_t jitcnt;
  57. compat_long_t calcnt;
  58. compat_long_t errcnt;
  59. compat_long_t stbcnt;
  60. compat_int_t tai;
  61. compat_int_t :32; compat_int_t :32; compat_int_t :32; compat_int_t :32;
  62. compat_int_t :32; compat_int_t :32; compat_int_t :32; compat_int_t :32;
  63. compat_int_t :32; compat_int_t :32; compat_int_t :32;
  64. };
  65. #define _COMPAT_NSIG_WORDS (_COMPAT_NSIG / _COMPAT_NSIG_BPW)
  66. typedef struct {
  67. compat_sigset_word sig[_COMPAT_NSIG_WORDS];
  68. } compat_sigset_t;
  69. extern int get_compat_timespec(struct timespec *, const struct compat_timespec __user *);
  70. extern int put_compat_timespec(const struct timespec *, struct compat_timespec __user *);
  71. struct compat_iovec {
  72. compat_uptr_t iov_base;
  73. compat_size_t iov_len;
  74. };
  75. struct compat_rlimit {
  76. compat_ulong_t rlim_cur;
  77. compat_ulong_t rlim_max;
  78. };
  79. struct compat_rusage {
  80. struct compat_timeval ru_utime;
  81. struct compat_timeval ru_stime;
  82. compat_long_t ru_maxrss;
  83. compat_long_t ru_ixrss;
  84. compat_long_t ru_idrss;
  85. compat_long_t ru_isrss;
  86. compat_long_t ru_minflt;
  87. compat_long_t ru_majflt;
  88. compat_long_t ru_nswap;
  89. compat_long_t ru_inblock;
  90. compat_long_t ru_oublock;
  91. compat_long_t ru_msgsnd;
  92. compat_long_t ru_msgrcv;
  93. compat_long_t ru_nsignals;
  94. compat_long_t ru_nvcsw;
  95. compat_long_t ru_nivcsw;
  96. };
  97. extern int put_compat_rusage(const struct rusage *, struct compat_rusage __user *);
  98. struct compat_siginfo;
  99. extern asmlinkage long compat_sys_waitid(int, compat_pid_t,
  100. struct compat_siginfo __user *, int,
  101. struct compat_rusage __user *);
  102. struct compat_dirent {
  103. u32 d_ino;
  104. compat_off_t d_off;
  105. u16 d_reclen;
  106. char d_name[256];
  107. };
  108. struct compat_ustat {
  109. compat_daddr_t f_tfree;
  110. compat_ino_t f_tinode;
  111. char f_fname[6];
  112. char f_fpack[6];
  113. };
  114. typedef union compat_sigval {
  115. compat_int_t sival_int;
  116. compat_uptr_t sival_ptr;
  117. } compat_sigval_t;
  118. #define COMPAT_SIGEV_PAD_SIZE ((SIGEV_MAX_SIZE/sizeof(int)) - 3)
  119. typedef struct compat_sigevent {
  120. compat_sigval_t sigev_value;
  121. compat_int_t sigev_signo;
  122. compat_int_t sigev_notify;
  123. union {
  124. compat_int_t _pad[COMPAT_SIGEV_PAD_SIZE];
  125. compat_int_t _tid;
  126. struct {
  127. compat_uptr_t _function;
  128. compat_uptr_t _attribute;
  129. } _sigev_thread;
  130. } _sigev_un;
  131. } compat_sigevent_t;
  132. struct compat_ifmap {
  133. compat_ulong_t mem_start;
  134. compat_ulong_t mem_end;
  135. unsigned short base_addr;
  136. unsigned char irq;
  137. unsigned char dma;
  138. unsigned char port;
  139. };
  140. struct compat_if_settings
  141. {
  142. unsigned int type; /* Type of physical device or protocol */
  143. unsigned int size; /* Size of the data allocated by the caller */
  144. compat_uptr_t ifs_ifsu; /* union of pointers */
  145. };
  146. struct compat_ifreq {
  147. union {
  148. char ifrn_name[IFNAMSIZ]; /* if name, e.g. "en0" */
  149. } ifr_ifrn;
  150. union {
  151. struct sockaddr ifru_addr;
  152. struct sockaddr ifru_dstaddr;
  153. struct sockaddr ifru_broadaddr;
  154. struct sockaddr ifru_netmask;
  155. struct sockaddr ifru_hwaddr;
  156. short ifru_flags;
  157. compat_int_t ifru_ivalue;
  158. compat_int_t ifru_mtu;
  159. struct compat_ifmap ifru_map;
  160. char ifru_slave[IFNAMSIZ]; /* Just fits the size */
  161. char ifru_newname[IFNAMSIZ];
  162. compat_caddr_t ifru_data;
  163. struct compat_if_settings ifru_settings;
  164. } ifr_ifru;
  165. };
  166. struct compat_ifconf {
  167. compat_int_t ifc_len; /* size of buffer */
  168. compat_caddr_t ifcbuf;
  169. };
  170. struct compat_robust_list {
  171. compat_uptr_t next;
  172. };
  173. struct compat_robust_list_head {
  174. struct compat_robust_list list;
  175. compat_long_t futex_offset;
  176. compat_uptr_t list_op_pending;
  177. };
  178. extern void compat_exit_robust_list(struct task_struct *curr);
  179. asmlinkage long
  180. compat_sys_set_robust_list(struct compat_robust_list_head __user *head,
  181. compat_size_t len);
  182. asmlinkage long
  183. compat_sys_get_robust_list(int pid, compat_uptr_t __user *head_ptr,
  184. compat_size_t __user *len_ptr);
  185. long compat_sys_semctl(int first, int second, int third, void __user *uptr);
  186. long compat_sys_msgsnd(int first, int second, int third, void __user *uptr);
  187. long compat_sys_msgrcv(int first, int second, int msgtyp, int third,
  188. int version, void __user *uptr);
  189. long compat_sys_msgctl(int first, int second, void __user *uptr);
  190. long compat_sys_shmat(int first, int second, compat_uptr_t third, int version,
  191. void __user *uptr);
  192. long compat_sys_shmctl(int first, int second, void __user *uptr);
  193. long compat_sys_semtimedop(int semid, struct sembuf __user *tsems,
  194. unsigned nsems, const struct compat_timespec __user *timeout);
  195. asmlinkage long compat_sys_keyctl(u32 option,
  196. u32 arg2, u32 arg3, u32 arg4, u32 arg5);
  197. asmlinkage long compat_sys_ustat(unsigned dev, struct compat_ustat __user *u32);
  198. asmlinkage ssize_t compat_sys_readv(unsigned long fd,
  199. const struct compat_iovec __user *vec, unsigned long vlen);
  200. asmlinkage ssize_t compat_sys_writev(unsigned long fd,
  201. const struct compat_iovec __user *vec, unsigned long vlen);
  202. asmlinkage ssize_t compat_sys_preadv(unsigned long fd,
  203. const struct compat_iovec __user *vec,
  204. unsigned long vlen, u32 pos_low, u32 pos_high);
  205. asmlinkage ssize_t compat_sys_pwritev(unsigned long fd,
  206. const struct compat_iovec __user *vec,
  207. unsigned long vlen, u32 pos_low, u32 pos_high);
  208. int compat_do_execve(char * filename, compat_uptr_t __user *argv,
  209. compat_uptr_t __user *envp, struct pt_regs * regs);
  210. asmlinkage long compat_sys_select(int n, compat_ulong_t __user *inp,
  211. compat_ulong_t __user *outp, compat_ulong_t __user *exp,
  212. struct compat_timeval __user *tvp);
  213. asmlinkage long compat_sys_old_select(struct compat_sel_arg_struct __user *arg);
  214. asmlinkage long compat_sys_wait4(compat_pid_t pid,
  215. compat_uint_t __user *stat_addr, int options,
  216. struct compat_rusage __user *ru);
  217. #define BITS_PER_COMPAT_LONG (8*sizeof(compat_long_t))
  218. #define BITS_TO_COMPAT_LONGS(bits) \
  219. (((bits)+BITS_PER_COMPAT_LONG-1)/BITS_PER_COMPAT_LONG)
  220. long compat_get_bitmap(unsigned long *mask, const compat_ulong_t __user *umask,
  221. unsigned long bitmap_size);
  222. long compat_put_bitmap(compat_ulong_t __user *umask, unsigned long *mask,
  223. unsigned long bitmap_size);
  224. int copy_siginfo_from_user32(siginfo_t *to, struct compat_siginfo __user *from);
  225. int copy_siginfo_to_user32(struct compat_siginfo __user *to, siginfo_t *from);
  226. int get_compat_sigevent(struct sigevent *event,
  227. const struct compat_sigevent __user *u_event);
  228. long compat_sys_rt_tgsigqueueinfo(compat_pid_t tgid, compat_pid_t pid, int sig,
  229. struct compat_siginfo __user *uinfo);
  230. static inline int compat_timeval_compare(struct compat_timeval *lhs,
  231. struct compat_timeval *rhs)
  232. {
  233. if (lhs->tv_sec < rhs->tv_sec)
  234. return -1;
  235. if (lhs->tv_sec > rhs->tv_sec)
  236. return 1;
  237. return lhs->tv_usec - rhs->tv_usec;
  238. }
  239. static inline int compat_timespec_compare(struct compat_timespec *lhs,
  240. struct compat_timespec *rhs)
  241. {
  242. if (lhs->tv_sec < rhs->tv_sec)
  243. return -1;
  244. if (lhs->tv_sec > rhs->tv_sec)
  245. return 1;
  246. return lhs->tv_nsec - rhs->tv_nsec;
  247. }
  248. extern int get_compat_itimerspec(struct itimerspec *dst,
  249. const struct compat_itimerspec __user *src);
  250. extern int put_compat_itimerspec(struct compat_itimerspec __user *dst,
  251. const struct itimerspec *src);
  252. asmlinkage long compat_sys_gettimeofday(struct compat_timeval __user *tv,
  253. struct timezone __user *tz);
  254. asmlinkage long compat_sys_settimeofday(struct compat_timeval __user *tv,
  255. struct timezone __user *tz);
  256. asmlinkage long compat_sys_adjtimex(struct compat_timex __user *utp);
  257. extern int compat_printk(const char *fmt, ...);
  258. extern void sigset_from_compat(sigset_t *set, compat_sigset_t *compat);
  259. asmlinkage long compat_sys_migrate_pages(compat_pid_t pid,
  260. compat_ulong_t maxnode, const compat_ulong_t __user *old_nodes,
  261. const compat_ulong_t __user *new_nodes);
  262. extern int compat_ptrace_request(struct task_struct *child,
  263. compat_long_t request,
  264. compat_ulong_t addr, compat_ulong_t data);
  265. extern long compat_arch_ptrace(struct task_struct *child, compat_long_t request,
  266. compat_ulong_t addr, compat_ulong_t data);
  267. asmlinkage long compat_sys_ptrace(compat_long_t request, compat_long_t pid,
  268. compat_long_t addr, compat_long_t data);
  269. /*
  270. * epoll (fs/eventpoll.c) compat bits follow ...
  271. */
  272. struct epoll_event;
  273. #define compat_epoll_event epoll_event
  274. asmlinkage long compat_sys_epoll_pwait(int epfd,
  275. struct compat_epoll_event __user *events,
  276. int maxevents, int timeout,
  277. const compat_sigset_t __user *sigmask,
  278. compat_size_t sigsetsize);
  279. asmlinkage long compat_sys_utimensat(unsigned int dfd, const char __user *filename,
  280. struct compat_timespec __user *t, int flags);
  281. asmlinkage long compat_sys_signalfd(int ufd,
  282. const compat_sigset_t __user *sigmask,
  283. compat_size_t sigsetsize);
  284. asmlinkage long compat_sys_timerfd_settime(int ufd, int flags,
  285. const struct compat_itimerspec __user *utmr,
  286. struct compat_itimerspec __user *otmr);
  287. asmlinkage long compat_sys_timerfd_gettime(int ufd,
  288. struct compat_itimerspec __user *otmr);
  289. asmlinkage long compat_sys_move_pages(pid_t pid, unsigned long nr_page,
  290. __u32 __user *pages,
  291. const int __user *nodes,
  292. int __user *status,
  293. int flags);
  294. asmlinkage long compat_sys_futimesat(unsigned int dfd, const char __user *filename,
  295. struct compat_timeval __user *t);
  296. asmlinkage long compat_sys_newfstatat(unsigned int dfd, const char __user * filename,
  297. struct compat_stat __user *statbuf,
  298. int flag);
  299. asmlinkage long compat_sys_openat(unsigned int dfd, const char __user *filename,
  300. int flags, int mode);
  301. extern ssize_t compat_rw_copy_check_uvector(int type,
  302. const struct compat_iovec __user *uvector, unsigned long nr_segs,
  303. unsigned long fast_segs, struct iovec *fast_pointer,
  304. struct iovec **ret_pointer);
  305. extern void __user *compat_alloc_user_space(unsigned long len);
  306. #endif /* CONFIG_COMPAT */
  307. #endif /* _LINUX_COMPAT_H */