compat.h 7.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324
  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. typedef u32 compat_uptr_t;
  41. struct compat_timespec {
  42. compat_time_t tv_sec;
  43. s32 tv_nsec;
  44. };
  45. struct compat_timeval {
  46. compat_time_t tv_sec;
  47. s32 tv_usec;
  48. };
  49. struct compat_stat {
  50. compat_dev_t st_dev;
  51. u16 __pad1;
  52. compat_ino_t st_ino;
  53. compat_mode_t st_mode;
  54. compat_nlink_t st_nlink;
  55. __compat_uid_t st_uid;
  56. __compat_gid_t st_gid;
  57. compat_dev_t st_rdev;
  58. u16 __pad2;
  59. u32 st_size;
  60. u32 st_blksize;
  61. u32 st_blocks;
  62. u32 st_atime;
  63. u32 st_atime_nsec;
  64. u32 st_mtime;
  65. u32 st_mtime_nsec;
  66. u32 st_ctime;
  67. u32 st_ctime_nsec;
  68. u32 __unused4;
  69. u32 __unused5;
  70. };
  71. struct compat_flock {
  72. short l_type;
  73. short l_whence;
  74. compat_off_t l_start;
  75. compat_off_t l_len;
  76. compat_pid_t l_pid;
  77. };
  78. #define F_GETLK64 12 /* using 'struct flock64' */
  79. #define F_SETLK64 13
  80. #define F_SETLKW64 14
  81. /*
  82. * IA32 uses 4 byte alignment for 64 bit quantities,
  83. * so we need to pack this structure.
  84. */
  85. struct compat_flock64 {
  86. short l_type;
  87. short l_whence;
  88. compat_loff_t l_start;
  89. compat_loff_t l_len;
  90. compat_pid_t l_pid;
  91. } __attribute__((packed));
  92. struct compat_statfs {
  93. int f_type;
  94. int f_bsize;
  95. int f_blocks;
  96. int f_bfree;
  97. int f_bavail;
  98. int f_files;
  99. int f_ffree;
  100. compat_fsid_t f_fsid;
  101. int f_namelen; /* SunOS ignores this field. */
  102. int f_frsize;
  103. int f_flags;
  104. int f_spare[4];
  105. };
  106. #define COMPAT_RLIM_OLD_INFINITY 0x7fffffff
  107. #define COMPAT_RLIM_INFINITY 0xffffffff
  108. typedef u32 compat_old_sigset_t; /* at least 32 bits */
  109. #define _COMPAT_NSIG 64
  110. #define _COMPAT_NSIG_BPW 32
  111. typedef u32 compat_sigset_word;
  112. typedef union compat_sigval {
  113. compat_int_t sival_int;
  114. compat_uptr_t sival_ptr;
  115. } compat_sigval_t;
  116. typedef struct compat_siginfo {
  117. int si_signo;
  118. int si_errno;
  119. int si_code;
  120. union {
  121. int _pad[128/sizeof(int) - 3];
  122. /* kill() */
  123. struct {
  124. unsigned int _pid; /* sender's pid */
  125. unsigned int _uid; /* sender's uid */
  126. } _kill;
  127. /* POSIX.1b timers */
  128. struct {
  129. compat_timer_t _tid; /* timer id */
  130. int _overrun; /* overrun count */
  131. compat_sigval_t _sigval; /* same as below */
  132. int _sys_private; /* not to be passed to user */
  133. int _overrun_incr; /* amount to add to overrun */
  134. } _timer;
  135. /* POSIX.1b signals */
  136. struct {
  137. unsigned int _pid; /* sender's pid */
  138. unsigned int _uid; /* sender's uid */
  139. compat_sigval_t _sigval;
  140. } _rt;
  141. /* SIGCHLD */
  142. struct {
  143. unsigned int _pid; /* which child */
  144. unsigned int _uid; /* sender's uid */
  145. int _status; /* exit code */
  146. compat_clock_t _utime;
  147. compat_clock_t _stime;
  148. } _sigchld;
  149. /* SIGCHLD (x32 version) */
  150. struct {
  151. unsigned int _pid; /* which child */
  152. unsigned int _uid; /* sender's uid */
  153. int _status; /* exit code */
  154. compat_s64 _utime;
  155. compat_s64 _stime;
  156. } _sigchld_x32;
  157. /* SIGILL, SIGFPE, SIGSEGV, SIGBUS */
  158. struct {
  159. unsigned int _addr; /* faulting insn/memory ref. */
  160. } _sigfault;
  161. /* SIGPOLL */
  162. struct {
  163. int _band; /* POLL_IN, POLL_OUT, POLL_MSG */
  164. int _fd;
  165. } _sigpoll;
  166. struct {
  167. unsigned int _call_addr; /* calling insn */
  168. int _syscall; /* triggering system call number */
  169. unsigned int _arch; /* AUDIT_ARCH_* of syscall */
  170. } _sigsys;
  171. } _sifields;
  172. } compat_siginfo_t;
  173. #define COMPAT_OFF_T_MAX 0x7fffffff
  174. #define COMPAT_LOFF_T_MAX 0x7fffffffffffffffL
  175. struct compat_ipc64_perm {
  176. compat_key_t key;
  177. __compat_uid32_t uid;
  178. __compat_gid32_t gid;
  179. __compat_uid32_t cuid;
  180. __compat_gid32_t cgid;
  181. unsigned short mode;
  182. unsigned short __pad1;
  183. unsigned short seq;
  184. unsigned short __pad2;
  185. compat_ulong_t unused1;
  186. compat_ulong_t unused2;
  187. };
  188. struct compat_semid64_ds {
  189. struct compat_ipc64_perm sem_perm;
  190. compat_time_t sem_otime;
  191. compat_ulong_t __unused1;
  192. compat_time_t sem_ctime;
  193. compat_ulong_t __unused2;
  194. compat_ulong_t sem_nsems;
  195. compat_ulong_t __unused3;
  196. compat_ulong_t __unused4;
  197. };
  198. struct compat_msqid64_ds {
  199. struct compat_ipc64_perm msg_perm;
  200. compat_time_t msg_stime;
  201. compat_ulong_t __unused1;
  202. compat_time_t msg_rtime;
  203. compat_ulong_t __unused2;
  204. compat_time_t msg_ctime;
  205. compat_ulong_t __unused3;
  206. compat_ulong_t msg_cbytes;
  207. compat_ulong_t msg_qnum;
  208. compat_ulong_t msg_qbytes;
  209. compat_pid_t msg_lspid;
  210. compat_pid_t msg_lrpid;
  211. compat_ulong_t __unused4;
  212. compat_ulong_t __unused5;
  213. };
  214. struct compat_shmid64_ds {
  215. struct compat_ipc64_perm shm_perm;
  216. compat_size_t shm_segsz;
  217. compat_time_t shm_atime;
  218. compat_ulong_t __unused1;
  219. compat_time_t shm_dtime;
  220. compat_ulong_t __unused2;
  221. compat_time_t shm_ctime;
  222. compat_ulong_t __unused3;
  223. compat_pid_t shm_cpid;
  224. compat_pid_t shm_lpid;
  225. compat_ulong_t shm_nattch;
  226. compat_ulong_t __unused4;
  227. compat_ulong_t __unused5;
  228. };
  229. /*
  230. * The type of struct elf_prstatus.pr_reg in compatible core dumps.
  231. */
  232. #ifdef CONFIG_X86_X32_ABI
  233. typedef struct user_regs_struct compat_elf_gregset_t;
  234. #define PR_REG_SIZE(S) (test_thread_flag(TIF_IA32) ? 68 : 216)
  235. #define PRSTATUS_SIZE(S) (test_thread_flag(TIF_IA32) ? 144 : 296)
  236. #define SET_PR_FPVALID(S,V) \
  237. do { *(int *) (((void *) &((S)->pr_reg)) + PR_REG_SIZE(0)) = (V); } \
  238. while (0)
  239. #define COMPAT_USE_64BIT_TIME \
  240. (!!(task_pt_regs(current)->orig_ax & __X32_SYSCALL_BIT))
  241. #else
  242. typedef struct user_regs_struct32 compat_elf_gregset_t;
  243. #endif
  244. /*
  245. * A pointer passed in from user mode. This should not
  246. * be used for syscall parameters, just declare them
  247. * as pointers because the syscall entry code will have
  248. * appropriately converted them already.
  249. */
  250. static inline void __user *compat_ptr(compat_uptr_t uptr)
  251. {
  252. return (void __user *)(unsigned long)uptr;
  253. }
  254. static inline compat_uptr_t ptr_to_compat(void __user *uptr)
  255. {
  256. return (u32)(unsigned long)uptr;
  257. }
  258. static inline void __user *arch_compat_alloc_user_space(long len)
  259. {
  260. compat_uptr_t sp;
  261. if (test_thread_flag(TIF_IA32)) {
  262. sp = task_pt_regs(current)->sp;
  263. } else {
  264. /* -128 for the x32 ABI redzone */
  265. sp = this_cpu_read(old_rsp) - 128;
  266. }
  267. return (void __user *)round_down(sp - len, 16);
  268. }
  269. static inline bool is_x32_task(void)
  270. {
  271. #ifdef CONFIG_X86_X32_ABI
  272. if (task_pt_regs(current)->orig_ax & __X32_SYSCALL_BIT)
  273. return true;
  274. #endif
  275. return false;
  276. }
  277. static inline bool is_compat_task(void)
  278. {
  279. return is_ia32_task() || is_x32_task();
  280. }
  281. #endif /* _ASM_X86_COMPAT_H */