compat.h 6.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311
  1. #ifndef _ASM_COMPAT_H
  2. #define _ASM_COMPAT_H
  3. /*
  4. * Architecture specific compatibility types
  5. */
  6. #include <linux/thread_info.h>
  7. #include <linux/types.h>
  8. #include <asm/page.h>
  9. #include <asm/ptrace.h>
  10. #define COMPAT_USER_HZ 100
  11. #define COMPAT_UTS_MACHINE "mips\0\0\0"
  12. typedef u32 compat_size_t;
  13. typedef s32 compat_ssize_t;
  14. typedef s32 compat_time_t;
  15. typedef s32 compat_clock_t;
  16. typedef s32 compat_suseconds_t;
  17. typedef s32 compat_pid_t;
  18. typedef s32 __compat_uid_t;
  19. typedef s32 __compat_gid_t;
  20. typedef __compat_uid_t __compat_uid32_t;
  21. typedef __compat_gid_t __compat_gid32_t;
  22. typedef u32 compat_mode_t;
  23. typedef u32 compat_ino_t;
  24. typedef u32 compat_dev_t;
  25. typedef s32 compat_off_t;
  26. typedef s64 compat_loff_t;
  27. typedef u32 compat_nlink_t;
  28. typedef s32 compat_ipc_pid_t;
  29. typedef s32 compat_daddr_t;
  30. typedef s32 compat_caddr_t;
  31. typedef struct {
  32. s32 val[2];
  33. } compat_fsid_t;
  34. typedef s32 compat_timer_t;
  35. typedef s32 compat_key_t;
  36. typedef s32 compat_int_t;
  37. typedef s32 compat_long_t;
  38. typedef s64 compat_s64;
  39. typedef u32 compat_uint_t;
  40. typedef u32 compat_ulong_t;
  41. typedef u64 compat_u64;
  42. typedef u32 compat_uptr_t;
  43. struct compat_timespec {
  44. compat_time_t tv_sec;
  45. s32 tv_nsec;
  46. };
  47. struct compat_timeval {
  48. compat_time_t tv_sec;
  49. s32 tv_usec;
  50. };
  51. struct compat_stat {
  52. compat_dev_t st_dev;
  53. s32 st_pad1[3];
  54. compat_ino_t st_ino;
  55. compat_mode_t st_mode;
  56. compat_nlink_t st_nlink;
  57. __compat_uid_t st_uid;
  58. __compat_gid_t st_gid;
  59. compat_dev_t st_rdev;
  60. s32 st_pad2[2];
  61. compat_off_t st_size;
  62. s32 st_pad3;
  63. compat_time_t st_atime;
  64. s32 st_atime_nsec;
  65. compat_time_t st_mtime;
  66. s32 st_mtime_nsec;
  67. compat_time_t st_ctime;
  68. s32 st_ctime_nsec;
  69. s32 st_blksize;
  70. s32 st_blocks;
  71. s32 st_pad4[14];
  72. };
  73. struct compat_flock {
  74. short l_type;
  75. short l_whence;
  76. compat_off_t l_start;
  77. compat_off_t l_len;
  78. s32 l_sysid;
  79. compat_pid_t l_pid;
  80. short __unused;
  81. s32 pad[4];
  82. };
  83. #define F_GETLK64 33
  84. #define F_SETLK64 34
  85. #define F_SETLKW64 35
  86. struct compat_flock64 {
  87. short l_type;
  88. short l_whence;
  89. compat_loff_t l_start;
  90. compat_loff_t l_len;
  91. compat_pid_t l_pid;
  92. };
  93. struct compat_statfs {
  94. int f_type;
  95. int f_bsize;
  96. int f_frsize;
  97. int f_blocks;
  98. int f_bfree;
  99. int f_files;
  100. int f_ffree;
  101. int f_bavail;
  102. compat_fsid_t f_fsid;
  103. int f_namelen;
  104. int f_flags;
  105. int f_spare[5];
  106. };
  107. #define COMPAT_RLIM_INFINITY 0x7fffffffUL
  108. typedef u32 compat_old_sigset_t; /* at least 32 bits */
  109. #define _COMPAT_NSIG 128 /* Don't ask !$@#% ... */
  110. #define _COMPAT_NSIG_BPW 32
  111. typedef u32 compat_sigset_word;
  112. typedef union compat_sigval {
  113. compat_int_t sival_int;
  114. compat_uptr_t sival_ptr;
  115. } compat_sigval_t;
  116. /* Can't use the generic version because si_code and si_errno are swapped */
  117. #define SI_PAD_SIZE32 (128/sizeof(int) - 3)
  118. typedef struct compat_siginfo {
  119. int si_signo;
  120. int si_code;
  121. int si_errno;
  122. union {
  123. int _pad[128 / sizeof(int) - 3];
  124. /* kill() */
  125. struct {
  126. compat_pid_t _pid; /* sender's pid */
  127. __compat_uid32_t _uid; /* sender's uid */
  128. } _kill;
  129. /* POSIX.1b timers */
  130. struct {
  131. compat_timer_t _tid; /* timer id */
  132. int _overrun; /* overrun count */
  133. compat_sigval_t _sigval; /* same as below */
  134. } _timer;
  135. /* POSIX.1b signals */
  136. struct {
  137. compat_pid_t _pid; /* sender's pid */
  138. __compat_uid32_t _uid; /* sender's uid */
  139. compat_sigval_t _sigval;
  140. } _rt;
  141. /* SIGCHLD */
  142. struct {
  143. compat_pid_t _pid; /* which child */
  144. __compat_uid32_t _uid; /* sender's uid */
  145. int _status; /* exit code */
  146. compat_clock_t _utime;
  147. compat_clock_t _stime;
  148. } _sigchld;
  149. /* SIGILL, SIGFPE, SIGSEGV, SIGBUS */
  150. struct {
  151. compat_uptr_t _addr; /* faulting insn/memory ref. */
  152. #ifdef __ARCH_SI_TRAPNO
  153. int _trapno; /* TRAP # which caused the signal */
  154. #endif
  155. short _addr_lsb; /* LSB of the reported address */
  156. struct {
  157. compat_uptr_t _lower;
  158. compat_uptr_t _upper;
  159. } _addr_bnd;
  160. } _sigfault;
  161. /* SIGPOLL */
  162. struct {
  163. compat_long_t _band; /* POLL_IN, POLL_OUT, POLL_MSG */
  164. int _fd;
  165. } _sigpoll;
  166. struct {
  167. compat_uptr_t _call_addr; /* calling insn */
  168. int _syscall; /* triggering system call number */
  169. compat_uint_t _arch; /* AUDIT_ARCH_* of syscall */
  170. } _sigsys;
  171. } _sifields;
  172. } compat_siginfo_t;
  173. #define COMPAT_OFF_T_MAX 0x7fffffff
  174. #define COMPAT_LOFF_T_MAX 0x7fffffffffffffffL
  175. /*
  176. * A pointer passed in from user mode. This should not
  177. * be used for syscall parameters, just declare them
  178. * as pointers because the syscall entry code will have
  179. * appropriately converted them already.
  180. */
  181. static inline void __user *compat_ptr(compat_uptr_t uptr)
  182. {
  183. /* cast to a __user pointer via "unsigned long" makes sparse happy */
  184. return (void __user *)(unsigned long)(long)uptr;
  185. }
  186. static inline compat_uptr_t ptr_to_compat(void __user *uptr)
  187. {
  188. return (u32)(unsigned long)uptr;
  189. }
  190. static inline void __user *arch_compat_alloc_user_space(long len)
  191. {
  192. struct pt_regs *regs = (struct pt_regs *)
  193. ((unsigned long) current_thread_info() + THREAD_SIZE - 32) - 1;
  194. return (void __user *) (regs->regs[29] - len);
  195. }
  196. struct compat_ipc64_perm {
  197. compat_key_t key;
  198. __compat_uid32_t uid;
  199. __compat_gid32_t gid;
  200. __compat_uid32_t cuid;
  201. __compat_gid32_t cgid;
  202. compat_mode_t mode;
  203. unsigned short seq;
  204. unsigned short __pad2;
  205. compat_ulong_t __unused1;
  206. compat_ulong_t __unused2;
  207. };
  208. struct compat_semid64_ds {
  209. struct compat_ipc64_perm sem_perm;
  210. compat_time_t sem_otime;
  211. compat_time_t sem_ctime;
  212. compat_ulong_t sem_nsems;
  213. compat_ulong_t __unused1;
  214. compat_ulong_t __unused2;
  215. };
  216. struct compat_msqid64_ds {
  217. struct compat_ipc64_perm msg_perm;
  218. #ifndef CONFIG_CPU_LITTLE_ENDIAN
  219. compat_ulong_t __unused1;
  220. #endif
  221. compat_time_t msg_stime;
  222. #ifdef CONFIG_CPU_LITTLE_ENDIAN
  223. compat_ulong_t __unused1;
  224. #endif
  225. #ifndef CONFIG_CPU_LITTLE_ENDIAN
  226. compat_ulong_t __unused2;
  227. #endif
  228. compat_time_t msg_rtime;
  229. #ifdef CONFIG_CPU_LITTLE_ENDIAN
  230. compat_ulong_t __unused2;
  231. #endif
  232. #ifndef CONFIG_CPU_LITTLE_ENDIAN
  233. compat_ulong_t __unused3;
  234. #endif
  235. compat_time_t msg_ctime;
  236. #ifdef CONFIG_CPU_LITTLE_ENDIAN
  237. compat_ulong_t __unused3;
  238. #endif
  239. compat_ulong_t msg_cbytes;
  240. compat_ulong_t msg_qnum;
  241. compat_ulong_t msg_qbytes;
  242. compat_pid_t msg_lspid;
  243. compat_pid_t msg_lrpid;
  244. compat_ulong_t __unused4;
  245. compat_ulong_t __unused5;
  246. };
  247. struct compat_shmid64_ds {
  248. struct compat_ipc64_perm shm_perm;
  249. compat_size_t shm_segsz;
  250. compat_time_t shm_atime;
  251. compat_time_t shm_dtime;
  252. compat_time_t shm_ctime;
  253. compat_pid_t shm_cpid;
  254. compat_pid_t shm_lpid;
  255. compat_ulong_t shm_nattch;
  256. compat_ulong_t __unused1;
  257. compat_ulong_t __unused2;
  258. };
  259. /* MIPS has unusual order of fields in stack_t */
  260. typedef struct compat_sigaltstack {
  261. compat_uptr_t ss_sp;
  262. compat_size_t ss_size;
  263. int ss_flags;
  264. } compat_stack_t;
  265. #define compat_sigaltstack compat_sigaltstack
  266. static inline int is_compat_task(void)
  267. {
  268. return test_thread_flag(TIF_32BIT_ADDR);
  269. }
  270. #endif /* _ASM_COMPAT_H */