compat.h 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245
  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/sched/task_stack.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_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_stat {
  64. #ifdef __AARCH64EB__
  65. short st_dev;
  66. short __pad1;
  67. #else
  68. compat_dev_t st_dev;
  69. #endif
  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. #ifdef __AARCH64EB__
  76. short st_rdev;
  77. short __pad2;
  78. #else
  79. compat_dev_t st_rdev;
  80. #endif
  81. compat_off_t st_size;
  82. compat_off_t st_blksize;
  83. compat_off_t st_blocks;
  84. old_time32_t st_atime;
  85. compat_ulong_t st_atime_nsec;
  86. old_time32_t st_mtime;
  87. compat_ulong_t st_mtime_nsec;
  88. old_time32_t st_ctime;
  89. compat_ulong_t st_ctime_nsec;
  90. compat_ulong_t __unused4[2];
  91. };
  92. struct compat_flock {
  93. short l_type;
  94. short l_whence;
  95. compat_off_t l_start;
  96. compat_off_t l_len;
  97. compat_pid_t l_pid;
  98. };
  99. #define F_GETLK64 12 /* using 'struct flock64' */
  100. #define F_SETLK64 13
  101. #define F_SETLKW64 14
  102. struct compat_flock64 {
  103. short l_type;
  104. short l_whence;
  105. compat_loff_t l_start;
  106. compat_loff_t l_len;
  107. compat_pid_t l_pid;
  108. };
  109. struct compat_statfs {
  110. int f_type;
  111. int f_bsize;
  112. int f_blocks;
  113. int f_bfree;
  114. int f_bavail;
  115. int f_files;
  116. int f_ffree;
  117. compat_fsid_t f_fsid;
  118. int f_namelen; /* SunOS ignores this field. */
  119. int f_frsize;
  120. int f_flags;
  121. int f_spare[4];
  122. };
  123. #define COMPAT_RLIM_INFINITY 0xffffffff
  124. typedef u32 compat_old_sigset_t;
  125. #define _COMPAT_NSIG 64
  126. #define _COMPAT_NSIG_BPW 32
  127. typedef u32 compat_sigset_word;
  128. #define COMPAT_OFF_T_MAX 0x7fffffff
  129. /*
  130. * A pointer passed in from user mode. This should not
  131. * be used for syscall parameters, just declare them
  132. * as pointers because the syscall entry code will have
  133. * appropriately converted them already.
  134. */
  135. static inline void __user *compat_ptr(compat_uptr_t uptr)
  136. {
  137. return (void __user *)(unsigned long)uptr;
  138. }
  139. static inline compat_uptr_t ptr_to_compat(void __user *uptr)
  140. {
  141. return (u32)(unsigned long)uptr;
  142. }
  143. #define compat_user_stack_pointer() (user_stack_pointer(task_pt_regs(current)))
  144. static inline void __user *arch_compat_alloc_user_space(long len)
  145. {
  146. return (void __user *)compat_user_stack_pointer() - len;
  147. }
  148. struct compat_ipc64_perm {
  149. compat_key_t key;
  150. __compat_uid32_t uid;
  151. __compat_gid32_t gid;
  152. __compat_uid32_t cuid;
  153. __compat_gid32_t cgid;
  154. unsigned short mode;
  155. unsigned short __pad1;
  156. unsigned short seq;
  157. unsigned short __pad2;
  158. compat_ulong_t unused1;
  159. compat_ulong_t unused2;
  160. };
  161. struct compat_semid64_ds {
  162. struct compat_ipc64_perm sem_perm;
  163. compat_ulong_t sem_otime;
  164. compat_ulong_t sem_otime_high;
  165. compat_ulong_t sem_ctime;
  166. compat_ulong_t sem_ctime_high;
  167. compat_ulong_t sem_nsems;
  168. compat_ulong_t __unused3;
  169. compat_ulong_t __unused4;
  170. };
  171. struct compat_msqid64_ds {
  172. struct compat_ipc64_perm msg_perm;
  173. compat_ulong_t msg_stime;
  174. compat_ulong_t msg_stime_high;
  175. compat_ulong_t msg_rtime;
  176. compat_ulong_t msg_rtime_high;
  177. compat_ulong_t msg_ctime;
  178. compat_ulong_t msg_ctime_high;
  179. compat_ulong_t msg_cbytes;
  180. compat_ulong_t msg_qnum;
  181. compat_ulong_t msg_qbytes;
  182. compat_pid_t msg_lspid;
  183. compat_pid_t msg_lrpid;
  184. compat_ulong_t __unused4;
  185. compat_ulong_t __unused5;
  186. };
  187. struct compat_shmid64_ds {
  188. struct compat_ipc64_perm shm_perm;
  189. compat_size_t shm_segsz;
  190. compat_ulong_t shm_atime;
  191. compat_ulong_t shm_atime_high;
  192. compat_ulong_t shm_dtime;
  193. compat_ulong_t shm_dtime_high;
  194. compat_ulong_t shm_ctime;
  195. compat_ulong_t shm_ctime_high;
  196. compat_pid_t shm_cpid;
  197. compat_pid_t shm_lpid;
  198. compat_ulong_t shm_nattch;
  199. compat_ulong_t __unused4;
  200. compat_ulong_t __unused5;
  201. };
  202. static inline int is_compat_task(void)
  203. {
  204. return test_thread_flag(TIF_32BIT);
  205. }
  206. static inline int is_compat_thread(struct thread_info *thread)
  207. {
  208. return test_ti_thread_flag(thread, TIF_32BIT);
  209. }
  210. #else /* !CONFIG_COMPAT */
  211. static inline int is_compat_thread(struct thread_info *thread)
  212. {
  213. return 0;
  214. }
  215. #endif /* CONFIG_COMPAT */
  216. #endif /* __KERNEL__ */
  217. #endif /* __ASM_COMPAT_H */