compat.h 5.5 KB

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