compat.h 7.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360
  1. #ifndef _ASM_S390X_COMPAT_H
  2. #define _ASM_S390X_COMPAT_H
  3. /*
  4. * Architecture specific compatibility types
  5. */
  6. #include <linux/types.h>
  7. #include <linux/sched.h>
  8. #include <linux/thread_info.h>
  9. #define __TYPE_IS_PTR(t) (!__builtin_types_compatible_p(typeof(0?(t)0:0ULL), u64))
  10. #define __SC_DELOUSE(t,v) ({ \
  11. BUILD_BUG_ON(sizeof(t) > 4 && !__TYPE_IS_PTR(t)); \
  12. (t)(__TYPE_IS_PTR(t) ? ((v) & 0x7fffffff) : (v)); \
  13. })
  14. #define PSW32_MASK_PER 0x40000000UL
  15. #define PSW32_MASK_DAT 0x04000000UL
  16. #define PSW32_MASK_IO 0x02000000UL
  17. #define PSW32_MASK_EXT 0x01000000UL
  18. #define PSW32_MASK_KEY 0x00F00000UL
  19. #define PSW32_MASK_BASE 0x00080000UL /* Always one */
  20. #define PSW32_MASK_MCHECK 0x00040000UL
  21. #define PSW32_MASK_WAIT 0x00020000UL
  22. #define PSW32_MASK_PSTATE 0x00010000UL
  23. #define PSW32_MASK_ASC 0x0000C000UL
  24. #define PSW32_MASK_CC 0x00003000UL
  25. #define PSW32_MASK_PM 0x00000f00UL
  26. #define PSW32_MASK_RI 0x00000080UL
  27. #define PSW32_MASK_USER 0x0000FF00UL
  28. #define PSW32_ADDR_AMODE 0x80000000UL
  29. #define PSW32_ADDR_INSN 0x7FFFFFFFUL
  30. #define PSW32_DEFAULT_KEY (((u32) PAGE_DEFAULT_ACC) << 20)
  31. #define PSW32_ASC_PRIMARY 0x00000000UL
  32. #define PSW32_ASC_ACCREG 0x00004000UL
  33. #define PSW32_ASC_SECONDARY 0x00008000UL
  34. #define PSW32_ASC_HOME 0x0000C000UL
  35. #define PSW32_USER_BITS (PSW32_MASK_DAT | PSW32_MASK_IO | PSW32_MASK_EXT | \
  36. PSW32_DEFAULT_KEY | PSW32_MASK_BASE | \
  37. PSW32_MASK_MCHECK | PSW32_MASK_PSTATE | \
  38. PSW32_ASC_PRIMARY)
  39. #define COMPAT_USER_HZ 100
  40. #define COMPAT_UTS_MACHINE "s390\0\0\0\0"
  41. typedef u32 compat_size_t;
  42. typedef s32 compat_ssize_t;
  43. typedef s32 compat_time_t;
  44. typedef s32 compat_clock_t;
  45. typedef s32 compat_pid_t;
  46. typedef u16 __compat_uid_t;
  47. typedef u16 __compat_gid_t;
  48. typedef u32 __compat_uid32_t;
  49. typedef u32 __compat_gid32_t;
  50. typedef u16 compat_mode_t;
  51. typedef u32 compat_ino_t;
  52. typedef u16 compat_dev_t;
  53. typedef s32 compat_off_t;
  54. typedef s64 compat_loff_t;
  55. typedef u16 compat_nlink_t;
  56. typedef u16 compat_ipc_pid_t;
  57. typedef s32 compat_daddr_t;
  58. typedef u32 compat_caddr_t;
  59. typedef __kernel_fsid_t compat_fsid_t;
  60. typedef s32 compat_key_t;
  61. typedef s32 compat_timer_t;
  62. typedef s32 compat_int_t;
  63. typedef s32 compat_long_t;
  64. typedef s64 compat_s64;
  65. typedef u32 compat_uint_t;
  66. typedef u32 compat_ulong_t;
  67. typedef u64 compat_u64;
  68. typedef u32 compat_uptr_t;
  69. typedef struct {
  70. u32 mask;
  71. u32 addr;
  72. } __aligned(8) psw_compat_t;
  73. typedef struct {
  74. psw_compat_t psw;
  75. u32 gprs[NUM_GPRS];
  76. u32 acrs[NUM_ACRS];
  77. u32 orig_gpr2;
  78. } s390_compat_regs;
  79. typedef struct {
  80. u32 gprs_high[NUM_GPRS];
  81. } s390_compat_regs_high;
  82. struct compat_timespec {
  83. compat_time_t tv_sec;
  84. s32 tv_nsec;
  85. };
  86. struct compat_timeval {
  87. compat_time_t tv_sec;
  88. s32 tv_usec;
  89. };
  90. struct compat_stat {
  91. compat_dev_t st_dev;
  92. u16 __pad1;
  93. compat_ino_t st_ino;
  94. compat_mode_t st_mode;
  95. compat_nlink_t st_nlink;
  96. __compat_uid_t st_uid;
  97. __compat_gid_t st_gid;
  98. compat_dev_t st_rdev;
  99. u16 __pad2;
  100. u32 st_size;
  101. u32 st_blksize;
  102. u32 st_blocks;
  103. u32 st_atime;
  104. u32 st_atime_nsec;
  105. u32 st_mtime;
  106. u32 st_mtime_nsec;
  107. u32 st_ctime;
  108. u32 st_ctime_nsec;
  109. u32 __unused4;
  110. u32 __unused5;
  111. };
  112. struct compat_flock {
  113. short l_type;
  114. short l_whence;
  115. compat_off_t l_start;
  116. compat_off_t l_len;
  117. compat_pid_t l_pid;
  118. };
  119. #define F_GETLK64 12
  120. #define F_SETLK64 13
  121. #define F_SETLKW64 14
  122. struct compat_flock64 {
  123. short l_type;
  124. short l_whence;
  125. compat_loff_t l_start;
  126. compat_loff_t l_len;
  127. compat_pid_t l_pid;
  128. };
  129. struct compat_statfs {
  130. u32 f_type;
  131. u32 f_bsize;
  132. u32 f_blocks;
  133. u32 f_bfree;
  134. u32 f_bavail;
  135. u32 f_files;
  136. u32 f_ffree;
  137. compat_fsid_t f_fsid;
  138. u32 f_namelen;
  139. u32 f_frsize;
  140. u32 f_flags;
  141. u32 f_spare[4];
  142. };
  143. struct compat_statfs64 {
  144. u32 f_type;
  145. u32 f_bsize;
  146. u64 f_blocks;
  147. u64 f_bfree;
  148. u64 f_bavail;
  149. u64 f_files;
  150. u64 f_ffree;
  151. compat_fsid_t f_fsid;
  152. u32 f_namelen;
  153. u32 f_frsize;
  154. u32 f_flags;
  155. u32 f_spare[4];
  156. };
  157. #define COMPAT_RLIM_OLD_INFINITY 0x7fffffff
  158. #define COMPAT_RLIM_INFINITY 0xffffffff
  159. typedef u32 compat_old_sigset_t; /* at least 32 bits */
  160. #define _COMPAT_NSIG 64
  161. #define _COMPAT_NSIG_BPW 32
  162. typedef u32 compat_sigset_word;
  163. typedef union compat_sigval {
  164. compat_int_t sival_int;
  165. compat_uptr_t sival_ptr;
  166. } compat_sigval_t;
  167. typedef struct compat_siginfo {
  168. int si_signo;
  169. int si_errno;
  170. int si_code;
  171. union {
  172. int _pad[128/sizeof(int) - 3];
  173. /* kill() */
  174. struct {
  175. pid_t _pid; /* sender's pid */
  176. uid_t _uid; /* sender's uid */
  177. } _kill;
  178. /* POSIX.1b timers */
  179. struct {
  180. compat_timer_t _tid; /* timer id */
  181. int _overrun; /* overrun count */
  182. compat_sigval_t _sigval; /* same as below */
  183. int _sys_private; /* not to be passed to user */
  184. } _timer;
  185. /* POSIX.1b signals */
  186. struct {
  187. pid_t _pid; /* sender's pid */
  188. uid_t _uid; /* sender's uid */
  189. compat_sigval_t _sigval;
  190. } _rt;
  191. /* SIGCHLD */
  192. struct {
  193. pid_t _pid; /* which child */
  194. uid_t _uid; /* sender's uid */
  195. int _status;/* exit code */
  196. compat_clock_t _utime;
  197. compat_clock_t _stime;
  198. } _sigchld;
  199. /* SIGILL, SIGFPE, SIGSEGV, SIGBUS */
  200. struct {
  201. __u32 _addr; /* faulting insn/memory ref. - pointer */
  202. } _sigfault;
  203. /* SIGPOLL */
  204. struct {
  205. int _band; /* POLL_IN, POLL_OUT, POLL_MSG */
  206. int _fd;
  207. } _sigpoll;
  208. } _sifields;
  209. } compat_siginfo_t;
  210. /*
  211. * How these fields are to be accessed.
  212. */
  213. #define si_pid _sifields._kill._pid
  214. #define si_uid _sifields._kill._uid
  215. #define si_status _sifields._sigchld._status
  216. #define si_utime _sifields._sigchld._utime
  217. #define si_stime _sifields._sigchld._stime
  218. #define si_value _sifields._rt._sigval
  219. #define si_int _sifields._rt._sigval.sival_int
  220. #define si_ptr _sifields._rt._sigval.sival_ptr
  221. #define si_addr _sifields._sigfault._addr
  222. #define si_band _sifields._sigpoll._band
  223. #define si_fd _sifields._sigpoll._fd
  224. #define si_tid _sifields._timer._tid
  225. #define si_overrun _sifields._timer._overrun
  226. #define COMPAT_OFF_T_MAX 0x7fffffff
  227. #define COMPAT_LOFF_T_MAX 0x7fffffffffffffffL
  228. /*
  229. * A pointer passed in from user mode. This should not
  230. * be used for syscall parameters, just declare them
  231. * as pointers because the syscall entry code will have
  232. * appropriately converted them already.
  233. */
  234. static inline void __user *compat_ptr(compat_uptr_t uptr)
  235. {
  236. return (void __user *)(unsigned long)(uptr & 0x7fffffffUL);
  237. }
  238. static inline compat_uptr_t ptr_to_compat(void __user *uptr)
  239. {
  240. return (u32)(unsigned long)uptr;
  241. }
  242. #ifdef CONFIG_COMPAT
  243. static inline int is_compat_task(void)
  244. {
  245. return test_thread_flag(TIF_31BIT);
  246. }
  247. static inline void __user *arch_compat_alloc_user_space(long len)
  248. {
  249. unsigned long stack;
  250. stack = KSTK_ESP(current);
  251. if (is_compat_task())
  252. stack &= 0x7fffffffUL;
  253. return (void __user *) (stack - len);
  254. }
  255. #endif
  256. struct compat_ipc64_perm {
  257. compat_key_t key;
  258. __compat_uid32_t uid;
  259. __compat_gid32_t gid;
  260. __compat_uid32_t cuid;
  261. __compat_gid32_t cgid;
  262. compat_mode_t mode;
  263. unsigned short __pad1;
  264. unsigned short seq;
  265. unsigned short __pad2;
  266. unsigned int __unused1;
  267. unsigned int __unused2;
  268. };
  269. struct compat_semid64_ds {
  270. struct compat_ipc64_perm sem_perm;
  271. compat_time_t sem_otime;
  272. compat_ulong_t __pad1;
  273. compat_time_t sem_ctime;
  274. compat_ulong_t __pad2;
  275. compat_ulong_t sem_nsems;
  276. compat_ulong_t __unused1;
  277. compat_ulong_t __unused2;
  278. };
  279. struct compat_msqid64_ds {
  280. struct compat_ipc64_perm msg_perm;
  281. compat_time_t msg_stime;
  282. compat_ulong_t __pad1;
  283. compat_time_t msg_rtime;
  284. compat_ulong_t __pad2;
  285. compat_time_t msg_ctime;
  286. compat_ulong_t __pad3;
  287. compat_ulong_t msg_cbytes;
  288. compat_ulong_t msg_qnum;
  289. compat_ulong_t msg_qbytes;
  290. compat_pid_t msg_lspid;
  291. compat_pid_t msg_lrpid;
  292. compat_ulong_t __unused1;
  293. compat_ulong_t __unused2;
  294. };
  295. struct compat_shmid64_ds {
  296. struct compat_ipc64_perm shm_perm;
  297. compat_size_t shm_segsz;
  298. compat_time_t shm_atime;
  299. compat_ulong_t __pad1;
  300. compat_time_t shm_dtime;
  301. compat_ulong_t __pad2;
  302. compat_time_t shm_ctime;
  303. compat_ulong_t __pad3;
  304. compat_pid_t shm_cpid;
  305. compat_pid_t shm_lpid;
  306. compat_ulong_t shm_nattch;
  307. compat_ulong_t __unused1;
  308. compat_ulong_t __unused2;
  309. };
  310. #endif /* _ASM_S390X_COMPAT_H */