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 | |
Chris Metcalf | 0707ad3 | 2010-06-25 17:04:17 -0400 | [diff] [blame] | 73 | #define compat_stat stat |
Chris Metcalf | 867e359 | 2010-05-28 23:09:12 -0400 | [diff] [blame] | 74 | #define compat_statfs statfs |
| 75 | |
| 76 | struct compat_sysctl { |
| 77 | unsigned int name; |
| 78 | int nlen; |
| 79 | unsigned int oldval; |
| 80 | unsigned int oldlenp; |
| 81 | unsigned int newval; |
| 82 | unsigned int newlen; |
| 83 | unsigned int __unused[4]; |
| 84 | }; |
| 85 | |
| 86 | |
| 87 | struct compat_flock { |
| 88 | short l_type; |
| 89 | short l_whence; |
| 90 | compat_off_t l_start; |
| 91 | compat_off_t l_len; |
| 92 | compat_pid_t l_pid; |
| 93 | }; |
| 94 | |
| 95 | #define F_GETLK64 12 /* using 'struct flock64' */ |
| 96 | #define F_SETLK64 13 |
| 97 | #define F_SETLKW64 14 |
| 98 | |
| 99 | struct compat_flock64 { |
| 100 | short l_type; |
| 101 | short l_whence; |
| 102 | compat_loff_t l_start; |
| 103 | compat_loff_t l_len; |
| 104 | compat_pid_t l_pid; |
| 105 | }; |
| 106 | |
| 107 | #define COMPAT_RLIM_INFINITY 0xffffffff |
| 108 | |
| 109 | #define _COMPAT_NSIG 64 |
| 110 | #define _COMPAT_NSIG_BPW 32 |
| 111 | |
| 112 | typedef u32 compat_sigset_word; |
| 113 | |
| 114 | #define COMPAT_OFF_T_MAX 0x7fffffff |
| 115 | #define COMPAT_LOFF_T_MAX 0x7fffffffffffffffL |
| 116 | |
| 117 | struct compat_ipc64_perm { |
| 118 | compat_key_t key; |
| 119 | __compat_uid32_t uid; |
| 120 | __compat_gid32_t gid; |
| 121 | __compat_uid32_t cuid; |
| 122 | __compat_gid32_t cgid; |
| 123 | unsigned short mode; |
| 124 | unsigned short __pad1; |
| 125 | unsigned short seq; |
| 126 | unsigned short __pad2; |
| 127 | compat_ulong_t unused1; |
| 128 | compat_ulong_t unused2; |
| 129 | }; |
| 130 | |
| 131 | struct compat_semid64_ds { |
| 132 | struct compat_ipc64_perm sem_perm; |
| 133 | compat_time_t sem_otime; |
| 134 | compat_ulong_t __unused1; |
| 135 | compat_time_t sem_ctime; |
| 136 | compat_ulong_t __unused2; |
| 137 | compat_ulong_t sem_nsems; |
| 138 | compat_ulong_t __unused3; |
| 139 | compat_ulong_t __unused4; |
| 140 | }; |
| 141 | |
| 142 | struct compat_msqid64_ds { |
| 143 | struct compat_ipc64_perm msg_perm; |
| 144 | compat_time_t msg_stime; |
| 145 | compat_ulong_t __unused1; |
| 146 | compat_time_t msg_rtime; |
| 147 | compat_ulong_t __unused2; |
| 148 | compat_time_t msg_ctime; |
| 149 | compat_ulong_t __unused3; |
| 150 | compat_ulong_t msg_cbytes; |
| 151 | compat_ulong_t msg_qnum; |
| 152 | compat_ulong_t msg_qbytes; |
| 153 | compat_pid_t msg_lspid; |
| 154 | compat_pid_t msg_lrpid; |
| 155 | compat_ulong_t __unused4; |
| 156 | compat_ulong_t __unused5; |
| 157 | }; |
| 158 | |
| 159 | struct compat_shmid64_ds { |
| 160 | struct compat_ipc64_perm shm_perm; |
| 161 | compat_size_t shm_segsz; |
| 162 | compat_time_t shm_atime; |
| 163 | compat_ulong_t __unused1; |
| 164 | compat_time_t shm_dtime; |
| 165 | compat_ulong_t __unused2; |
| 166 | compat_time_t shm_ctime; |
| 167 | compat_ulong_t __unused3; |
| 168 | compat_pid_t shm_cpid; |
| 169 | compat_pid_t shm_lpid; |
| 170 | compat_ulong_t shm_nattch; |
| 171 | compat_ulong_t __unused4; |
| 172 | compat_ulong_t __unused5; |
| 173 | }; |
| 174 | |
| 175 | /* |
| 176 | * A pointer passed in from user mode. This should not |
| 177 | * be used for syscall parameters, just declare them |
| 178 | * as pointers because the syscall entry code will have |
| 179 | * appropriately converted them already. |
| 180 | */ |
| 181 | |
| 182 | static inline void __user *compat_ptr(compat_uptr_t uptr) |
| 183 | { |
Chris Metcalf | 9f9c038 | 2010-06-25 17:00:56 -0400 | [diff] [blame] | 184 | return (void __user *)(long)(s32)uptr; |
Chris Metcalf | 867e359 | 2010-05-28 23:09:12 -0400 | [diff] [blame] | 185 | } |
| 186 | |
| 187 | static inline compat_uptr_t ptr_to_compat(void __user *uptr) |
| 188 | { |
| 189 | return (u32)(unsigned long)uptr; |
| 190 | } |
| 191 | |
| 192 | /* Sign-extend when storing a kernel pointer to a user's ptregs. */ |
| 193 | static inline unsigned long ptr_to_compat_reg(void __user *uptr) |
| 194 | { |
Chris Metcalf | 0707ad3 | 2010-06-25 17:04:17 -0400 | [diff] [blame] | 195 | return (long)(int)(long __force)uptr; |
Chris Metcalf | 867e359 | 2010-05-28 23:09:12 -0400 | [diff] [blame] | 196 | } |
| 197 | |
H. Peter Anvin | c41d68a | 2010-09-07 16:16:18 -0700 | [diff] [blame] | 198 | static inline void __user *arch_compat_alloc_user_space(long len) |
Chris Metcalf | 867e359 | 2010-05-28 23:09:12 -0400 | [diff] [blame] | 199 | { |
| 200 | struct pt_regs *regs = task_pt_regs(current); |
| 201 | return (void __user *)regs->sp - len; |
| 202 | } |
| 203 | |
| 204 | static inline int is_compat_task(void) |
| 205 | { |
| 206 | return current_thread_info()->status & TS_COMPAT; |
| 207 | } |
| 208 | |
| 209 | extern int compat_setup_rt_frame(int sig, struct k_sigaction *ka, |
| 210 | siginfo_t *info, sigset_t *set, |
| 211 | struct pt_regs *regs); |
| 212 | |
| 213 | /* Compat syscalls. */ |
| 214 | struct compat_sigaction; |
| 215 | struct compat_siginfo; |
| 216 | struct compat_sigaltstack; |
Chris Metcalf | e6e6c46 | 2010-09-15 11:16:05 -0400 | [diff] [blame] | 217 | long compat_sys_execve(const char __user *path, |
| 218 | const compat_uptr_t __user *argv, |
Chris Metcalf | d929b6a | 2010-10-14 14:34:33 -0400 | [diff] [blame^] | 219 | const compat_uptr_t __user *envp, struct pt_regs *); |
Chris Metcalf | 867e359 | 2010-05-28 23:09:12 -0400 | [diff] [blame] | 220 | long compat_sys_rt_sigaction(int sig, struct compat_sigaction __user *act, |
| 221 | struct compat_sigaction __user *oact, |
| 222 | size_t sigsetsize); |
| 223 | long compat_sys_rt_sigqueueinfo(int pid, int sig, |
| 224 | struct compat_siginfo __user *uinfo); |
Chris Metcalf | d929b6a | 2010-10-14 14:34:33 -0400 | [diff] [blame^] | 225 | long compat_sys_rt_sigreturn(struct pt_regs *); |
Chris Metcalf | 867e359 | 2010-05-28 23:09:12 -0400 | [diff] [blame] | 226 | long compat_sys_sigaltstack(const struct compat_sigaltstack __user *uss_ptr, |
Chris Metcalf | d929b6a | 2010-10-14 14:34:33 -0400 | [diff] [blame^] | 227 | struct compat_sigaltstack __user *uoss_ptr, |
| 228 | struct pt_regs *); |
Chris Metcalf | 867e359 | 2010-05-28 23:09:12 -0400 | [diff] [blame] | 229 | long compat_sys_truncate64(char __user *filename, u32 dummy, u32 low, u32 high); |
| 230 | long compat_sys_ftruncate64(unsigned int fd, u32 dummy, u32 low, u32 high); |
| 231 | long compat_sys_pread64(unsigned int fd, char __user *ubuf, size_t count, |
| 232 | u32 dummy, u32 low, u32 high); |
| 233 | long compat_sys_pwrite64(unsigned int fd, char __user *ubuf, size_t count, |
| 234 | u32 dummy, u32 low, u32 high); |
| 235 | long compat_sys_lookup_dcookie(u32 low, u32 high, char __user *buf, size_t len); |
| 236 | long compat_sys_sync_file_range2(int fd, unsigned int flags, |
| 237 | u32 offset_lo, u32 offset_hi, |
| 238 | u32 nbytes_lo, u32 nbytes_hi); |
| 239 | long compat_sys_fallocate(int fd, int mode, |
| 240 | u32 offset_lo, u32 offset_hi, |
| 241 | u32 len_lo, u32 len_hi); |
Chris Metcalf | 867e359 | 2010-05-28 23:09:12 -0400 | [diff] [blame] | 242 | long compat_sys_sched_rr_get_interval(compat_pid_t pid, |
| 243 | struct compat_timespec __user *interval); |
Chris Metcalf | 867e359 | 2010-05-28 23:09:12 -0400 | [diff] [blame] | 244 | |
| 245 | /* Versions of compat functions that differ from generic Linux. */ |
| 246 | struct compat_msgbuf; |
| 247 | long tile_compat_sys_msgsnd(int msqid, |
| 248 | struct compat_msgbuf __user *msgp, |
| 249 | size_t msgsz, int msgflg); |
| 250 | long tile_compat_sys_msgrcv(int msqid, |
| 251 | struct compat_msgbuf __user *msgp, |
| 252 | size_t msgsz, long msgtyp, int msgflg); |
| 253 | long tile_compat_sys_ptrace(compat_long_t request, compat_long_t pid, |
| 254 | compat_long_t addr, compat_long_t data); |
| 255 | |
| 256 | /* Tilera Linux syscalls that don't have "compat" versions. */ |
Chris Metcalf | 867e359 | 2010-05-28 23:09:12 -0400 | [diff] [blame] | 257 | #define compat_sys_flush_cache sys_flush_cache |
| 258 | |
Chris Metcalf | d929b6a | 2010-10-14 14:34:33 -0400 | [diff] [blame^] | 259 | /* These are the intvec_64.S trampolines. */ |
| 260 | long _compat_sys_execve(const char __user *path, |
| 261 | const compat_uptr_t __user *argv, |
| 262 | const compat_uptr_t __user *envp); |
| 263 | long _compat_sys_sigaltstack(const struct compat_sigaltstack __user *uss_ptr, |
| 264 | struct compat_sigaltstack __user *uoss_ptr); |
| 265 | long _compat_sys_rt_sigreturn(void); |
| 266 | |
Chris Metcalf | 867e359 | 2010-05-28 23:09:12 -0400 | [diff] [blame] | 267 | #endif /* _ASM_TILE_COMPAT_H */ |