1b2441318SGreg Kroah-Hartman /* SPDX-License-Identifier: GPL-2.0 */ 2c6557e7fSMartin Schwidefsky #ifndef _ASM_S390X_COMPAT_H 3c6557e7fSMartin Schwidefsky #define _ASM_S390X_COMPAT_H 4c6557e7fSMartin Schwidefsky /* 5c6557e7fSMartin Schwidefsky * Architecture specific compatibility types 6c6557e7fSMartin Schwidefsky */ 7c6557e7fSMartin Schwidefsky #include <linux/types.h> 8c6557e7fSMartin Schwidefsky #include <linux/sched.h> 968db0cf1SIngo Molnar #include <linux/sched/task_stack.h> 107757591aSHeiko Carstens #include <linux/thread_info.h> 11*67a9c428SHeiko Carstens #include <asm/ptrace.h> 12c6557e7fSMartin Schwidefsky 131a33b18bSArnd Bergmann #define compat_mode_t compat_mode_t 141a33b18bSArnd Bergmann typedef u16 compat_mode_t; 151a33b18bSArnd Bergmann 16fb373975SArnd Bergmann #include <asm-generic/compat.h> 17fb373975SArnd Bergmann 184f59c718SAl Viro #define __TYPE_IS_PTR(t) (!__builtin_types_compatible_p( \ 194f59c718SAl Viro typeof(0?(__force t)0:0ULL), u64)) 209a205286SHeiko Carstens 219a205286SHeiko Carstens #define __SC_DELOUSE(t,v) ({ \ 229a205286SHeiko Carstens BUILD_BUG_ON(sizeof(t) > 4 && !__TYPE_IS_PTR(t)); \ 234f59c718SAl Viro (__force t)(__TYPE_IS_PTR(t) ? ((v) & 0x7fffffff) : (v)); \ 249a205286SHeiko Carstens }) 2546836613SAl Viro 26fa968ee2SMartin Schwidefsky #define PSW32_MASK_USER 0x0000FF00UL 27b50511e4SMartin Schwidefsky 28f26946d7SHeiko Carstens #define PSW32_USER_BITS (PSW32_MASK_DAT | PSW32_MASK_IO | PSW32_MASK_EXT | \ 29f26946d7SHeiko Carstens PSW32_DEFAULT_KEY | PSW32_MASK_BASE | \ 30075dfd82SHeiko Carstens PSW32_MASK_MCHECK | PSW32_MASK_PSTATE | \ 31075dfd82SHeiko Carstens PSW32_ASC_PRIMARY) 32c6557e7fSMartin Schwidefsky 33c6557e7fSMartin Schwidefsky #define COMPAT_USER_HZ 100 34e28cbf22SChristoph Hellwig #define COMPAT_UTS_MACHINE "s390\0\0\0\0" 35c6557e7fSMartin Schwidefsky 36c6557e7fSMartin Schwidefsky typedef u16 __compat_uid_t; 37c6557e7fSMartin Schwidefsky typedef u16 __compat_gid_t; 38c6557e7fSMartin Schwidefsky typedef u16 compat_dev_t; 39c6557e7fSMartin Schwidefsky typedef u16 compat_nlink_t; 40c6557e7fSMartin Schwidefsky typedef u16 compat_ipc_pid_t; 41c6557e7fSMartin Schwidefsky typedef __kernel_fsid_t compat_fsid_t; 42c6557e7fSMartin Schwidefsky 43e4371f60SHeiko Carstens typedef struct { 44e4371f60SHeiko Carstens u32 mask; 45e4371f60SHeiko Carstens u32 addr; 46e4371f60SHeiko Carstens } __aligned(8) psw_compat_t; 47e4371f60SHeiko Carstens 48e4371f60SHeiko Carstens typedef struct { 49e4371f60SHeiko Carstens psw_compat_t psw; 50e4371f60SHeiko Carstens u32 gprs[NUM_GPRS]; 51e4371f60SHeiko Carstens u32 acrs[NUM_ACRS]; 52e4371f60SHeiko Carstens u32 orig_gpr2; 53e4371f60SHeiko Carstens } s390_compat_regs; 54e4371f60SHeiko Carstens 55e4371f60SHeiko Carstens typedef struct { 56e4371f60SHeiko Carstens u32 gprs_high[NUM_GPRS]; 57e4371f60SHeiko Carstens } s390_compat_regs_high; 58e4371f60SHeiko Carstens 59c6557e7fSMartin Schwidefsky struct compat_stat { 60c6557e7fSMartin Schwidefsky compat_dev_t st_dev; 61c6557e7fSMartin Schwidefsky u16 __pad1; 62c6557e7fSMartin Schwidefsky compat_ino_t st_ino; 63c6557e7fSMartin Schwidefsky compat_mode_t st_mode; 64c6557e7fSMartin Schwidefsky compat_nlink_t st_nlink; 65c6557e7fSMartin Schwidefsky __compat_uid_t st_uid; 66c6557e7fSMartin Schwidefsky __compat_gid_t st_gid; 67c6557e7fSMartin Schwidefsky compat_dev_t st_rdev; 68c6557e7fSMartin Schwidefsky u16 __pad2; 69c6557e7fSMartin Schwidefsky u32 st_size; 70c6557e7fSMartin Schwidefsky u32 st_blksize; 71c6557e7fSMartin Schwidefsky u32 st_blocks; 72c6557e7fSMartin Schwidefsky u32 st_atime; 73c6557e7fSMartin Schwidefsky u32 st_atime_nsec; 74c6557e7fSMartin Schwidefsky u32 st_mtime; 75c6557e7fSMartin Schwidefsky u32 st_mtime_nsec; 76c6557e7fSMartin Schwidefsky u32 st_ctime; 77c6557e7fSMartin Schwidefsky u32 st_ctime_nsec; 78c6557e7fSMartin Schwidefsky u32 __unused4; 79c6557e7fSMartin Schwidefsky u32 __unused5; 80c6557e7fSMartin Schwidefsky }; 81c6557e7fSMartin Schwidefsky 82c6557e7fSMartin Schwidefsky struct compat_flock { 83c6557e7fSMartin Schwidefsky short l_type; 84c6557e7fSMartin Schwidefsky short l_whence; 85c6557e7fSMartin Schwidefsky compat_off_t l_start; 86c6557e7fSMartin Schwidefsky compat_off_t l_len; 87c6557e7fSMartin Schwidefsky compat_pid_t l_pid; 88c6557e7fSMartin Schwidefsky }; 89c6557e7fSMartin Schwidefsky 90c6557e7fSMartin Schwidefsky #define F_GETLK64 12 91c6557e7fSMartin Schwidefsky #define F_SETLK64 13 92c6557e7fSMartin Schwidefsky #define F_SETLKW64 14 93c6557e7fSMartin Schwidefsky 94c6557e7fSMartin Schwidefsky struct compat_flock64 { 95c6557e7fSMartin Schwidefsky short l_type; 96c6557e7fSMartin Schwidefsky short l_whence; 97c6557e7fSMartin Schwidefsky compat_loff_t l_start; 98c6557e7fSMartin Schwidefsky compat_loff_t l_len; 99c6557e7fSMartin Schwidefsky compat_pid_t l_pid; 100c6557e7fSMartin Schwidefsky }; 101c6557e7fSMartin Schwidefsky 102c6557e7fSMartin Schwidefsky struct compat_statfs { 103b8668fd0SHeiko Carstens u32 f_type; 104b8668fd0SHeiko Carstens u32 f_bsize; 105b8668fd0SHeiko Carstens u32 f_blocks; 106b8668fd0SHeiko Carstens u32 f_bfree; 107b8668fd0SHeiko Carstens u32 f_bavail; 108b8668fd0SHeiko Carstens u32 f_files; 109b8668fd0SHeiko Carstens u32 f_ffree; 110c6557e7fSMartin Schwidefsky compat_fsid_t f_fsid; 111b8668fd0SHeiko Carstens u32 f_namelen; 112b8668fd0SHeiko Carstens u32 f_frsize; 113b8668fd0SHeiko Carstens u32 f_flags; 114b8668fd0SHeiko Carstens u32 f_spare[4]; 115b8668fd0SHeiko Carstens }; 116b8668fd0SHeiko Carstens 117b8668fd0SHeiko Carstens struct compat_statfs64 { 118b8668fd0SHeiko Carstens u32 f_type; 119b8668fd0SHeiko Carstens u32 f_bsize; 120b8668fd0SHeiko Carstens u64 f_blocks; 121b8668fd0SHeiko Carstens u64 f_bfree; 122b8668fd0SHeiko Carstens u64 f_bavail; 123b8668fd0SHeiko Carstens u64 f_files; 124b8668fd0SHeiko Carstens u64 f_ffree; 125b8668fd0SHeiko Carstens compat_fsid_t f_fsid; 126b8668fd0SHeiko Carstens u32 f_namelen; 127b8668fd0SHeiko Carstens u32 f_frsize; 128b8668fd0SHeiko Carstens u32 f_flags; 129b8668fd0SHeiko Carstens u32 f_spare[4]; 130c6557e7fSMartin Schwidefsky }; 131c6557e7fSMartin Schwidefsky 132c6557e7fSMartin Schwidefsky #define COMPAT_RLIM_INFINITY 0xffffffff 133c6557e7fSMartin Schwidefsky 134c6557e7fSMartin Schwidefsky #define COMPAT_OFF_T_MAX 0x7fffffff 135c6557e7fSMartin Schwidefsky 136c6557e7fSMartin Schwidefsky /* 137c6557e7fSMartin Schwidefsky * A pointer passed in from user mode. This should not 138c6557e7fSMartin Schwidefsky * be used for syscall parameters, just declare them 139c6557e7fSMartin Schwidefsky * as pointers because the syscall entry code will have 140c6557e7fSMartin Schwidefsky * appropriately converted them already. 141c6557e7fSMartin Schwidefsky */ 142c6557e7fSMartin Schwidefsky 143c6557e7fSMartin Schwidefsky static inline void __user *compat_ptr(compat_uptr_t uptr) 144c6557e7fSMartin Schwidefsky { 145c6557e7fSMartin Schwidefsky return (void __user *)(unsigned long)(uptr & 0x7fffffffUL); 146c6557e7fSMartin Schwidefsky } 147202bf8d7SArnd Bergmann #define compat_ptr(uptr) compat_ptr(uptr) 148c6557e7fSMartin Schwidefsky 1497757591aSHeiko Carstens #ifdef CONFIG_COMPAT 1507757591aSHeiko Carstens 1517757591aSHeiko Carstens static inline int is_compat_task(void) 1527757591aSHeiko Carstens { 1539eb31be3SHeiko Carstens return test_thread_flag(TIF_31BIT); 1547757591aSHeiko Carstens } 1557757591aSHeiko Carstens 1560f58104cSHeiko Carstens #endif 1570f58104cSHeiko Carstens 158c6557e7fSMartin Schwidefsky struct compat_ipc64_perm { 159c6557e7fSMartin Schwidefsky compat_key_t key; 160c6557e7fSMartin Schwidefsky __compat_uid32_t uid; 161c6557e7fSMartin Schwidefsky __compat_gid32_t gid; 162c6557e7fSMartin Schwidefsky __compat_uid32_t cuid; 163c6557e7fSMartin Schwidefsky __compat_gid32_t cgid; 164c6557e7fSMartin Schwidefsky compat_mode_t mode; 165c6557e7fSMartin Schwidefsky unsigned short __pad1; 166c6557e7fSMartin Schwidefsky unsigned short seq; 167c6557e7fSMartin Schwidefsky unsigned short __pad2; 168c6557e7fSMartin Schwidefsky unsigned int __unused1; 169c6557e7fSMartin Schwidefsky unsigned int __unused2; 170c6557e7fSMartin Schwidefsky }; 171c6557e7fSMartin Schwidefsky 172c6557e7fSMartin Schwidefsky struct compat_semid64_ds { 173c6557e7fSMartin Schwidefsky struct compat_ipc64_perm sem_perm; 17426293b31SArnd Bergmann compat_ulong_t sem_otime; 17526293b31SArnd Bergmann compat_ulong_t sem_otime_high; 17626293b31SArnd Bergmann compat_ulong_t sem_ctime; 17726293b31SArnd Bergmann compat_ulong_t sem_ctime_high; 178c6557e7fSMartin Schwidefsky compat_ulong_t sem_nsems; 179c6557e7fSMartin Schwidefsky compat_ulong_t __unused1; 180c6557e7fSMartin Schwidefsky compat_ulong_t __unused2; 181c6557e7fSMartin Schwidefsky }; 182c6557e7fSMartin Schwidefsky 183c6557e7fSMartin Schwidefsky struct compat_msqid64_ds { 184c6557e7fSMartin Schwidefsky struct compat_ipc64_perm msg_perm; 18526293b31SArnd Bergmann compat_ulong_t msg_stime; 18626293b31SArnd Bergmann compat_ulong_t msg_stime_high; 18726293b31SArnd Bergmann compat_ulong_t msg_rtime; 18826293b31SArnd Bergmann compat_ulong_t msg_rtime_high; 18926293b31SArnd Bergmann compat_ulong_t msg_ctime; 19026293b31SArnd Bergmann compat_ulong_t msg_ctime_high; 191c6557e7fSMartin Schwidefsky compat_ulong_t msg_cbytes; 192c6557e7fSMartin Schwidefsky compat_ulong_t msg_qnum; 193c6557e7fSMartin Schwidefsky compat_ulong_t msg_qbytes; 194c6557e7fSMartin Schwidefsky compat_pid_t msg_lspid; 195c6557e7fSMartin Schwidefsky compat_pid_t msg_lrpid; 196c6557e7fSMartin Schwidefsky compat_ulong_t __unused1; 197c6557e7fSMartin Schwidefsky compat_ulong_t __unused2; 198c6557e7fSMartin Schwidefsky }; 199c6557e7fSMartin Schwidefsky 200c6557e7fSMartin Schwidefsky struct compat_shmid64_ds { 201c6557e7fSMartin Schwidefsky struct compat_ipc64_perm shm_perm; 202c6557e7fSMartin Schwidefsky compat_size_t shm_segsz; 20326293b31SArnd Bergmann compat_ulong_t shm_atime; 20426293b31SArnd Bergmann compat_ulong_t shm_atime_high; 20526293b31SArnd Bergmann compat_ulong_t shm_dtime; 20626293b31SArnd Bergmann compat_ulong_t shm_dtime_high; 20726293b31SArnd Bergmann compat_ulong_t shm_ctime; 20826293b31SArnd Bergmann compat_ulong_t shm_ctime_high; 209c6557e7fSMartin Schwidefsky compat_pid_t shm_cpid; 210c6557e7fSMartin Schwidefsky compat_pid_t shm_lpid; 211c6557e7fSMartin Schwidefsky compat_ulong_t shm_nattch; 212c6557e7fSMartin Schwidefsky compat_ulong_t __unused1; 213c6557e7fSMartin Schwidefsky compat_ulong_t __unused2; 214c6557e7fSMartin Schwidefsky }; 215c6557e7fSMartin Schwidefsky #endif /* _ASM_S390X_COMPAT_H */ 216