compat.h 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230
  1. /* SPDX-License-Identifier: GPL-2.0 */
  2. #ifndef _ASM_COMPAT_H
  3. #define _ASM_COMPAT_H
  4. /*
  5. * Architecture specific compatibility types
  6. */
  7. #include <linux/thread_info.h>
  8. #include <linux/types.h>
  9. #include <asm/page.h>
  10. #include <asm/ptrace.h>
  11. #define COMPAT_USER_HZ 100
  12. #define COMPAT_UTS_MACHINE "mips\0\0\0"
  13. typedef u32 compat_size_t;
  14. typedef s32 compat_ssize_t;
  15. typedef s32 compat_clock_t;
  16. typedef s32 compat_suseconds_t;
  17. typedef s32 compat_pid_t;
  18. typedef s32 __compat_uid_t;
  19. typedef s32 __compat_gid_t;
  20. typedef __compat_uid_t __compat_uid32_t;
  21. typedef __compat_gid_t __compat_gid32_t;
  22. typedef u32 compat_mode_t;
  23. typedef u32 compat_ino_t;
  24. typedef u32 compat_dev_t;
  25. typedef s32 compat_off_t;
  26. typedef s64 compat_loff_t;
  27. typedef u32 compat_nlink_t;
  28. typedef s32 compat_ipc_pid_t;
  29. typedef s32 compat_daddr_t;
  30. typedef s32 compat_caddr_t;
  31. typedef struct {
  32. s32 val[2];
  33. } compat_fsid_t;
  34. typedef s32 compat_timer_t;
  35. typedef s32 compat_key_t;
  36. typedef s16 compat_short_t;
  37. typedef s32 compat_int_t;
  38. typedef s32 compat_long_t;
  39. typedef s64 compat_s64;
  40. typedef u16 compat_ushort_t;
  41. typedef u32 compat_uint_t;
  42. typedef u32 compat_ulong_t;
  43. typedef u64 compat_u64;
  44. typedef u32 compat_uptr_t;
  45. struct compat_stat {
  46. compat_dev_t st_dev;
  47. s32 st_pad1[3];
  48. compat_ino_t st_ino;
  49. compat_mode_t st_mode;
  50. compat_nlink_t st_nlink;
  51. __compat_uid_t st_uid;
  52. __compat_gid_t st_gid;
  53. compat_dev_t st_rdev;
  54. s32 st_pad2[2];
  55. compat_off_t st_size;
  56. s32 st_pad3;
  57. compat_time_t st_atime;
  58. s32 st_atime_nsec;
  59. compat_time_t st_mtime;
  60. s32 st_mtime_nsec;
  61. compat_time_t st_ctime;
  62. s32 st_ctime_nsec;
  63. s32 st_blksize;
  64. s32 st_blocks;
  65. s32 st_pad4[14];
  66. };
  67. struct compat_flock {
  68. short l_type;
  69. short l_whence;
  70. compat_off_t l_start;
  71. compat_off_t l_len;
  72. s32 l_sysid;
  73. compat_pid_t l_pid;
  74. s32 pad[4];
  75. };
  76. #define F_GETLK64 33
  77. #define F_SETLK64 34
  78. #define F_SETLKW64 35
  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. };
  86. struct compat_statfs {
  87. int f_type;
  88. int f_bsize;
  89. int f_frsize;
  90. int f_blocks;
  91. int f_bfree;
  92. int f_files;
  93. int f_ffree;
  94. int f_bavail;
  95. compat_fsid_t f_fsid;
  96. int f_namelen;
  97. int f_flags;
  98. int f_spare[5];
  99. };
  100. #define COMPAT_RLIM_INFINITY 0x7fffffffUL
  101. typedef u32 compat_old_sigset_t; /* at least 32 bits */
  102. #define _COMPAT_NSIG 128 /* Don't ask !$@#% ... */
  103. #define _COMPAT_NSIG_BPW 32
  104. typedef u32 compat_sigset_word;
  105. #define COMPAT_OFF_T_MAX 0x7fffffff
  106. /*
  107. * A pointer passed in from user mode. This should not
  108. * be used for syscall parameters, just declare them
  109. * as pointers because the syscall entry code will have
  110. * appropriately converted them already.
  111. */
  112. static inline void __user *compat_ptr(compat_uptr_t uptr)
  113. {
  114. /* cast to a __user pointer via "unsigned long" makes sparse happy */
  115. return (void __user *)(unsigned long)(long)uptr;
  116. }
  117. static inline compat_uptr_t ptr_to_compat(void __user *uptr)
  118. {
  119. return (u32)(unsigned long)uptr;
  120. }
  121. static inline void __user *arch_compat_alloc_user_space(long len)
  122. {
  123. struct pt_regs *regs = (struct pt_regs *)
  124. ((unsigned long) current_thread_info() + THREAD_SIZE - 32) - 1;
  125. return (void __user *) (regs->regs[29] - len);
  126. }
  127. struct compat_ipc64_perm {
  128. compat_key_t key;
  129. __compat_uid32_t uid;
  130. __compat_gid32_t gid;
  131. __compat_uid32_t cuid;
  132. __compat_gid32_t cgid;
  133. compat_mode_t mode;
  134. unsigned short seq;
  135. unsigned short __pad2;
  136. compat_ulong_t __unused1;
  137. compat_ulong_t __unused2;
  138. };
  139. struct compat_semid64_ds {
  140. struct compat_ipc64_perm sem_perm;
  141. compat_ulong_t sem_otime;
  142. compat_ulong_t sem_ctime;
  143. compat_ulong_t sem_nsems;
  144. compat_ulong_t sem_otime_high;
  145. compat_ulong_t sem_ctime_high;
  146. };
  147. struct compat_msqid64_ds {
  148. struct compat_ipc64_perm msg_perm;
  149. #ifndef CONFIG_CPU_LITTLE_ENDIAN
  150. compat_ulong_t msg_stime_high;
  151. #endif
  152. compat_ulong_t msg_stime;
  153. #ifdef CONFIG_CPU_LITTLE_ENDIAN
  154. compat_ulong_t msg_stime_high;
  155. #endif
  156. #ifndef CONFIG_CPU_LITTLE_ENDIAN
  157. compat_ulong_t msg_rtime_high;
  158. #endif
  159. compat_ulong_t msg_rtime;
  160. #ifdef CONFIG_CPU_LITTLE_ENDIAN
  161. compat_ulong_t msg_rtime_high;
  162. #endif
  163. #ifndef CONFIG_CPU_LITTLE_ENDIAN
  164. compat_ulong_t msg_ctime_high;
  165. #endif
  166. compat_ulong_t msg_ctime;
  167. #ifdef CONFIG_CPU_LITTLE_ENDIAN
  168. compat_ulong_t msg_ctime_high;
  169. #endif
  170. compat_ulong_t msg_cbytes;
  171. compat_ulong_t msg_qnum;
  172. compat_ulong_t msg_qbytes;
  173. compat_pid_t msg_lspid;
  174. compat_pid_t msg_lrpid;
  175. compat_ulong_t __unused4;
  176. compat_ulong_t __unused5;
  177. };
  178. struct compat_shmid64_ds {
  179. struct compat_ipc64_perm shm_perm;
  180. compat_size_t shm_segsz;
  181. compat_ulong_t shm_atime;
  182. compat_ulong_t shm_dtime;
  183. compat_ulong_t shm_ctime;
  184. compat_pid_t shm_cpid;
  185. compat_pid_t shm_lpid;
  186. compat_ulong_t shm_nattch;
  187. compat_ushort_t shm_atime_high;
  188. compat_ushort_t shm_dtime_high;
  189. compat_ushort_t shm_ctime_high;
  190. compat_ushort_t __unused2;
  191. };
  192. /* MIPS has unusual order of fields in stack_t */
  193. typedef struct compat_sigaltstack {
  194. compat_uptr_t ss_sp;
  195. compat_size_t ss_size;
  196. int ss_flags;
  197. } compat_stack_t;
  198. #define compat_sigaltstack compat_sigaltstack
  199. static inline int is_compat_task(void)
  200. {
  201. return test_thread_flag(TIF_32BIT_ADDR);
  202. }
  203. #endif /* _ASM_COMPAT_H */