compat.h 7.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296
  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_ipc_pid_t compat_ipc_pid_t;
  43. typedef __kernel_daddr_t compat_daddr_t;
  44. typedef __kernel_fsid_t compat_fsid_t;
  45. typedef __kernel_timer_t compat_timer_t;
  46. typedef __kernel_key_t compat_key_t;
  47. typedef int compat_int_t;
  48. typedef s64 compat_s64;
  49. typedef uint compat_uint_t;
  50. typedef u64 compat_u64;
  51. /* We use the same register dump format in 32-bit images. */
  52. typedef unsigned long compat_elf_greg_t;
  53. #define COMPAT_ELF_NGREG (sizeof(struct pt_regs) / sizeof(compat_elf_greg_t))
  54. typedef compat_elf_greg_t compat_elf_gregset_t[COMPAT_ELF_NGREG];
  55. struct compat_timespec {
  56. compat_time_t tv_sec;
  57. s32 tv_nsec;
  58. };
  59. struct compat_timeval {
  60. compat_time_t tv_sec;
  61. s32 tv_usec;
  62. };
  63. #define compat_stat stat
  64. #define compat_statfs statfs
  65. struct compat_sysctl {
  66. unsigned int name;
  67. int nlen;
  68. unsigned int oldval;
  69. unsigned int oldlenp;
  70. unsigned int newval;
  71. unsigned int newlen;
  72. unsigned int __unused[4];
  73. };
  74. struct compat_flock {
  75. short l_type;
  76. short l_whence;
  77. compat_off_t l_start;
  78. compat_off_t l_len;
  79. compat_pid_t l_pid;
  80. };
  81. #define F_GETLK64 12 /* using 'struct flock64' */
  82. #define F_SETLK64 13
  83. #define F_SETLKW64 14
  84. struct compat_flock64 {
  85. short l_type;
  86. short l_whence;
  87. compat_loff_t l_start;
  88. compat_loff_t l_len;
  89. compat_pid_t l_pid;
  90. };
  91. #define COMPAT_RLIM_INFINITY 0xffffffff
  92. #define _COMPAT_NSIG 64
  93. #define _COMPAT_NSIG_BPW 32
  94. typedef u32 compat_sigset_word;
  95. typedef union compat_sigval {
  96. compat_int_t sival_int;
  97. compat_uptr_t sival_ptr;
  98. } compat_sigval_t;
  99. #define COMPAT_SI_PAD_SIZE (128/sizeof(int) - 3)
  100. typedef struct compat_siginfo {
  101. int si_signo;
  102. int si_errno;
  103. int si_code;
  104. union {
  105. int _pad[COMPAT_SI_PAD_SIZE];
  106. /* kill() */
  107. struct {
  108. unsigned int _pid; /* sender's pid */
  109. unsigned int _uid; /* sender's uid */
  110. } _kill;
  111. /* POSIX.1b timers */
  112. struct {
  113. compat_timer_t _tid; /* timer id */
  114. int _overrun; /* overrun count */
  115. compat_sigval_t _sigval; /* same as below */
  116. int _sys_private; /* not to be passed to user */
  117. int _overrun_incr; /* amount to add to overrun */
  118. } _timer;
  119. /* POSIX.1b signals */
  120. struct {
  121. unsigned int _pid; /* sender's pid */
  122. unsigned int _uid; /* sender's uid */
  123. compat_sigval_t _sigval;
  124. } _rt;
  125. /* SIGCHLD */
  126. struct {
  127. unsigned int _pid; /* which child */
  128. unsigned int _uid; /* sender's uid */
  129. int _status; /* exit code */
  130. compat_clock_t _utime;
  131. compat_clock_t _stime;
  132. } _sigchld;
  133. /* SIGILL, SIGFPE, SIGSEGV, SIGBUS */
  134. struct {
  135. unsigned int _addr; /* faulting insn/memory ref. */
  136. #ifdef __ARCH_SI_TRAPNO
  137. int _trapno; /* TRAP # which caused the signal */
  138. #endif
  139. } _sigfault;
  140. /* SIGPOLL */
  141. struct {
  142. int _band; /* POLL_IN, POLL_OUT, POLL_MSG */
  143. int _fd;
  144. } _sigpoll;
  145. } _sifields;
  146. } compat_siginfo_t;
  147. #define COMPAT_OFF_T_MAX 0x7fffffff
  148. #define COMPAT_LOFF_T_MAX 0x7fffffffffffffffL
  149. struct compat_ipc64_perm {
  150. compat_key_t key;
  151. __compat_uid32_t uid;
  152. __compat_gid32_t gid;
  153. __compat_uid32_t cuid;
  154. __compat_gid32_t cgid;
  155. unsigned short mode;
  156. unsigned short __pad1;
  157. unsigned short seq;
  158. unsigned short __pad2;
  159. compat_ulong_t unused1;
  160. compat_ulong_t unused2;
  161. };
  162. struct compat_semid64_ds {
  163. struct compat_ipc64_perm sem_perm;
  164. compat_time_t sem_otime;
  165. compat_ulong_t __unused1;
  166. compat_time_t sem_ctime;
  167. compat_ulong_t __unused2;
  168. compat_ulong_t sem_nsems;
  169. compat_ulong_t __unused3;
  170. compat_ulong_t __unused4;
  171. };
  172. struct compat_msqid64_ds {
  173. struct compat_ipc64_perm msg_perm;
  174. compat_time_t msg_stime;
  175. compat_ulong_t __unused1;
  176. compat_time_t msg_rtime;
  177. compat_ulong_t __unused2;
  178. compat_time_t msg_ctime;
  179. compat_ulong_t __unused3;
  180. compat_ulong_t msg_cbytes;
  181. compat_ulong_t msg_qnum;
  182. compat_ulong_t msg_qbytes;
  183. compat_pid_t msg_lspid;
  184. compat_pid_t msg_lrpid;
  185. compat_ulong_t __unused4;
  186. compat_ulong_t __unused5;
  187. };
  188. struct compat_shmid64_ds {
  189. struct compat_ipc64_perm shm_perm;
  190. compat_size_t shm_segsz;
  191. compat_time_t shm_atime;
  192. compat_ulong_t __unused1;
  193. compat_time_t shm_dtime;
  194. compat_ulong_t __unused2;
  195. compat_time_t shm_ctime;
  196. compat_ulong_t __unused3;
  197. compat_pid_t shm_cpid;
  198. compat_pid_t shm_lpid;
  199. compat_ulong_t shm_nattch;
  200. compat_ulong_t __unused4;
  201. compat_ulong_t __unused5;
  202. };
  203. /*
  204. * A pointer passed in from user mode. This should not
  205. * be used for syscall parameters, just declare them
  206. * as pointers because the syscall entry code will have
  207. * appropriately converted them already.
  208. */
  209. static inline void __user *compat_ptr(compat_uptr_t uptr)
  210. {
  211. return (void __user *)(long)(s32)uptr;
  212. }
  213. static inline compat_uptr_t ptr_to_compat(void __user *uptr)
  214. {
  215. return (u32)(unsigned long)uptr;
  216. }
  217. /* Sign-extend when storing a kernel pointer to a user's ptregs. */
  218. static inline unsigned long ptr_to_compat_reg(void __user *uptr)
  219. {
  220. return (long)(int)(long __force)uptr;
  221. }
  222. static inline void __user *arch_compat_alloc_user_space(long len)
  223. {
  224. struct pt_regs *regs = task_pt_regs(current);
  225. return (void __user *)regs->sp - len;
  226. }
  227. static inline int is_compat_task(void)
  228. {
  229. return current_thread_info()->status & TS_COMPAT;
  230. }
  231. extern int compat_setup_rt_frame(struct ksignal *ksig, sigset_t *set,
  232. struct pt_regs *regs);
  233. /* Compat syscalls. */
  234. struct compat_siginfo;
  235. struct compat_sigaltstack;
  236. long compat_sys_rt_sigreturn(void);
  237. long compat_sys_truncate64(char __user *filename, u32 dummy, u32 low, u32 high);
  238. long compat_sys_ftruncate64(unsigned int fd, u32 dummy, u32 low, u32 high);
  239. long compat_sys_pread64(unsigned int fd, char __user *ubuf, size_t count,
  240. u32 dummy, u32 low, u32 high);
  241. long compat_sys_pwrite64(unsigned int fd, char __user *ubuf, size_t count,
  242. u32 dummy, u32 low, u32 high);
  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_llseek(unsigned int fd, unsigned int offset_high,
  250. unsigned int offset_low, loff_t __user * result,
  251. unsigned int origin);
  252. /* Assembly trampoline to avoid clobbering r0. */
  253. long _compat_sys_rt_sigreturn(void);
  254. #endif /* _ASM_TILE_COMPAT_H */