compat.h 7.1 KB

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