xref: /openbmc/linux/arch/arm64/include/asm/compat.h (revision fb373975)
1 /*
2  * Copyright (C) 2012 ARM Ltd.
3  *
4  * This program is free software; you can redistribute it and/or modify
5  * it under the terms of the GNU General Public License version 2 as
6  * published by the Free Software Foundation.
7  *
8  * This program is distributed in the hope that it will be useful,
9  * but WITHOUT ANY WARRANTY; without even the implied warranty of
10  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
11  * GNU General Public License for more details.
12  *
13  * You should have received a copy of the GNU General Public License
14  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
15  */
16 #ifndef __ASM_COMPAT_H
17 #define __ASM_COMPAT_H
18 #ifdef __KERNEL__
19 #ifdef CONFIG_COMPAT
20 
21 /*
22  * Architecture specific compatibility types
23  */
24 #include <linux/types.h>
25 #include <linux/sched.h>
26 #include <linux/sched/task_stack.h>
27 
28 #include <asm-generic/compat.h>
29 
30 #define COMPAT_USER_HZ		100
31 #ifdef __AARCH64EB__
32 #define COMPAT_UTS_MACHINE	"armv8b\0\0"
33 #else
34 #define COMPAT_UTS_MACHINE	"armv8l\0\0"
35 #endif
36 
37 typedef u16		__compat_uid_t;
38 typedef u16		__compat_gid_t;
39 typedef u16		__compat_uid16_t;
40 typedef u16		__compat_gid16_t;
41 typedef u32		__compat_uid32_t;
42 typedef u32		__compat_gid32_t;
43 typedef u16		compat_mode_t;
44 typedef u32		compat_dev_t;
45 typedef s32		compat_nlink_t;
46 typedef u16		compat_ipc_pid_t;
47 typedef u32		compat_caddr_t;
48 typedef __kernel_fsid_t	compat_fsid_t;
49 typedef s64		compat_s64;
50 typedef u64		compat_u64;
51 
52 struct compat_stat {
53 #ifdef __AARCH64EB__
54 	short		st_dev;
55 	short		__pad1;
56 #else
57 	compat_dev_t	st_dev;
58 #endif
59 	compat_ino_t	st_ino;
60 	compat_mode_t	st_mode;
61 	compat_ushort_t	st_nlink;
62 	__compat_uid16_t	st_uid;
63 	__compat_gid16_t	st_gid;
64 #ifdef __AARCH64EB__
65 	short		st_rdev;
66 	short		__pad2;
67 #else
68 	compat_dev_t	st_rdev;
69 #endif
70 	compat_off_t	st_size;
71 	compat_off_t	st_blksize;
72 	compat_off_t	st_blocks;
73 	old_time32_t	st_atime;
74 	compat_ulong_t	st_atime_nsec;
75 	old_time32_t	st_mtime;
76 	compat_ulong_t	st_mtime_nsec;
77 	old_time32_t	st_ctime;
78 	compat_ulong_t	st_ctime_nsec;
79 	compat_ulong_t	__unused4[2];
80 };
81 
82 struct compat_flock {
83 	short		l_type;
84 	short		l_whence;
85 	compat_off_t	l_start;
86 	compat_off_t	l_len;
87 	compat_pid_t	l_pid;
88 };
89 
90 #define F_GETLK64	12	/*  using 'struct flock64' */
91 #define F_SETLK64	13
92 #define F_SETLKW64	14
93 
94 struct compat_flock64 {
95 	short		l_type;
96 	short		l_whence;
97 	compat_loff_t	l_start;
98 	compat_loff_t	l_len;
99 	compat_pid_t	l_pid;
100 };
101 
102 struct compat_statfs {
103 	int		f_type;
104 	int		f_bsize;
105 	int		f_blocks;
106 	int		f_bfree;
107 	int		f_bavail;
108 	int		f_files;
109 	int		f_ffree;
110 	compat_fsid_t	f_fsid;
111 	int		f_namelen;	/* SunOS ignores this field. */
112 	int		f_frsize;
113 	int		f_flags;
114 	int		f_spare[4];
115 };
116 
117 #define COMPAT_RLIM_INFINITY		0xffffffff
118 
119 typedef u32		compat_old_sigset_t;
120 
121 #define _COMPAT_NSIG		64
122 #define _COMPAT_NSIG_BPW	32
123 
124 typedef u32		compat_sigset_word;
125 
126 #define COMPAT_OFF_T_MAX	0x7fffffff
127 
128 /*
129  * A pointer passed in from user mode. This should not
130  * be used for syscall parameters, just declare them
131  * as pointers because the syscall entry code will have
132  * appropriately converted them already.
133  */
134 
135 static inline void __user *compat_ptr(compat_uptr_t uptr)
136 {
137 	return (void __user *)(unsigned long)uptr;
138 }
139 
140 static inline compat_uptr_t ptr_to_compat(void __user *uptr)
141 {
142 	return (u32)(unsigned long)uptr;
143 }
144 
145 #define compat_user_stack_pointer() (user_stack_pointer(task_pt_regs(current)))
146 
147 static inline void __user *arch_compat_alloc_user_space(long len)
148 {
149 	return (void __user *)compat_user_stack_pointer() - len;
150 }
151 
152 struct compat_ipc64_perm {
153 	compat_key_t key;
154 	__compat_uid32_t uid;
155 	__compat_gid32_t gid;
156 	__compat_uid32_t cuid;
157 	__compat_gid32_t cgid;
158 	unsigned short mode;
159 	unsigned short __pad1;
160 	unsigned short seq;
161 	unsigned short __pad2;
162 	compat_ulong_t unused1;
163 	compat_ulong_t unused2;
164 };
165 
166 struct compat_semid64_ds {
167 	struct compat_ipc64_perm sem_perm;
168 	compat_ulong_t sem_otime;
169 	compat_ulong_t sem_otime_high;
170 	compat_ulong_t sem_ctime;
171 	compat_ulong_t sem_ctime_high;
172 	compat_ulong_t sem_nsems;
173 	compat_ulong_t __unused3;
174 	compat_ulong_t __unused4;
175 };
176 
177 struct compat_msqid64_ds {
178 	struct compat_ipc64_perm msg_perm;
179 	compat_ulong_t msg_stime;
180 	compat_ulong_t msg_stime_high;
181 	compat_ulong_t msg_rtime;
182 	compat_ulong_t msg_rtime_high;
183 	compat_ulong_t msg_ctime;
184 	compat_ulong_t msg_ctime_high;
185 	compat_ulong_t msg_cbytes;
186 	compat_ulong_t msg_qnum;
187 	compat_ulong_t msg_qbytes;
188 	compat_pid_t   msg_lspid;
189 	compat_pid_t   msg_lrpid;
190 	compat_ulong_t __unused4;
191 	compat_ulong_t __unused5;
192 };
193 
194 struct compat_shmid64_ds {
195 	struct compat_ipc64_perm shm_perm;
196 	compat_size_t  shm_segsz;
197 	compat_ulong_t shm_atime;
198 	compat_ulong_t shm_atime_high;
199 	compat_ulong_t shm_dtime;
200 	compat_ulong_t shm_dtime_high;
201 	compat_ulong_t shm_ctime;
202 	compat_ulong_t shm_ctime_high;
203 	compat_pid_t   shm_cpid;
204 	compat_pid_t   shm_lpid;
205 	compat_ulong_t shm_nattch;
206 	compat_ulong_t __unused4;
207 	compat_ulong_t __unused5;
208 };
209 
210 static inline int is_compat_task(void)
211 {
212 	return test_thread_flag(TIF_32BIT);
213 }
214 
215 static inline int is_compat_thread(struct thread_info *thread)
216 {
217 	return test_ti_thread_flag(thread, TIF_32BIT);
218 }
219 
220 #else /* !CONFIG_COMPAT */
221 
222 static inline int is_compat_thread(struct thread_info *thread)
223 {
224 	return 0;
225 }
226 
227 #endif /* CONFIG_COMPAT */
228 #endif /* __KERNEL__ */
229 #endif /* __ASM_COMPAT_H */
230