compat.h 5.0 KB

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