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 27 #define COMPAT_USER_HZ 100 28 #define COMPAT_UTS_MACHINE "armv8l\0\0" 29 30 typedef u32 compat_size_t; 31 typedef s32 compat_ssize_t; 32 typedef s32 compat_time_t; 33 typedef s32 compat_clock_t; 34 typedef s32 compat_pid_t; 35 typedef u32 __compat_uid_t; 36 typedef u32 __compat_gid_t; 37 typedef u32 __compat_uid32_t; 38 typedef u32 __compat_gid32_t; 39 typedef u32 compat_mode_t; 40 typedef u32 compat_ino_t; 41 typedef u32 compat_dev_t; 42 typedef s32 compat_off_t; 43 typedef s64 compat_loff_t; 44 typedef s16 compat_nlink_t; 45 typedef u16 compat_ipc_pid_t; 46 typedef s32 compat_daddr_t; 47 typedef u32 compat_caddr_t; 48 typedef __kernel_fsid_t compat_fsid_t; 49 typedef s32 compat_key_t; 50 typedef s32 compat_timer_t; 51 52 typedef s32 compat_int_t; 53 typedef s32 compat_long_t; 54 typedef s64 compat_s64; 55 typedef u32 compat_uint_t; 56 typedef u32 compat_ulong_t; 57 typedef u64 compat_u64; 58 typedef u32 compat_uptr_t; 59 60 struct compat_timespec { 61 compat_time_t tv_sec; 62 s32 tv_nsec; 63 }; 64 65 struct compat_timeval { 66 compat_time_t tv_sec; 67 s32 tv_usec; 68 }; 69 70 struct compat_stat { 71 compat_dev_t st_dev; 72 compat_ino_t st_ino; 73 compat_mode_t st_mode; 74 compat_nlink_t st_nlink; 75 __compat_uid32_t st_uid; 76 __compat_gid32_t st_gid; 77 compat_dev_t st_rdev; 78 compat_off_t st_size; 79 compat_off_t st_blksize; 80 compat_off_t st_blocks; 81 compat_time_t st_atime; 82 u32 st_atime_nsec; 83 compat_time_t st_mtime; 84 u32 st_mtime_nsec; 85 compat_time_t st_ctime; 86 u32 st_ctime_nsec; 87 u32 __unused4[2]; 88 }; 89 90 struct compat_flock { 91 short l_type; 92 short l_whence; 93 compat_off_t l_start; 94 compat_off_t l_len; 95 compat_pid_t l_pid; 96 }; 97 98 #define F_GETLK64 12 /* using 'struct flock64' */ 99 #define F_SETLK64 13 100 #define F_SETLKW64 14 101 102 struct compat_flock64 { 103 short l_type; 104 short l_whence; 105 compat_loff_t l_start; 106 compat_loff_t l_len; 107 compat_pid_t l_pid; 108 }; 109 110 struct compat_statfs { 111 int f_type; 112 int f_bsize; 113 int f_blocks; 114 int f_bfree; 115 int f_bavail; 116 int f_files; 117 int f_ffree; 118 compat_fsid_t f_fsid; 119 int f_namelen; /* SunOS ignores this field. */ 120 int f_frsize; 121 int f_flags; 122 int f_spare[4]; 123 }; 124 125 #define COMPAT_RLIM_INFINITY 0xffffffff 126 127 typedef u32 compat_old_sigset_t; 128 129 #define _COMPAT_NSIG 64 130 #define _COMPAT_NSIG_BPW 32 131 132 typedef u32 compat_sigset_word; 133 134 typedef union compat_sigval { 135 compat_int_t sival_int; 136 compat_uptr_t sival_ptr; 137 } compat_sigval_t; 138 139 typedef struct compat_siginfo { 140 int si_signo; 141 int si_errno; 142 int si_code; 143 144 union { 145 /* The padding is the same size as AArch64. */ 146 int _pad[128/sizeof(int) - 3]; 147 148 /* kill() */ 149 struct { 150 compat_pid_t _pid; /* sender's pid */ 151 __compat_uid32_t _uid; /* sender's uid */ 152 } _kill; 153 154 /* POSIX.1b timers */ 155 struct { 156 compat_timer_t _tid; /* timer id */ 157 int _overrun; /* overrun count */ 158 compat_sigval_t _sigval; /* same as below */ 159 int _sys_private; /* not to be passed to user */ 160 } _timer; 161 162 /* POSIX.1b signals */ 163 struct { 164 compat_pid_t _pid; /* sender's pid */ 165 __compat_uid32_t _uid; /* sender's uid */ 166 compat_sigval_t _sigval; 167 } _rt; 168 169 /* SIGCHLD */ 170 struct { 171 compat_pid_t _pid; /* which child */ 172 __compat_uid32_t _uid; /* sender's uid */ 173 int _status; /* exit code */ 174 compat_clock_t _utime; 175 compat_clock_t _stime; 176 } _sigchld; 177 178 /* SIGILL, SIGFPE, SIGSEGV, SIGBUS */ 179 struct { 180 compat_uptr_t _addr; /* faulting insn/memory ref. */ 181 short _addr_lsb; /* LSB of the reported address */ 182 } _sigfault; 183 184 /* SIGPOLL */ 185 struct { 186 compat_long_t _band; /* POLL_IN, POLL_OUT, POLL_MSG */ 187 int _fd; 188 } _sigpoll; 189 } _sifields; 190 } compat_siginfo_t; 191 192 #define COMPAT_OFF_T_MAX 0x7fffffff 193 #define COMPAT_LOFF_T_MAX 0x7fffffffffffffffL 194 195 /* 196 * A pointer passed in from user mode. This should not 197 * be used for syscall parameters, just declare them 198 * as pointers because the syscall entry code will have 199 * appropriately converted them already. 200 */ 201 202 static inline void __user *compat_ptr(compat_uptr_t uptr) 203 { 204 return (void __user *)(unsigned long)uptr; 205 } 206 207 static inline compat_uptr_t ptr_to_compat(void __user *uptr) 208 { 209 return (u32)(unsigned long)uptr; 210 } 211 212 static inline void __user *arch_compat_alloc_user_space(long len) 213 { 214 struct pt_regs *regs = task_pt_regs(current); 215 return (void __user *)regs->compat_sp - len; 216 } 217 218 struct compat_ipc64_perm { 219 compat_key_t key; 220 __compat_uid32_t uid; 221 __compat_gid32_t gid; 222 __compat_uid32_t cuid; 223 __compat_gid32_t cgid; 224 unsigned short mode; 225 unsigned short __pad1; 226 unsigned short seq; 227 unsigned short __pad2; 228 compat_ulong_t unused1; 229 compat_ulong_t unused2; 230 }; 231 232 struct compat_semid64_ds { 233 struct compat_ipc64_perm sem_perm; 234 compat_time_t sem_otime; 235 compat_ulong_t __unused1; 236 compat_time_t sem_ctime; 237 compat_ulong_t __unused2; 238 compat_ulong_t sem_nsems; 239 compat_ulong_t __unused3; 240 compat_ulong_t __unused4; 241 }; 242 243 struct compat_msqid64_ds { 244 struct compat_ipc64_perm msg_perm; 245 compat_time_t msg_stime; 246 compat_ulong_t __unused1; 247 compat_time_t msg_rtime; 248 compat_ulong_t __unused2; 249 compat_time_t msg_ctime; 250 compat_ulong_t __unused3; 251 compat_ulong_t msg_cbytes; 252 compat_ulong_t msg_qnum; 253 compat_ulong_t msg_qbytes; 254 compat_pid_t msg_lspid; 255 compat_pid_t msg_lrpid; 256 compat_ulong_t __unused4; 257 compat_ulong_t __unused5; 258 }; 259 260 struct compat_shmid64_ds { 261 struct compat_ipc64_perm shm_perm; 262 compat_size_t shm_segsz; 263 compat_time_t shm_atime; 264 compat_ulong_t __unused1; 265 compat_time_t shm_dtime; 266 compat_ulong_t __unused2; 267 compat_time_t shm_ctime; 268 compat_ulong_t __unused3; 269 compat_pid_t shm_cpid; 270 compat_pid_t shm_lpid; 271 compat_ulong_t shm_nattch; 272 compat_ulong_t __unused4; 273 compat_ulong_t __unused5; 274 }; 275 276 static inline int is_compat_task(void) 277 { 278 return test_thread_flag(TIF_32BIT); 279 } 280 281 static inline int is_compat_thread(struct thread_info *thread) 282 { 283 return test_ti_thread_flag(thread, TIF_32BIT); 284 } 285 286 #else /* !CONFIG_COMPAT */ 287 288 static inline int is_compat_task(void) 289 { 290 return 0; 291 } 292 293 static inline int is_compat_thread(struct thread_info *thread) 294 { 295 return 0; 296 } 297 298 #endif /* CONFIG_COMPAT */ 299 #endif /* __KERNEL__ */ 300 #endif /* __ASM_COMPAT_H */ 301