Chris Metcalf | 867e359 | 2010-05-28 23:09:12 -0400 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2010 Tilera Corporation. All Rights Reserved. |
| 3 | * |
| 4 | * This program is free software; you can redistribute it and/or |
| 5 | * modify it under the terms of the GNU General Public License |
| 6 | * as published by the Free Software Foundation, version 2. |
| 7 | * |
| 8 | * This program is distributed in the hope that it will be useful, but |
| 9 | * WITHOUT ANY WARRANTY; without even the implied warranty of |
| 10 | * MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE, GOOD TITLE or |
| 11 | * NON INFRINGEMENT. See the GNU General Public License for |
| 12 | * more details. |
| 13 | */ |
| 14 | |
| 15 | #ifndef _ASM_TILE_COMPAT_H |
| 16 | #define _ASM_TILE_COMPAT_H |
| 17 | |
| 18 | /* |
| 19 | * Architecture specific compatibility types |
| 20 | */ |
| 21 | #include <linux/types.h> |
| 22 | #include <linux/sched.h> |
| 23 | |
| 24 | #define COMPAT_USER_HZ 100 |
| 25 | |
| 26 | /* "long" and pointer-based types are different. */ |
| 27 | typedef s32 compat_long_t; |
| 28 | typedef u32 compat_ulong_t; |
| 29 | typedef u32 compat_size_t; |
| 30 | typedef s32 compat_ssize_t; |
| 31 | typedef s32 compat_off_t; |
| 32 | typedef s32 compat_time_t; |
| 33 | typedef s32 compat_clock_t; |
| 34 | typedef u32 compat_ino_t; |
| 35 | typedef u32 compat_caddr_t; |
| 36 | typedef u32 compat_uptr_t; |
| 37 | |
| 38 | /* Many types are "int" or otherwise the same. */ |
| 39 | typedef __kernel_pid_t compat_pid_t; |
| 40 | typedef __kernel_uid_t __compat_uid_t; |
| 41 | typedef __kernel_gid_t __compat_gid_t; |
| 42 | typedef __kernel_uid32_t __compat_uid32_t; |
| 43 | typedef __kernel_uid32_t __compat_gid32_t; |
| 44 | typedef __kernel_mode_t compat_mode_t; |
| 45 | typedef __kernel_dev_t compat_dev_t; |
| 46 | typedef __kernel_loff_t compat_loff_t; |
| 47 | typedef __kernel_nlink_t compat_nlink_t; |
| 48 | typedef __kernel_ipc_pid_t compat_ipc_pid_t; |
| 49 | typedef __kernel_daddr_t compat_daddr_t; |
| 50 | typedef __kernel_fsid_t compat_fsid_t; |
| 51 | typedef __kernel_timer_t compat_timer_t; |
| 52 | typedef __kernel_key_t compat_key_t; |
| 53 | typedef int compat_int_t; |
| 54 | typedef s64 compat_s64; |
| 55 | typedef uint compat_uint_t; |
| 56 | typedef u64 compat_u64; |
| 57 | |
| 58 | /* We use the same register dump format in 32-bit images. */ |
| 59 | typedef unsigned long compat_elf_greg_t; |
| 60 | #define COMPAT_ELF_NGREG (sizeof(struct pt_regs) / sizeof(compat_elf_greg_t)) |
| 61 | typedef compat_elf_greg_t compat_elf_gregset_t[COMPAT_ELF_NGREG]; |
| 62 | |
| 63 | struct compat_timespec { |
| 64 | compat_time_t tv_sec; |
| 65 | s32 tv_nsec; |
| 66 | }; |
| 67 | |
| 68 | struct compat_timeval { |
| 69 | compat_time_t tv_sec; |
| 70 | s32 tv_usec; |
| 71 | }; |
| 72 | |
| 73 | struct compat_stat { |
| 74 | unsigned int st_dev; |
| 75 | unsigned int st_ino; |
| 76 | unsigned int st_mode; |
| 77 | unsigned int st_nlink; |
| 78 | unsigned int st_uid; |
| 79 | unsigned int st_gid; |
| 80 | unsigned int st_rdev; |
| 81 | unsigned int __pad1; |
| 82 | int st_size; |
| 83 | int st_blksize; |
| 84 | int __pad2; |
| 85 | int st_blocks; |
| 86 | int st_atime; |
| 87 | unsigned int st_atime_nsec; |
| 88 | int st_mtime; |
| 89 | unsigned int st_mtime_nsec; |
| 90 | int st_ctime; |
| 91 | unsigned int st_ctime_nsec; |
| 92 | unsigned int __unused[2]; |
| 93 | }; |
| 94 | |
| 95 | struct compat_stat64 { |
| 96 | unsigned long st_dev; |
| 97 | unsigned long st_ino; |
| 98 | unsigned int st_mode; |
| 99 | unsigned int st_nlink; |
| 100 | unsigned int st_uid; |
| 101 | unsigned int st_gid; |
| 102 | unsigned long st_rdev; |
| 103 | long st_size; |
| 104 | unsigned int st_blksize; |
| 105 | unsigned long st_blocks __attribute__((packed)); |
| 106 | unsigned int st_atime; |
| 107 | unsigned int st_atime_nsec; |
| 108 | unsigned int st_mtime; |
| 109 | unsigned int st_mtime_nsec; |
| 110 | unsigned int st_ctime; |
| 111 | unsigned int st_ctime_nsec; |
| 112 | unsigned int __unused8; |
| 113 | }; |
| 114 | |
| 115 | #define compat_statfs statfs |
| 116 | |
| 117 | struct compat_sysctl { |
| 118 | unsigned int name; |
| 119 | int nlen; |
| 120 | unsigned int oldval; |
| 121 | unsigned int oldlenp; |
| 122 | unsigned int newval; |
| 123 | unsigned int newlen; |
| 124 | unsigned int __unused[4]; |
| 125 | }; |
| 126 | |
| 127 | |
| 128 | struct compat_flock { |
| 129 | short l_type; |
| 130 | short l_whence; |
| 131 | compat_off_t l_start; |
| 132 | compat_off_t l_len; |
| 133 | compat_pid_t l_pid; |
| 134 | }; |
| 135 | |
| 136 | #define F_GETLK64 12 /* using 'struct flock64' */ |
| 137 | #define F_SETLK64 13 |
| 138 | #define F_SETLKW64 14 |
| 139 | |
| 140 | struct compat_flock64 { |
| 141 | short l_type; |
| 142 | short l_whence; |
| 143 | compat_loff_t l_start; |
| 144 | compat_loff_t l_len; |
| 145 | compat_pid_t l_pid; |
| 146 | }; |
| 147 | |
| 148 | #define COMPAT_RLIM_INFINITY 0xffffffff |
| 149 | |
| 150 | #define _COMPAT_NSIG 64 |
| 151 | #define _COMPAT_NSIG_BPW 32 |
| 152 | |
| 153 | typedef u32 compat_sigset_word; |
| 154 | |
| 155 | #define COMPAT_OFF_T_MAX 0x7fffffff |
| 156 | #define COMPAT_LOFF_T_MAX 0x7fffffffffffffffL |
| 157 | |
| 158 | struct compat_ipc64_perm { |
| 159 | compat_key_t key; |
| 160 | __compat_uid32_t uid; |
| 161 | __compat_gid32_t gid; |
| 162 | __compat_uid32_t cuid; |
| 163 | __compat_gid32_t cgid; |
| 164 | unsigned short mode; |
| 165 | unsigned short __pad1; |
| 166 | unsigned short seq; |
| 167 | unsigned short __pad2; |
| 168 | compat_ulong_t unused1; |
| 169 | compat_ulong_t unused2; |
| 170 | }; |
| 171 | |
| 172 | struct compat_semid64_ds { |
| 173 | struct compat_ipc64_perm sem_perm; |
| 174 | compat_time_t sem_otime; |
| 175 | compat_ulong_t __unused1; |
| 176 | compat_time_t sem_ctime; |
| 177 | compat_ulong_t __unused2; |
| 178 | compat_ulong_t sem_nsems; |
| 179 | compat_ulong_t __unused3; |
| 180 | compat_ulong_t __unused4; |
| 181 | }; |
| 182 | |
| 183 | struct compat_msqid64_ds { |
| 184 | struct compat_ipc64_perm msg_perm; |
| 185 | compat_time_t msg_stime; |
| 186 | compat_ulong_t __unused1; |
| 187 | compat_time_t msg_rtime; |
| 188 | compat_ulong_t __unused2; |
| 189 | compat_time_t msg_ctime; |
| 190 | compat_ulong_t __unused3; |
| 191 | compat_ulong_t msg_cbytes; |
| 192 | compat_ulong_t msg_qnum; |
| 193 | compat_ulong_t msg_qbytes; |
| 194 | compat_pid_t msg_lspid; |
| 195 | compat_pid_t msg_lrpid; |
| 196 | compat_ulong_t __unused4; |
| 197 | compat_ulong_t __unused5; |
| 198 | }; |
| 199 | |
| 200 | struct compat_shmid64_ds { |
| 201 | struct compat_ipc64_perm shm_perm; |
| 202 | compat_size_t shm_segsz; |
| 203 | compat_time_t shm_atime; |
| 204 | compat_ulong_t __unused1; |
| 205 | compat_time_t shm_dtime; |
| 206 | compat_ulong_t __unused2; |
| 207 | compat_time_t shm_ctime; |
| 208 | compat_ulong_t __unused3; |
| 209 | compat_pid_t shm_cpid; |
| 210 | compat_pid_t shm_lpid; |
| 211 | compat_ulong_t shm_nattch; |
| 212 | compat_ulong_t __unused4; |
| 213 | compat_ulong_t __unused5; |
| 214 | }; |
| 215 | |
| 216 | /* |
| 217 | * A pointer passed in from user mode. This should not |
| 218 | * be used for syscall parameters, just declare them |
| 219 | * as pointers because the syscall entry code will have |
| 220 | * appropriately converted them already. |
| 221 | */ |
| 222 | |
| 223 | static inline void __user *compat_ptr(compat_uptr_t uptr) |
| 224 | { |
Chris Metcalf | 9f9c038 | 2010-06-25 17:00:56 -0400 | [diff] [blame^] | 225 | return (void __user *)(long)(s32)uptr; |
Chris Metcalf | 867e359 | 2010-05-28 23:09:12 -0400 | [diff] [blame] | 226 | } |
| 227 | |
| 228 | static inline compat_uptr_t ptr_to_compat(void __user *uptr) |
| 229 | { |
| 230 | return (u32)(unsigned long)uptr; |
| 231 | } |
| 232 | |
| 233 | /* Sign-extend when storing a kernel pointer to a user's ptregs. */ |
| 234 | static inline unsigned long ptr_to_compat_reg(void __user *uptr) |
| 235 | { |
| 236 | return (long)(int)(long)uptr; |
| 237 | } |
| 238 | |
| 239 | static inline void __user *compat_alloc_user_space(long len) |
| 240 | { |
| 241 | struct pt_regs *regs = task_pt_regs(current); |
| 242 | return (void __user *)regs->sp - len; |
| 243 | } |
| 244 | |
| 245 | static inline int is_compat_task(void) |
| 246 | { |
| 247 | return current_thread_info()->status & TS_COMPAT; |
| 248 | } |
| 249 | |
| 250 | extern int compat_setup_rt_frame(int sig, struct k_sigaction *ka, |
| 251 | siginfo_t *info, sigset_t *set, |
| 252 | struct pt_regs *regs); |
| 253 | |
| 254 | /* Compat syscalls. */ |
| 255 | struct compat_sigaction; |
| 256 | struct compat_siginfo; |
| 257 | struct compat_sigaltstack; |
| 258 | long compat_sys_execve(char __user *path, compat_uptr_t __user *argv, |
| 259 | compat_uptr_t __user *envp); |
| 260 | long compat_sys_rt_sigaction(int sig, struct compat_sigaction __user *act, |
| 261 | struct compat_sigaction __user *oact, |
| 262 | size_t sigsetsize); |
| 263 | long compat_sys_rt_sigqueueinfo(int pid, int sig, |
| 264 | struct compat_siginfo __user *uinfo); |
| 265 | long compat_sys_rt_sigreturn(void); |
| 266 | long compat_sys_sigaltstack(const struct compat_sigaltstack __user *uss_ptr, |
| 267 | struct compat_sigaltstack __user *uoss_ptr); |
| 268 | long compat_sys_truncate64(char __user *filename, u32 dummy, u32 low, u32 high); |
| 269 | long compat_sys_ftruncate64(unsigned int fd, u32 dummy, u32 low, u32 high); |
| 270 | long compat_sys_pread64(unsigned int fd, char __user *ubuf, size_t count, |
| 271 | u32 dummy, u32 low, u32 high); |
| 272 | long compat_sys_pwrite64(unsigned int fd, char __user *ubuf, size_t count, |
| 273 | u32 dummy, u32 low, u32 high); |
| 274 | long compat_sys_lookup_dcookie(u32 low, u32 high, char __user *buf, size_t len); |
| 275 | long compat_sys_sync_file_range2(int fd, unsigned int flags, |
| 276 | u32 offset_lo, u32 offset_hi, |
| 277 | u32 nbytes_lo, u32 nbytes_hi); |
| 278 | long compat_sys_fallocate(int fd, int mode, |
| 279 | u32 offset_lo, u32 offset_hi, |
| 280 | u32 len_lo, u32 len_hi); |
| 281 | long compat_sys_stat64(char __user *filename, |
| 282 | struct compat_stat64 __user *statbuf); |
| 283 | long compat_sys_lstat64(char __user *filename, |
| 284 | struct compat_stat64 __user *statbuf); |
| 285 | long compat_sys_fstat64(unsigned int fd, struct compat_stat64 __user *statbuf); |
| 286 | long compat_sys_fstatat64(int dfd, char __user *filename, |
| 287 | struct compat_stat64 __user *statbuf, int flag); |
| 288 | long compat_sys_sched_rr_get_interval(compat_pid_t pid, |
| 289 | struct compat_timespec __user *interval); |
| 290 | ssize_t compat_sys_sendfile(int out_fd, int in_fd, compat_off_t __user *offset, |
| 291 | size_t count); |
| 292 | |
| 293 | /* Versions of compat functions that differ from generic Linux. */ |
| 294 | struct compat_msgbuf; |
| 295 | long tile_compat_sys_msgsnd(int msqid, |
| 296 | struct compat_msgbuf __user *msgp, |
| 297 | size_t msgsz, int msgflg); |
| 298 | long tile_compat_sys_msgrcv(int msqid, |
| 299 | struct compat_msgbuf __user *msgp, |
| 300 | size_t msgsz, long msgtyp, int msgflg); |
| 301 | long tile_compat_sys_ptrace(compat_long_t request, compat_long_t pid, |
| 302 | compat_long_t addr, compat_long_t data); |
| 303 | |
| 304 | /* Tilera Linux syscalls that don't have "compat" versions. */ |
| 305 | #define compat_sys_raise_fpe sys_raise_fpe |
| 306 | #define compat_sys_flush_cache sys_flush_cache |
| 307 | |
| 308 | #endif /* _ASM_TILE_COMPAT_H */ |