xref: /linux/arch/mips/include/asm/compat.h (revision bfd5bb6f90af092aa345b15cd78143956a13c2a8)
1 /* SPDX-License-Identifier: GPL-2.0 */
2 #ifndef _ASM_COMPAT_H
3 #define _ASM_COMPAT_H
4 /*
5  * Architecture specific compatibility types
6  */
7 #include <linux/thread_info.h>
8 #include <linux/types.h>
9 #include <asm/page.h>
10 #include <asm/ptrace.h>
11 
12 #define COMPAT_USER_HZ		100
13 #define COMPAT_UTS_MACHINE	"mips\0\0\0"
14 
15 typedef u32		compat_size_t;
16 typedef s32		compat_ssize_t;
17 typedef s32		compat_clock_t;
18 typedef s32		compat_suseconds_t;
19 
20 typedef s32		compat_pid_t;
21 typedef s32		__compat_uid_t;
22 typedef s32		__compat_gid_t;
23 typedef __compat_uid_t	__compat_uid32_t;
24 typedef __compat_gid_t	__compat_gid32_t;
25 typedef u32		compat_mode_t;
26 typedef u32		compat_ino_t;
27 typedef u32		compat_dev_t;
28 typedef s32		compat_off_t;
29 typedef s64		compat_loff_t;
30 typedef u32		compat_nlink_t;
31 typedef s32		compat_ipc_pid_t;
32 typedef s32		compat_daddr_t;
33 typedef s32		compat_caddr_t;
34 typedef struct {
35 	s32	val[2];
36 } compat_fsid_t;
37 typedef s32		compat_timer_t;
38 typedef s32		compat_key_t;
39 
40 typedef s16		compat_short_t;
41 typedef s32		compat_int_t;
42 typedef s32		compat_long_t;
43 typedef s64		compat_s64;
44 typedef u16		compat_ushort_t;
45 typedef u32		compat_uint_t;
46 typedef u32		compat_ulong_t;
47 typedef u64		compat_u64;
48 typedef u32		compat_uptr_t;
49 
50 struct compat_stat {
51 	compat_dev_t	st_dev;
52 	s32		st_pad1[3];
53 	compat_ino_t	st_ino;
54 	compat_mode_t	st_mode;
55 	compat_nlink_t	st_nlink;
56 	__compat_uid_t	st_uid;
57 	__compat_gid_t	st_gid;
58 	compat_dev_t	st_rdev;
59 	s32		st_pad2[2];
60 	compat_off_t	st_size;
61 	s32		st_pad3;
62 	compat_time_t	st_atime;
63 	s32		st_atime_nsec;
64 	compat_time_t	st_mtime;
65 	s32		st_mtime_nsec;
66 	compat_time_t	st_ctime;
67 	s32		st_ctime_nsec;
68 	s32		st_blksize;
69 	s32		st_blocks;
70 	s32		st_pad4[14];
71 };
72 
73 struct compat_flock {
74 	short		l_type;
75 	short		l_whence;
76 	compat_off_t	l_start;
77 	compat_off_t	l_len;
78 	s32		l_sysid;
79 	compat_pid_t	l_pid;
80 	s32		pad[4];
81 };
82 
83 #define F_GETLK64	33
84 #define F_SETLK64	34
85 #define F_SETLKW64	35
86 
87 struct compat_flock64 {
88 	short		l_type;
89 	short		l_whence;
90 	compat_loff_t	l_start;
91 	compat_loff_t	l_len;
92 	compat_pid_t	l_pid;
93 };
94 
95 struct compat_statfs {
96 	int		f_type;
97 	int		f_bsize;
98 	int		f_frsize;
99 	int		f_blocks;
100 	int		f_bfree;
101 	int		f_files;
102 	int		f_ffree;
103 	int		f_bavail;
104 	compat_fsid_t	f_fsid;
105 	int		f_namelen;
106 	int		f_flags;
107 	int		f_spare[5];
108 };
109 
110 #define COMPAT_RLIM_INFINITY	0x7fffffffUL
111 
112 typedef u32		compat_old_sigset_t;	/* at least 32 bits */
113 
114 #define _COMPAT_NSIG		128		/* Don't ask !$@#% ...	*/
115 #define _COMPAT_NSIG_BPW	32
116 
117 typedef u32		compat_sigset_word;
118 
119 #define COMPAT_OFF_T_MAX	0x7fffffff
120 
121 /*
122  * A pointer passed in from user mode. This should not
123  * be used for syscall parameters, just declare them
124  * as pointers because the syscall entry code will have
125  * appropriately converted them already.
126  */
127 
128 static inline void __user *compat_ptr(compat_uptr_t uptr)
129 {
130 	/* cast to a __user pointer via "unsigned long" makes sparse happy */
131 	return (void __user *)(unsigned long)(long)uptr;
132 }
133 
134 static inline compat_uptr_t ptr_to_compat(void __user *uptr)
135 {
136 	return (u32)(unsigned long)uptr;
137 }
138 
139 static inline void __user *arch_compat_alloc_user_space(long len)
140 {
141 	struct pt_regs *regs = (struct pt_regs *)
142 		((unsigned long) current_thread_info() + THREAD_SIZE - 32) - 1;
143 
144 	return (void __user *) (regs->regs[29] - len);
145 }
146 
147 struct compat_ipc64_perm {
148 	compat_key_t key;
149 	__compat_uid32_t uid;
150 	__compat_gid32_t gid;
151 	__compat_uid32_t cuid;
152 	__compat_gid32_t cgid;
153 	compat_mode_t mode;
154 	unsigned short seq;
155 	unsigned short __pad2;
156 	compat_ulong_t __unused1;
157 	compat_ulong_t __unused2;
158 };
159 
160 struct compat_semid64_ds {
161 	struct compat_ipc64_perm sem_perm;
162 	compat_ulong_t	sem_otime;
163 	compat_ulong_t	sem_ctime;
164 	compat_ulong_t	sem_nsems;
165 	compat_ulong_t	sem_otime_high;
166 	compat_ulong_t	sem_ctime_high;
167 };
168 
169 struct compat_msqid64_ds {
170 	struct compat_ipc64_perm msg_perm;
171 #ifndef CONFIG_CPU_LITTLE_ENDIAN
172 	compat_ulong_t	msg_stime_high;
173 #endif
174 	compat_ulong_t	msg_stime;
175 #ifdef CONFIG_CPU_LITTLE_ENDIAN
176 	compat_ulong_t	msg_stime_high;
177 #endif
178 #ifndef CONFIG_CPU_LITTLE_ENDIAN
179 	compat_ulong_t	msg_rtime_high;
180 #endif
181 	compat_ulong_t	msg_rtime;
182 #ifdef CONFIG_CPU_LITTLE_ENDIAN
183 	compat_ulong_t	msg_rtime_high;
184 #endif
185 #ifndef CONFIG_CPU_LITTLE_ENDIAN
186 	compat_ulong_t	msg_ctime_high;
187 #endif
188 	compat_ulong_t	msg_ctime;
189 #ifdef CONFIG_CPU_LITTLE_ENDIAN
190 	compat_ulong_t	msg_ctime_high;
191 #endif
192 	compat_ulong_t	msg_cbytes;
193 	compat_ulong_t	msg_qnum;
194 	compat_ulong_t	msg_qbytes;
195 	compat_pid_t	msg_lspid;
196 	compat_pid_t	msg_lrpid;
197 	compat_ulong_t	__unused4;
198 	compat_ulong_t	__unused5;
199 };
200 
201 struct compat_shmid64_ds {
202 	struct compat_ipc64_perm shm_perm;
203 	compat_size_t	shm_segsz;
204 	compat_ulong_t	shm_atime;
205 	compat_ulong_t	shm_dtime;
206 	compat_ulong_t	shm_ctime;
207 	compat_pid_t	shm_cpid;
208 	compat_pid_t	shm_lpid;
209 	compat_ulong_t	shm_nattch;
210 	compat_ushort_t	shm_atime_high;
211 	compat_ushort_t	shm_dtime_high;
212 	compat_ushort_t	shm_ctime_high;
213 	compat_ushort_t	__unused2;
214 };
215 
216 /* MIPS has unusual order of fields in stack_t */
217 typedef struct compat_sigaltstack {
218 	compat_uptr_t			ss_sp;
219 	compat_size_t			ss_size;
220 	int				ss_flags;
221 } compat_stack_t;
222 #define compat_sigaltstack compat_sigaltstack
223 
224 static inline int is_compat_task(void)
225 {
226 	return test_thread_flag(TIF_32BIT_ADDR);
227 }
228 
229 #endif /* _ASM_COMPAT_H */
230