compat.h 6.8 KB

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