compat.h 6.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302
  1. /*
  2. * Copyright (C) 2012 ARM Ltd.
  3. *
  4. * This program is free software; you can redistribute it and/or modify
  5. * it under the terms of the GNU General Public License version 2 as
  6. * published by the Free Software Foundation.
  7. *
  8. * This program is distributed in the hope that it will be useful,
  9. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  11. * GNU General Public License for more details.
  12. *
  13. * You should have received a copy of the GNU General Public License
  14. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  15. */
  16. #ifndef __ASM_COMPAT_H
  17. #define __ASM_COMPAT_H
  18. #ifdef __KERNEL__
  19. #ifdef CONFIG_COMPAT
  20. /*
  21. * Architecture specific compatibility types
  22. */
  23. #include <linux/types.h>
  24. #include <linux/sched.h>
  25. #include <linux/ptrace.h>
  26. #define COMPAT_USER_HZ 100
  27. #define COMPAT_UTS_MACHINE "armv8l\0\0"
  28. typedef u32 compat_size_t;
  29. typedef s32 compat_ssize_t;
  30. typedef s32 compat_time_t;
  31. typedef s32 compat_clock_t;
  32. typedef s32 compat_pid_t;
  33. typedef u32 __compat_uid_t;
  34. typedef u32 __compat_gid_t;
  35. typedef u32 __compat_uid32_t;
  36. typedef u32 __compat_gid32_t;
  37. typedef u32 compat_mode_t;
  38. typedef u32 compat_ino_t;
  39. typedef u32 compat_dev_t;
  40. typedef s32 compat_off_t;
  41. typedef s64 compat_loff_t;
  42. typedef s16 compat_nlink_t;
  43. typedef u16 compat_ipc_pid_t;
  44. typedef s32 compat_daddr_t;
  45. typedef u32 compat_caddr_t;
  46. typedef __kernel_fsid_t compat_fsid_t;
  47. typedef s32 compat_key_t;
  48. typedef s32 compat_timer_t;
  49. typedef s32 compat_int_t;
  50. typedef s32 compat_long_t;
  51. typedef s64 compat_s64;
  52. typedef u32 compat_uint_t;
  53. typedef u32 compat_ulong_t;
  54. typedef u64 compat_u64;
  55. typedef u32 compat_uptr_t;
  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. compat_dev_t st_dev;
  66. compat_ino_t st_ino;
  67. compat_mode_t st_mode;
  68. compat_nlink_t st_nlink;
  69. __compat_uid32_t st_uid;
  70. __compat_gid32_t st_gid;
  71. compat_dev_t st_rdev;
  72. compat_off_t st_size;
  73. compat_off_t st_blksize;
  74. compat_off_t st_blocks;
  75. compat_time_t st_atime;
  76. u32 st_atime_nsec;
  77. compat_time_t st_mtime;
  78. u32 st_mtime_nsec;
  79. compat_time_t st_ctime;
  80. u32 st_ctime_nsec;
  81. u32 __unused4[2];
  82. };
  83. struct compat_flock {
  84. short l_type;
  85. short l_whence;
  86. compat_off_t l_start;
  87. compat_off_t l_len;
  88. compat_pid_t l_pid;
  89. };
  90. #define F_GETLK64 12 /* using 'struct flock64' */
  91. #define F_SETLK64 13
  92. #define F_SETLKW64 14
  93. struct compat_flock64 {
  94. short l_type;
  95. short l_whence;
  96. compat_loff_t l_start;
  97. compat_loff_t l_len;
  98. compat_pid_t l_pid;
  99. };
  100. struct compat_statfs {
  101. int f_type;
  102. int f_bsize;
  103. int f_blocks;
  104. int f_bfree;
  105. int f_bavail;
  106. int f_files;
  107. int f_ffree;
  108. compat_fsid_t f_fsid;
  109. int f_namelen; /* SunOS ignores this field. */
  110. int f_frsize;
  111. int f_flags;
  112. int f_spare[4];
  113. };
  114. #define COMPAT_RLIM_INFINITY 0xffffffff
  115. typedef u32 compat_old_sigset_t;
  116. #define _COMPAT_NSIG 64
  117. #define _COMPAT_NSIG_BPW 32
  118. typedef u32 compat_sigset_word;
  119. typedef union compat_sigval {
  120. compat_int_t sival_int;
  121. compat_uptr_t sival_ptr;
  122. } compat_sigval_t;
  123. typedef struct compat_siginfo {
  124. int si_signo;
  125. int si_errno;
  126. int si_code;
  127. union {
  128. /* The padding is the same size as AArch64. */
  129. int _pad[128/sizeof(int) - 3];
  130. /* kill() */
  131. struct {
  132. compat_pid_t _pid; /* sender's pid */
  133. __compat_uid32_t _uid; /* sender's uid */
  134. } _kill;
  135. /* POSIX.1b timers */
  136. struct {
  137. compat_timer_t _tid; /* timer id */
  138. int _overrun; /* overrun count */
  139. compat_sigval_t _sigval; /* same as below */
  140. int _sys_private; /* not to be passed to user */
  141. } _timer;
  142. /* POSIX.1b signals */
  143. struct {
  144. compat_pid_t _pid; /* sender's pid */
  145. __compat_uid32_t _uid; /* sender's uid */
  146. compat_sigval_t _sigval;
  147. } _rt;
  148. /* SIGCHLD */
  149. struct {
  150. compat_pid_t _pid; /* which child */
  151. __compat_uid32_t _uid; /* sender's uid */
  152. int _status; /* exit code */
  153. compat_clock_t _utime;
  154. compat_clock_t _stime;
  155. } _sigchld;
  156. /* SIGILL, SIGFPE, SIGSEGV, SIGBUS */
  157. struct {
  158. compat_uptr_t _addr; /* faulting insn/memory ref. */
  159. short _addr_lsb; /* LSB of the reported address */
  160. } _sigfault;
  161. /* SIGPOLL */
  162. struct {
  163. compat_long_t _band; /* POLL_IN, POLL_OUT, POLL_MSG */
  164. int _fd;
  165. } _sigpoll;
  166. } _sifields;
  167. } compat_siginfo_t;
  168. #define COMPAT_OFF_T_MAX 0x7fffffff
  169. #define COMPAT_LOFF_T_MAX 0x7fffffffffffffffL
  170. /*
  171. * A pointer passed in from user mode. This should not
  172. * be used for syscall parameters, just declare them
  173. * as pointers because the syscall entry code will have
  174. * appropriately converted them already.
  175. */
  176. static inline void __user *compat_ptr(compat_uptr_t uptr)
  177. {
  178. return (void __user *)(unsigned long)uptr;
  179. }
  180. static inline compat_uptr_t ptr_to_compat(void __user *uptr)
  181. {
  182. return (u32)(unsigned long)uptr;
  183. }
  184. #define compat_user_stack_pointer() (current_pt_regs()->compat_sp)
  185. static inline void __user *arch_compat_alloc_user_space(long len)
  186. {
  187. return (void __user *)compat_user_stack_pointer() - len;
  188. }
  189. struct compat_ipc64_perm {
  190. compat_key_t key;
  191. __compat_uid32_t uid;
  192. __compat_gid32_t gid;
  193. __compat_uid32_t cuid;
  194. __compat_gid32_t cgid;
  195. unsigned short mode;
  196. unsigned short __pad1;
  197. unsigned short seq;
  198. unsigned short __pad2;
  199. compat_ulong_t unused1;
  200. compat_ulong_t unused2;
  201. };
  202. struct compat_semid64_ds {
  203. struct compat_ipc64_perm sem_perm;
  204. compat_time_t sem_otime;
  205. compat_ulong_t __unused1;
  206. compat_time_t sem_ctime;
  207. compat_ulong_t __unused2;
  208. compat_ulong_t sem_nsems;
  209. compat_ulong_t __unused3;
  210. compat_ulong_t __unused4;
  211. };
  212. struct compat_msqid64_ds {
  213. struct compat_ipc64_perm msg_perm;
  214. compat_time_t msg_stime;
  215. compat_ulong_t __unused1;
  216. compat_time_t msg_rtime;
  217. compat_ulong_t __unused2;
  218. compat_time_t msg_ctime;
  219. compat_ulong_t __unused3;
  220. compat_ulong_t msg_cbytes;
  221. compat_ulong_t msg_qnum;
  222. compat_ulong_t msg_qbytes;
  223. compat_pid_t msg_lspid;
  224. compat_pid_t msg_lrpid;
  225. compat_ulong_t __unused4;
  226. compat_ulong_t __unused5;
  227. };
  228. struct compat_shmid64_ds {
  229. struct compat_ipc64_perm shm_perm;
  230. compat_size_t shm_segsz;
  231. compat_time_t shm_atime;
  232. compat_ulong_t __unused1;
  233. compat_time_t shm_dtime;
  234. compat_ulong_t __unused2;
  235. compat_time_t shm_ctime;
  236. compat_ulong_t __unused3;
  237. compat_pid_t shm_cpid;
  238. compat_pid_t shm_lpid;
  239. compat_ulong_t shm_nattch;
  240. compat_ulong_t __unused4;
  241. compat_ulong_t __unused5;
  242. };
  243. static inline int is_compat_task(void)
  244. {
  245. return test_thread_flag(TIF_32BIT);
  246. }
  247. static inline int is_compat_thread(struct thread_info *thread)
  248. {
  249. return test_ti_thread_flag(thread, TIF_32BIT);
  250. }
  251. #else /* !CONFIG_COMPAT */
  252. static inline int is_compat_task(void)
  253. {
  254. return 0;
  255. }
  256. static inline int is_compat_thread(struct thread_info *thread)
  257. {
  258. return 0;
  259. }
  260. #endif /* CONFIG_COMPAT */
  261. #endif /* __KERNEL__ */
  262. #endif /* __ASM_COMPAT_H */