compat.h 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214
  1. /* SPDX-License-Identifier: GPL-2.0 */
  2. #ifndef _ASM_POWERPC_COMPAT_H
  3. #define _ASM_POWERPC_COMPAT_H
  4. #ifdef __KERNEL__
  5. /*
  6. * Architecture specific compatibility types
  7. */
  8. #include <linux/types.h>
  9. #include <linux/sched.h>
  10. #define COMPAT_USER_HZ 100
  11. #ifdef __BIG_ENDIAN__
  12. #define COMPAT_UTS_MACHINE "ppc\0\0"
  13. #else
  14. #define COMPAT_UTS_MACHINE "ppcle\0\0"
  15. #endif
  16. typedef u32 compat_size_t;
  17. typedef s32 compat_ssize_t;
  18. typedef s32 compat_clock_t;
  19. typedef s32 compat_pid_t;
  20. typedef u32 __compat_uid_t;
  21. typedef u32 __compat_gid_t;
  22. typedef u32 __compat_uid32_t;
  23. typedef u32 __compat_gid32_t;
  24. typedef u32 compat_mode_t;
  25. typedef u32 compat_ino_t;
  26. typedef u32 compat_dev_t;
  27. typedef s32 compat_off_t;
  28. typedef s64 compat_loff_t;
  29. typedef s16 compat_nlink_t;
  30. typedef u16 compat_ipc_pid_t;
  31. typedef s32 compat_daddr_t;
  32. typedef u32 compat_caddr_t;
  33. typedef __kernel_fsid_t compat_fsid_t;
  34. typedef s32 compat_key_t;
  35. typedef s32 compat_timer_t;
  36. typedef s32 compat_int_t;
  37. typedef s32 compat_long_t;
  38. typedef s64 compat_s64;
  39. typedef u32 compat_uint_t;
  40. typedef u32 compat_ulong_t;
  41. typedef u64 compat_u64;
  42. typedef u32 compat_uptr_t;
  43. struct compat_stat {
  44. compat_dev_t st_dev;
  45. compat_ino_t st_ino;
  46. compat_mode_t st_mode;
  47. compat_nlink_t st_nlink;
  48. __compat_uid32_t st_uid;
  49. __compat_gid32_t st_gid;
  50. compat_dev_t st_rdev;
  51. compat_off_t st_size;
  52. compat_off_t st_blksize;
  53. compat_off_t st_blocks;
  54. old_time32_t st_atime;
  55. u32 st_atime_nsec;
  56. old_time32_t st_mtime;
  57. u32 st_mtime_nsec;
  58. old_time32_t st_ctime;
  59. u32 st_ctime_nsec;
  60. u32 __unused4[2];
  61. };
  62. struct compat_flock {
  63. short l_type;
  64. short l_whence;
  65. compat_off_t l_start;
  66. compat_off_t l_len;
  67. compat_pid_t l_pid;
  68. };
  69. #define F_GETLK64 12 /* using 'struct flock64' */
  70. #define F_SETLK64 13
  71. #define F_SETLKW64 14
  72. struct compat_flock64 {
  73. short l_type;
  74. short l_whence;
  75. compat_loff_t l_start;
  76. compat_loff_t l_len;
  77. compat_pid_t l_pid;
  78. };
  79. struct compat_statfs {
  80. int f_type;
  81. int f_bsize;
  82. int f_blocks;
  83. int f_bfree;
  84. int f_bavail;
  85. int f_files;
  86. int f_ffree;
  87. compat_fsid_t f_fsid;
  88. int f_namelen; /* SunOS ignores this field. */
  89. int f_frsize;
  90. int f_flags;
  91. int f_spare[4];
  92. };
  93. #define COMPAT_RLIM_INFINITY 0xffffffff
  94. typedef u32 compat_old_sigset_t;
  95. #define _COMPAT_NSIG 64
  96. #define _COMPAT_NSIG_BPW 32
  97. typedef u32 compat_sigset_word;
  98. #define COMPAT_OFF_T_MAX 0x7fffffff
  99. /*
  100. * A pointer passed in from user mode. This should not
  101. * be used for syscall parameters, just declare them
  102. * as pointers because the syscall entry code will have
  103. * appropriately converted them already.
  104. */
  105. static inline void __user *compat_ptr(compat_uptr_t uptr)
  106. {
  107. return (void __user *)(unsigned long)uptr;
  108. }
  109. static inline compat_uptr_t ptr_to_compat(void __user *uptr)
  110. {
  111. return (u32)(unsigned long)uptr;
  112. }
  113. static inline void __user *arch_compat_alloc_user_space(long len)
  114. {
  115. struct pt_regs *regs = current->thread.regs;
  116. unsigned long usp = regs->gpr[1];
  117. /*
  118. * We can't access below the stack pointer in the 32bit ABI and
  119. * can access 288 bytes in the 64bit big-endian ABI,
  120. * or 512 bytes with the new ELFv2 little-endian ABI.
  121. */
  122. if (!is_32bit_task())
  123. usp -= USER_REDZONE_SIZE;
  124. return (void __user *) (usp - len);
  125. }
  126. /*
  127. * ipc64_perm is actually 32/64bit clean but since the compat layer refers to
  128. * it we may as well define it.
  129. */
  130. struct compat_ipc64_perm {
  131. compat_key_t key;
  132. __compat_uid_t uid;
  133. __compat_gid_t gid;
  134. __compat_uid_t cuid;
  135. __compat_gid_t cgid;
  136. compat_mode_t mode;
  137. unsigned int seq;
  138. unsigned int __pad2;
  139. unsigned long __unused1; /* yes they really are 64bit pads */
  140. unsigned long __unused2;
  141. };
  142. struct compat_semid64_ds {
  143. struct compat_ipc64_perm sem_perm;
  144. unsigned int sem_otime_high;
  145. unsigned int sem_otime;
  146. unsigned int sem_ctime_high;
  147. unsigned int sem_ctime;
  148. compat_ulong_t sem_nsems;
  149. compat_ulong_t __unused3;
  150. compat_ulong_t __unused4;
  151. };
  152. struct compat_msqid64_ds {
  153. struct compat_ipc64_perm msg_perm;
  154. unsigned int msg_stime_high;
  155. unsigned int msg_stime;
  156. unsigned int msg_rtime_high;
  157. unsigned int msg_rtime;
  158. unsigned int msg_ctime_high;
  159. unsigned int msg_ctime;
  160. compat_ulong_t msg_cbytes;
  161. compat_ulong_t msg_qnum;
  162. compat_ulong_t msg_qbytes;
  163. compat_pid_t msg_lspid;
  164. compat_pid_t msg_lrpid;
  165. compat_ulong_t __unused4;
  166. compat_ulong_t __unused5;
  167. };
  168. struct compat_shmid64_ds {
  169. struct compat_ipc64_perm shm_perm;
  170. unsigned int shm_atime_high;
  171. unsigned int shm_atime;
  172. unsigned int shm_dtime_high;
  173. unsigned int shm_dtime;
  174. unsigned int shm_ctime_high;
  175. unsigned int shm_ctime;
  176. unsigned int __unused4;
  177. compat_size_t shm_segsz;
  178. compat_pid_t shm_cpid;
  179. compat_pid_t shm_lpid;
  180. compat_ulong_t shm_nattch;
  181. compat_ulong_t __unused5;
  182. compat_ulong_t __unused6;
  183. };
  184. static inline int is_compat_task(void)
  185. {
  186. return is_32bit_task();
  187. }
  188. #endif /* __KERNEL__ */
  189. #endif /* _ASM_POWERPC_COMPAT_H */