compat.h 6.6 KB

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