compat.h 5.3 KB

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