compat.h 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230
  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. #include <asm-generic/compat.h>
  27. #define COMPAT_USER_HZ 100
  28. #ifdef __AARCH64EB__
  29. #define COMPAT_UTS_MACHINE "armv8b\0\0"
  30. #else
  31. #define COMPAT_UTS_MACHINE "armv8l\0\0"
  32. #endif
  33. typedef u16 __compat_uid_t;
  34. typedef u16 __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_dev_t;
  41. typedef s32 compat_nlink_t;
  42. typedef u16 compat_ipc_pid_t;
  43. typedef u32 compat_caddr_t;
  44. typedef __kernel_fsid_t compat_fsid_t;
  45. typedef s64 compat_s64;
  46. typedef u64 compat_u64;
  47. struct compat_stat {
  48. #ifdef __AARCH64EB__
  49. short st_dev;
  50. short __pad1;
  51. #else
  52. compat_dev_t st_dev;
  53. #endif
  54. compat_ino_t st_ino;
  55. compat_mode_t st_mode;
  56. compat_ushort_t st_nlink;
  57. __compat_uid16_t st_uid;
  58. __compat_gid16_t st_gid;
  59. #ifdef __AARCH64EB__
  60. short st_rdev;
  61. short __pad2;
  62. #else
  63. compat_dev_t st_rdev;
  64. #endif
  65. compat_off_t st_size;
  66. compat_off_t st_blksize;
  67. compat_off_t st_blocks;
  68. old_time32_t st_atime;
  69. compat_ulong_t st_atime_nsec;
  70. old_time32_t st_mtime;
  71. compat_ulong_t st_mtime_nsec;
  72. old_time32_t st_ctime;
  73. compat_ulong_t st_ctime_nsec;
  74. compat_ulong_t __unused4[2];
  75. };
  76. struct compat_flock {
  77. short l_type;
  78. short l_whence;
  79. compat_off_t l_start;
  80. compat_off_t l_len;
  81. compat_pid_t l_pid;
  82. };
  83. #define F_GETLK64 12 /* using 'struct flock64' */
  84. #define F_SETLK64 13
  85. #define F_SETLKW64 14
  86. struct compat_flock64 {
  87. short l_type;
  88. short l_whence;
  89. compat_loff_t l_start;
  90. compat_loff_t l_len;
  91. compat_pid_t l_pid;
  92. };
  93. struct compat_statfs {
  94. int f_type;
  95. int f_bsize;
  96. int f_blocks;
  97. int f_bfree;
  98. int f_bavail;
  99. int f_files;
  100. int f_ffree;
  101. compat_fsid_t f_fsid;
  102. int f_namelen; /* SunOS ignores this field. */
  103. int f_frsize;
  104. int f_flags;
  105. int f_spare[4];
  106. };
  107. #define COMPAT_RLIM_INFINITY 0xffffffff
  108. typedef u32 compat_old_sigset_t;
  109. #define _COMPAT_NSIG 64
  110. #define _COMPAT_NSIG_BPW 32
  111. typedef u32 compat_sigset_word;
  112. #define COMPAT_OFF_T_MAX 0x7fffffff
  113. /*
  114. * A pointer passed in from user mode. This should not
  115. * be used for syscall parameters, just declare them
  116. * as pointers because the syscall entry code will have
  117. * appropriately converted them already.
  118. */
  119. static inline void __user *compat_ptr(compat_uptr_t uptr)
  120. {
  121. return (void __user *)(unsigned long)uptr;
  122. }
  123. static inline compat_uptr_t ptr_to_compat(void __user *uptr)
  124. {
  125. return (u32)(unsigned long)uptr;
  126. }
  127. #define compat_user_stack_pointer() (user_stack_pointer(task_pt_regs(current)))
  128. #define COMPAT_MINSIGSTKSZ 2048
  129. static inline void __user *arch_compat_alloc_user_space(long len)
  130. {
  131. return (void __user *)compat_user_stack_pointer() - len;
  132. }
  133. struct compat_ipc64_perm {
  134. compat_key_t key;
  135. __compat_uid32_t uid;
  136. __compat_gid32_t gid;
  137. __compat_uid32_t cuid;
  138. __compat_gid32_t cgid;
  139. unsigned short mode;
  140. unsigned short __pad1;
  141. unsigned short seq;
  142. unsigned short __pad2;
  143. compat_ulong_t unused1;
  144. compat_ulong_t unused2;
  145. };
  146. struct compat_semid64_ds {
  147. struct compat_ipc64_perm sem_perm;
  148. compat_ulong_t sem_otime;
  149. compat_ulong_t sem_otime_high;
  150. compat_ulong_t sem_ctime;
  151. compat_ulong_t sem_ctime_high;
  152. compat_ulong_t sem_nsems;
  153. compat_ulong_t __unused3;
  154. compat_ulong_t __unused4;
  155. };
  156. struct compat_msqid64_ds {
  157. struct compat_ipc64_perm msg_perm;
  158. compat_ulong_t msg_stime;
  159. compat_ulong_t msg_stime_high;
  160. compat_ulong_t msg_rtime;
  161. compat_ulong_t msg_rtime_high;
  162. compat_ulong_t msg_ctime;
  163. compat_ulong_t msg_ctime_high;
  164. compat_ulong_t msg_cbytes;
  165. compat_ulong_t msg_qnum;
  166. compat_ulong_t msg_qbytes;
  167. compat_pid_t msg_lspid;
  168. compat_pid_t msg_lrpid;
  169. compat_ulong_t __unused4;
  170. compat_ulong_t __unused5;
  171. };
  172. struct compat_shmid64_ds {
  173. struct compat_ipc64_perm shm_perm;
  174. compat_size_t shm_segsz;
  175. compat_ulong_t shm_atime;
  176. compat_ulong_t shm_atime_high;
  177. compat_ulong_t shm_dtime;
  178. compat_ulong_t shm_dtime_high;
  179. compat_ulong_t shm_ctime;
  180. compat_ulong_t shm_ctime_high;
  181. compat_pid_t shm_cpid;
  182. compat_pid_t shm_lpid;
  183. compat_ulong_t shm_nattch;
  184. compat_ulong_t __unused4;
  185. compat_ulong_t __unused5;
  186. };
  187. static inline int is_compat_task(void)
  188. {
  189. return test_thread_flag(TIF_32BIT);
  190. }
  191. static inline int is_compat_thread(struct thread_info *thread)
  192. {
  193. return test_ti_thread_flag(thread, TIF_32BIT);
  194. }
  195. #else /* !CONFIG_COMPAT */
  196. static inline int is_compat_thread(struct thread_info *thread)
  197. {
  198. return 0;
  199. }
  200. #endif /* CONFIG_COMPAT */
  201. #endif /* __KERNEL__ */
  202. #endif /* __ASM_COMPAT_H */