xref: /openbmc/linux/arch/s390/include/asm/compat.h (revision 9134211f)
1 /* SPDX-License-Identifier: GPL-2.0 */
2 #ifndef _ASM_S390X_COMPAT_H
3 #define _ASM_S390X_COMPAT_H
4 /*
5  * Architecture specific compatibility types
6  */
7 #include <linux/types.h>
8 #include <linux/sched.h>
9 #include <linux/sched/task_stack.h>
10 #include <linux/thread_info.h>
11 #include <asm/ptrace.h>
12 
13 #define compat_mode_t	compat_mode_t
14 typedef u16		compat_mode_t;
15 
16 #define __compat_uid_t	__compat_uid_t
17 typedef u16		__compat_uid_t;
18 typedef u16		__compat_gid_t;
19 
20 #define compat_dev_t	compat_dev_t
21 typedef u16		compat_dev_t;
22 
23 #define compat_ipc_pid_t compat_ipc_pid_t
24 typedef u16		 compat_ipc_pid_t;
25 
26 #define compat_statfs	compat_statfs
27 
28 #include <asm-generic/compat.h>
29 
30 #define __TYPE_IS_PTR(t) (!__builtin_types_compatible_p( \
31 				typeof(0?(__force t)0:0ULL), u64))
32 
33 #define __SC_DELOUSE(t,v) ({ \
34 	BUILD_BUG_ON(sizeof(t) > 4 && !__TYPE_IS_PTR(t)); \
35 	(__force t)(__TYPE_IS_PTR(t) ? ((v) & 0x7fffffff) : (v)); \
36 })
37 
38 #define PSW32_MASK_USER		0x0000FF00UL
39 
40 #define PSW32_USER_BITS (PSW32_MASK_DAT | PSW32_MASK_IO | PSW32_MASK_EXT | \
41 			 PSW32_DEFAULT_KEY | PSW32_MASK_BASE | \
42 			 PSW32_MASK_MCHECK | PSW32_MASK_PSTATE | \
43 			 PSW32_ASC_PRIMARY)
44 
45 #define COMPAT_UTS_MACHINE	"s390\0\0\0\0"
46 
47 typedef u16		compat_nlink_t;
48 
49 typedef struct {
50 	u32 mask;
51 	u32 addr;
52 } __aligned(8) psw_compat_t;
53 
54 typedef struct {
55 	psw_compat_t psw;
56 	u32 gprs[NUM_GPRS];
57 	u32 acrs[NUM_ACRS];
58 	u32 orig_gpr2;
59 } s390_compat_regs;
60 
61 typedef struct {
62 	u32 gprs_high[NUM_GPRS];
63 } s390_compat_regs_high;
64 
65 struct compat_stat {
66 	compat_dev_t	st_dev;
67 	u16		__pad1;
68 	compat_ino_t	st_ino;
69 	compat_mode_t	st_mode;
70 	compat_nlink_t	st_nlink;
71 	__compat_uid_t	st_uid;
72 	__compat_gid_t	st_gid;
73 	compat_dev_t	st_rdev;
74 	u16		__pad2;
75 	u32		st_size;
76 	u32		st_blksize;
77 	u32		st_blocks;
78 	u32		st_atime;
79 	u32		st_atime_nsec;
80 	u32		st_mtime;
81 	u32		st_mtime_nsec;
82 	u32		st_ctime;
83 	u32		st_ctime_nsec;
84 	u32		__unused4;
85 	u32		__unused5;
86 };
87 
88 struct compat_statfs {
89 	u32		f_type;
90 	u32		f_bsize;
91 	u32		f_blocks;
92 	u32		f_bfree;
93 	u32		f_bavail;
94 	u32		f_files;
95 	u32		f_ffree;
96 	compat_fsid_t	f_fsid;
97 	u32		f_namelen;
98 	u32		f_frsize;
99 	u32		f_flags;
100 	u32		f_spare[4];
101 };
102 
103 struct compat_statfs64 {
104 	u32		f_type;
105 	u32		f_bsize;
106 	u64		f_blocks;
107 	u64		f_bfree;
108 	u64		f_bavail;
109 	u64		f_files;
110 	u64		f_ffree;
111 	compat_fsid_t	f_fsid;
112 	u32		f_namelen;
113 	u32		f_frsize;
114 	u32		f_flags;
115 	u32		f_spare[5];
116 };
117 
118 /*
119  * A pointer passed in from user mode. This should not
120  * be used for syscall parameters, just declare them
121  * as pointers because the syscall entry code will have
122  * appropriately converted them already.
123  */
124 
125 static inline void __user *compat_ptr(compat_uptr_t uptr)
126 {
127 	return (void __user *)(unsigned long)(uptr & 0x7fffffffUL);
128 }
129 #define compat_ptr(uptr) compat_ptr(uptr)
130 
131 #ifdef CONFIG_COMPAT
132 
133 static inline int is_compat_task(void)
134 {
135 	return test_thread_flag(TIF_31BIT);
136 }
137 
138 #endif
139 
140 #endif /* _ASM_S390X_COMPAT_H */
141