compat.h 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245
  1. /* SPDX-License-Identifier: GPL-2.0 */
  2. #ifndef _ASM_X86_COMPAT_H
  3. #define _ASM_X86_COMPAT_H
  4. /*
  5. * Architecture specific compatibility types
  6. */
  7. #include <linux/types.h>
  8. #include <linux/sched.h>
  9. #include <linux/sched/task_stack.h>
  10. #include <asm/processor.h>
  11. #include <asm/user32.h>
  12. #include <asm/unistd.h>
  13. #define COMPAT_USER_HZ 100
  14. #define COMPAT_UTS_MACHINE "i686\0\0"
  15. typedef u32 compat_size_t;
  16. typedef s32 compat_ssize_t;
  17. typedef s32 compat_clock_t;
  18. typedef s32 compat_pid_t;
  19. typedef u16 __compat_uid_t;
  20. typedef u16 __compat_gid_t;
  21. typedef u32 __compat_uid32_t;
  22. typedef u32 __compat_gid32_t;
  23. typedef u16 compat_mode_t;
  24. typedef u32 compat_ino_t;
  25. typedef u16 compat_dev_t;
  26. typedef s32 compat_off_t;
  27. typedef s64 compat_loff_t;
  28. typedef u16 compat_nlink_t;
  29. typedef u16 compat_ipc_pid_t;
  30. typedef s32 compat_daddr_t;
  31. typedef u32 compat_caddr_t;
  32. typedef __kernel_fsid_t compat_fsid_t;
  33. typedef s32 compat_timer_t;
  34. typedef s32 compat_key_t;
  35. typedef s32 compat_int_t;
  36. typedef s32 compat_long_t;
  37. typedef s64 __attribute__((aligned(4))) compat_s64;
  38. typedef u32 compat_uint_t;
  39. typedef u32 compat_ulong_t;
  40. typedef u32 compat_u32;
  41. typedef u64 __attribute__((aligned(4))) compat_u64;
  42. typedef u32 compat_uptr_t;
  43. struct compat_stat {
  44. compat_dev_t st_dev;
  45. u16 __pad1;
  46. compat_ino_t st_ino;
  47. compat_mode_t st_mode;
  48. compat_nlink_t st_nlink;
  49. __compat_uid_t st_uid;
  50. __compat_gid_t st_gid;
  51. compat_dev_t st_rdev;
  52. u16 __pad2;
  53. u32 st_size;
  54. u32 st_blksize;
  55. u32 st_blocks;
  56. u32 st_atime;
  57. u32 st_atime_nsec;
  58. u32 st_mtime;
  59. u32 st_mtime_nsec;
  60. u32 st_ctime;
  61. u32 st_ctime_nsec;
  62. u32 __unused4;
  63. u32 __unused5;
  64. };
  65. struct compat_flock {
  66. short l_type;
  67. short l_whence;
  68. compat_off_t l_start;
  69. compat_off_t l_len;
  70. compat_pid_t l_pid;
  71. };
  72. #define F_GETLK64 12 /* using 'struct flock64' */
  73. #define F_SETLK64 13
  74. #define F_SETLKW64 14
  75. /*
  76. * IA32 uses 4 byte alignment for 64 bit quantities,
  77. * so we need to pack this structure.
  78. */
  79. struct compat_flock64 {
  80. short l_type;
  81. short l_whence;
  82. compat_loff_t l_start;
  83. compat_loff_t l_len;
  84. compat_pid_t l_pid;
  85. } __attribute__((packed));
  86. struct compat_statfs {
  87. int f_type;
  88. int f_bsize;
  89. int f_blocks;
  90. int f_bfree;
  91. int f_bavail;
  92. int f_files;
  93. int f_ffree;
  94. compat_fsid_t f_fsid;
  95. int f_namelen; /* SunOS ignores this field. */
  96. int f_frsize;
  97. int f_flags;
  98. int f_spare[4];
  99. };
  100. #define COMPAT_RLIM_INFINITY 0xffffffff
  101. typedef u32 compat_old_sigset_t; /* at least 32 bits */
  102. #define _COMPAT_NSIG 64
  103. #define _COMPAT_NSIG_BPW 32
  104. typedef u32 compat_sigset_word;
  105. #define COMPAT_OFF_T_MAX 0x7fffffff
  106. struct compat_ipc64_perm {
  107. compat_key_t key;
  108. __compat_uid32_t uid;
  109. __compat_gid32_t gid;
  110. __compat_uid32_t cuid;
  111. __compat_gid32_t cgid;
  112. unsigned short mode;
  113. unsigned short __pad1;
  114. unsigned short seq;
  115. unsigned short __pad2;
  116. compat_ulong_t unused1;
  117. compat_ulong_t unused2;
  118. };
  119. struct compat_semid64_ds {
  120. struct compat_ipc64_perm sem_perm;
  121. compat_time_t sem_otime;
  122. compat_ulong_t __unused1;
  123. compat_time_t sem_ctime;
  124. compat_ulong_t __unused2;
  125. compat_ulong_t sem_nsems;
  126. compat_ulong_t __unused3;
  127. compat_ulong_t __unused4;
  128. };
  129. struct compat_msqid64_ds {
  130. struct compat_ipc64_perm msg_perm;
  131. compat_time_t msg_stime;
  132. compat_ulong_t __unused1;
  133. compat_time_t msg_rtime;
  134. compat_ulong_t __unused2;
  135. compat_time_t msg_ctime;
  136. compat_ulong_t __unused3;
  137. compat_ulong_t msg_cbytes;
  138. compat_ulong_t msg_qnum;
  139. compat_ulong_t msg_qbytes;
  140. compat_pid_t msg_lspid;
  141. compat_pid_t msg_lrpid;
  142. compat_ulong_t __unused4;
  143. compat_ulong_t __unused5;
  144. };
  145. struct compat_shmid64_ds {
  146. struct compat_ipc64_perm shm_perm;
  147. compat_size_t shm_segsz;
  148. compat_time_t shm_atime;
  149. compat_ulong_t __unused1;
  150. compat_time_t shm_dtime;
  151. compat_ulong_t __unused2;
  152. compat_time_t shm_ctime;
  153. compat_ulong_t __unused3;
  154. compat_pid_t shm_cpid;
  155. compat_pid_t shm_lpid;
  156. compat_ulong_t shm_nattch;
  157. compat_ulong_t __unused4;
  158. compat_ulong_t __unused5;
  159. };
  160. /*
  161. * The type of struct elf_prstatus.pr_reg in compatible core dumps.
  162. */
  163. typedef struct user_regs_struct compat_elf_gregset_t;
  164. /* Full regset -- prstatus on x32, otherwise on ia32 */
  165. #define PRSTATUS_SIZE(S, R) (R != sizeof(S.pr_reg) ? 144 : 296)
  166. #define SET_PR_FPVALID(S, V, R) \
  167. do { *(int *) (((void *) &((S)->pr_reg)) + R) = (V); } \
  168. while (0)
  169. #ifdef CONFIG_X86_X32_ABI
  170. #define COMPAT_USE_64BIT_TIME \
  171. (!!(task_pt_regs(current)->orig_ax & __X32_SYSCALL_BIT))
  172. #endif
  173. /*
  174. * A pointer passed in from user mode. This should not
  175. * be used for syscall parameters, just declare them
  176. * as pointers because the syscall entry code will have
  177. * appropriately converted them already.
  178. */
  179. static inline void __user *compat_ptr(compat_uptr_t uptr)
  180. {
  181. return (void __user *)(unsigned long)uptr;
  182. }
  183. static inline compat_uptr_t ptr_to_compat(void __user *uptr)
  184. {
  185. return (u32)(unsigned long)uptr;
  186. }
  187. static inline void __user *arch_compat_alloc_user_space(long len)
  188. {
  189. compat_uptr_t sp;
  190. if (test_thread_flag(TIF_IA32)) {
  191. sp = task_pt_regs(current)->sp;
  192. } else {
  193. /* -128 for the x32 ABI redzone */
  194. sp = task_pt_regs(current)->sp - 128;
  195. }
  196. return (void __user *)round_down(sp - len, 16);
  197. }
  198. static inline bool in_x32_syscall(void)
  199. {
  200. #ifdef CONFIG_X86_X32_ABI
  201. if (task_pt_regs(current)->orig_ax & __X32_SYSCALL_BIT)
  202. return true;
  203. #endif
  204. return false;
  205. }
  206. static inline bool in_compat_syscall(void)
  207. {
  208. return in_ia32_syscall() || in_x32_syscall();
  209. }
  210. #define in_compat_syscall in_compat_syscall /* override the generic impl */
  211. struct compat_siginfo;
  212. int __copy_siginfo_to_user32(struct compat_siginfo __user *to,
  213. const siginfo_t *from, bool x32_ABI);
  214. #endif /* _ASM_X86_COMPAT_H */