compat.h 8.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308
  1. /*
  2. * Copyright 2010 Tilera Corporation. All Rights Reserved.
  3. *
  4. * This program is free software; you can redistribute it and/or
  5. * modify it under the terms of the GNU General Public License
  6. * as published by the Free Software Foundation, version 2.
  7. *
  8. * This program is distributed in the hope that it will be useful, but
  9. * WITHOUT ANY WARRANTY; without even the implied warranty of
  10. * MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE, GOOD TITLE or
  11. * NON INFRINGEMENT. See the GNU General Public License for
  12. * more details.
  13. */
  14. #ifndef _ASM_TILE_COMPAT_H
  15. #define _ASM_TILE_COMPAT_H
  16. /*
  17. * Architecture specific compatibility types
  18. */
  19. #include <linux/types.h>
  20. #include <linux/sched.h>
  21. #define COMPAT_USER_HZ 100
  22. /* "long" and pointer-based types are different. */
  23. typedef s32 compat_long_t;
  24. typedef u32 compat_ulong_t;
  25. typedef u32 compat_size_t;
  26. typedef s32 compat_ssize_t;
  27. typedef s32 compat_off_t;
  28. typedef s32 compat_time_t;
  29. typedef s32 compat_clock_t;
  30. typedef u32 compat_ino_t;
  31. typedef u32 compat_caddr_t;
  32. typedef u32 compat_uptr_t;
  33. /* Many types are "int" or otherwise the same. */
  34. typedef __kernel_pid_t compat_pid_t;
  35. typedef __kernel_uid_t __compat_uid_t;
  36. typedef __kernel_gid_t __compat_gid_t;
  37. typedef __kernel_uid32_t __compat_uid32_t;
  38. typedef __kernel_uid32_t __compat_gid32_t;
  39. typedef __kernel_mode_t compat_mode_t;
  40. typedef __kernel_dev_t compat_dev_t;
  41. typedef __kernel_loff_t compat_loff_t;
  42. typedef __kernel_nlink_t compat_nlink_t;
  43. typedef __kernel_ipc_pid_t compat_ipc_pid_t;
  44. typedef __kernel_daddr_t compat_daddr_t;
  45. typedef __kernel_fsid_t compat_fsid_t;
  46. typedef __kernel_timer_t compat_timer_t;
  47. typedef __kernel_key_t compat_key_t;
  48. typedef int compat_int_t;
  49. typedef s64 compat_s64;
  50. typedef uint compat_uint_t;
  51. typedef u64 compat_u64;
  52. /* We use the same register dump format in 32-bit images. */
  53. typedef unsigned long compat_elf_greg_t;
  54. #define COMPAT_ELF_NGREG (sizeof(struct pt_regs) / sizeof(compat_elf_greg_t))
  55. typedef compat_elf_greg_t compat_elf_gregset_t[COMPAT_ELF_NGREG];
  56. struct compat_timespec {
  57. compat_time_t tv_sec;
  58. s32 tv_nsec;
  59. };
  60. struct compat_timeval {
  61. compat_time_t tv_sec;
  62. s32 tv_usec;
  63. };
  64. struct compat_stat {
  65. unsigned int st_dev;
  66. unsigned int st_ino;
  67. unsigned int st_mode;
  68. unsigned int st_nlink;
  69. unsigned int st_uid;
  70. unsigned int st_gid;
  71. unsigned int st_rdev;
  72. unsigned int __pad1;
  73. int st_size;
  74. int st_blksize;
  75. int __pad2;
  76. int st_blocks;
  77. int st_atime;
  78. unsigned int st_atime_nsec;
  79. int st_mtime;
  80. unsigned int st_mtime_nsec;
  81. int st_ctime;
  82. unsigned int st_ctime_nsec;
  83. unsigned int __unused[2];
  84. };
  85. struct compat_stat64 {
  86. unsigned long st_dev;
  87. unsigned long st_ino;
  88. unsigned int st_mode;
  89. unsigned int st_nlink;
  90. unsigned int st_uid;
  91. unsigned int st_gid;
  92. unsigned long st_rdev;
  93. long st_size;
  94. unsigned int st_blksize;
  95. unsigned long st_blocks __attribute__((packed));
  96. unsigned int st_atime;
  97. unsigned int st_atime_nsec;
  98. unsigned int st_mtime;
  99. unsigned int st_mtime_nsec;
  100. unsigned int st_ctime;
  101. unsigned int st_ctime_nsec;
  102. unsigned int __unused8;
  103. };
  104. #define compat_statfs statfs
  105. struct compat_sysctl {
  106. unsigned int name;
  107. int nlen;
  108. unsigned int oldval;
  109. unsigned int oldlenp;
  110. unsigned int newval;
  111. unsigned int newlen;
  112. unsigned int __unused[4];
  113. };
  114. struct compat_flock {
  115. short l_type;
  116. short l_whence;
  117. compat_off_t l_start;
  118. compat_off_t l_len;
  119. compat_pid_t l_pid;
  120. };
  121. #define F_GETLK64 12 /* using 'struct flock64' */
  122. #define F_SETLK64 13
  123. #define F_SETLKW64 14
  124. struct compat_flock64 {
  125. short l_type;
  126. short l_whence;
  127. compat_loff_t l_start;
  128. compat_loff_t l_len;
  129. compat_pid_t l_pid;
  130. };
  131. #define COMPAT_RLIM_INFINITY 0xffffffff
  132. #define _COMPAT_NSIG 64
  133. #define _COMPAT_NSIG_BPW 32
  134. typedef u32 compat_sigset_word;
  135. #define COMPAT_OFF_T_MAX 0x7fffffff
  136. #define COMPAT_LOFF_T_MAX 0x7fffffffffffffffL
  137. struct compat_ipc64_perm {
  138. compat_key_t key;
  139. __compat_uid32_t uid;
  140. __compat_gid32_t gid;
  141. __compat_uid32_t cuid;
  142. __compat_gid32_t cgid;
  143. unsigned short mode;
  144. unsigned short __pad1;
  145. unsigned short seq;
  146. unsigned short __pad2;
  147. compat_ulong_t unused1;
  148. compat_ulong_t unused2;
  149. };
  150. struct compat_semid64_ds {
  151. struct compat_ipc64_perm sem_perm;
  152. compat_time_t sem_otime;
  153. compat_ulong_t __unused1;
  154. compat_time_t sem_ctime;
  155. compat_ulong_t __unused2;
  156. compat_ulong_t sem_nsems;
  157. compat_ulong_t __unused3;
  158. compat_ulong_t __unused4;
  159. };
  160. struct compat_msqid64_ds {
  161. struct compat_ipc64_perm msg_perm;
  162. compat_time_t msg_stime;
  163. compat_ulong_t __unused1;
  164. compat_time_t msg_rtime;
  165. compat_ulong_t __unused2;
  166. compat_time_t msg_ctime;
  167. compat_ulong_t __unused3;
  168. compat_ulong_t msg_cbytes;
  169. compat_ulong_t msg_qnum;
  170. compat_ulong_t msg_qbytes;
  171. compat_pid_t msg_lspid;
  172. compat_pid_t msg_lrpid;
  173. compat_ulong_t __unused4;
  174. compat_ulong_t __unused5;
  175. };
  176. struct compat_shmid64_ds {
  177. struct compat_ipc64_perm shm_perm;
  178. compat_size_t shm_segsz;
  179. compat_time_t shm_atime;
  180. compat_ulong_t __unused1;
  181. compat_time_t shm_dtime;
  182. compat_ulong_t __unused2;
  183. compat_time_t shm_ctime;
  184. compat_ulong_t __unused3;
  185. compat_pid_t shm_cpid;
  186. compat_pid_t shm_lpid;
  187. compat_ulong_t shm_nattch;
  188. compat_ulong_t __unused4;
  189. compat_ulong_t __unused5;
  190. };
  191. /*
  192. * A pointer passed in from user mode. This should not
  193. * be used for syscall parameters, just declare them
  194. * as pointers because the syscall entry code will have
  195. * appropriately converted them already.
  196. */
  197. static inline void __user *compat_ptr(compat_uptr_t uptr)
  198. {
  199. return (void __user *)(long)(s32)uptr;
  200. }
  201. static inline compat_uptr_t ptr_to_compat(void __user *uptr)
  202. {
  203. return (u32)(unsigned long)uptr;
  204. }
  205. /* Sign-extend when storing a kernel pointer to a user's ptregs. */
  206. static inline unsigned long ptr_to_compat_reg(void __user *uptr)
  207. {
  208. return (long)(int)(long)uptr;
  209. }
  210. static inline void __user *compat_alloc_user_space(long len)
  211. {
  212. struct pt_regs *regs = task_pt_regs(current);
  213. return (void __user *)regs->sp - len;
  214. }
  215. static inline int is_compat_task(void)
  216. {
  217. return current_thread_info()->status & TS_COMPAT;
  218. }
  219. extern int compat_setup_rt_frame(int sig, struct k_sigaction *ka,
  220. siginfo_t *info, sigset_t *set,
  221. struct pt_regs *regs);
  222. /* Compat syscalls. */
  223. struct compat_sigaction;
  224. struct compat_siginfo;
  225. struct compat_sigaltstack;
  226. long compat_sys_execve(char __user *path, compat_uptr_t __user *argv,
  227. compat_uptr_t __user *envp);
  228. long compat_sys_rt_sigaction(int sig, struct compat_sigaction __user *act,
  229. struct compat_sigaction __user *oact,
  230. size_t sigsetsize);
  231. long compat_sys_rt_sigqueueinfo(int pid, int sig,
  232. struct compat_siginfo __user *uinfo);
  233. long compat_sys_rt_sigreturn(void);
  234. long compat_sys_sigaltstack(const struct compat_sigaltstack __user *uss_ptr,
  235. struct compat_sigaltstack __user *uoss_ptr);
  236. long compat_sys_truncate64(char __user *filename, u32 dummy, u32 low, u32 high);
  237. long compat_sys_ftruncate64(unsigned int fd, u32 dummy, u32 low, u32 high);
  238. long compat_sys_pread64(unsigned int fd, char __user *ubuf, size_t count,
  239. u32 dummy, u32 low, u32 high);
  240. long compat_sys_pwrite64(unsigned int fd, char __user *ubuf, size_t count,
  241. u32 dummy, u32 low, u32 high);
  242. long compat_sys_lookup_dcookie(u32 low, u32 high, char __user *buf, size_t len);
  243. long compat_sys_sync_file_range2(int fd, unsigned int flags,
  244. u32 offset_lo, u32 offset_hi,
  245. u32 nbytes_lo, u32 nbytes_hi);
  246. long compat_sys_fallocate(int fd, int mode,
  247. u32 offset_lo, u32 offset_hi,
  248. u32 len_lo, u32 len_hi);
  249. long compat_sys_stat64(char __user *filename,
  250. struct compat_stat64 __user *statbuf);
  251. long compat_sys_lstat64(char __user *filename,
  252. struct compat_stat64 __user *statbuf);
  253. long compat_sys_fstat64(unsigned int fd, struct compat_stat64 __user *statbuf);
  254. long compat_sys_fstatat64(int dfd, char __user *filename,
  255. struct compat_stat64 __user *statbuf, int flag);
  256. long compat_sys_sched_rr_get_interval(compat_pid_t pid,
  257. struct compat_timespec __user *interval);
  258. ssize_t compat_sys_sendfile(int out_fd, int in_fd, compat_off_t __user *offset,
  259. size_t count);
  260. /* Versions of compat functions that differ from generic Linux. */
  261. struct compat_msgbuf;
  262. long tile_compat_sys_msgsnd(int msqid,
  263. struct compat_msgbuf __user *msgp,
  264. size_t msgsz, int msgflg);
  265. long tile_compat_sys_msgrcv(int msqid,
  266. struct compat_msgbuf __user *msgp,
  267. size_t msgsz, long msgtyp, int msgflg);
  268. long tile_compat_sys_ptrace(compat_long_t request, compat_long_t pid,
  269. compat_long_t addr, compat_long_t data);
  270. /* Tilera Linux syscalls that don't have "compat" versions. */
  271. #define compat_sys_raise_fpe sys_raise_fpe
  272. #define compat_sys_flush_cache sys_flush_cache
  273. #endif /* _ASM_TILE_COMPAT_H */