compat.h 7.1 KB

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