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