compat.h 7.4 KB

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