1 /* 2 * sys_parisc32.c: Conversion between 32bit and 64bit native syscalls. 3 * 4 * Copyright (C) 2000-2001 Hewlett Packard Company 5 * Copyright (C) 2000 John Marvin 6 * Copyright (C) 2001 Matthew Wilcox 7 * 8 * These routines maintain argument size conversion between 32bit and 64bit 9 * environment. Based heavily on sys_ia32.c and sys_sparc32.c. 10 */ 11 12 #include <linux/compat.h> 13 #include <linux/kernel.h> 14 #include <linux/sched.h> 15 #include <linux/fs.h> 16 #include <linux/mm.h> 17 #include <linux/file.h> 18 #include <linux/signal.h> 19 #include <linux/resource.h> 20 #include <linux/times.h> 21 #include <linux/time.h> 22 #include <linux/smp.h> 23 #include <linux/smp_lock.h> 24 #include <linux/sem.h> 25 #include <linux/msg.h> 26 #include <linux/shm.h> 27 #include <linux/slab.h> 28 #include <linux/uio.h> 29 #include <linux/ncp_fs.h> 30 #include <linux/poll.h> 31 #include <linux/personality.h> 32 #include <linux/stat.h> 33 #include <linux/highmem.h> 34 #include <linux/highuid.h> 35 #include <linux/mman.h> 36 #include <linux/binfmts.h> 37 #include <linux/namei.h> 38 #include <linux/vfs.h> 39 #include <linux/ptrace.h> 40 #include <linux/swap.h> 41 #include <linux/syscalls.h> 42 43 #include <asm/types.h> 44 #include <asm/uaccess.h> 45 #include <asm/mmu_context.h> 46 47 #include "sys32.h" 48 49 #undef DEBUG 50 51 #ifdef DEBUG 52 #define DBG(x) printk x 53 #else 54 #define DBG(x) 55 #endif 56 57 /* 58 * sys32_execve() executes a new program. 59 */ 60 61 asmlinkage int sys32_execve(struct pt_regs *regs) 62 { 63 int error; 64 char *filename; 65 66 DBG(("sys32_execve(%p) r26 = 0x%lx\n", regs, regs->gr[26])); 67 filename = getname((const char __user *) regs->gr[26]); 68 error = PTR_ERR(filename); 69 if (IS_ERR(filename)) 70 goto out; 71 error = compat_do_execve(filename, compat_ptr(regs->gr[25]), 72 compat_ptr(regs->gr[24]), regs); 73 putname(filename); 74 out: 75 76 return error; 77 } 78 79 asmlinkage long sys32_unimplemented(int r26, int r25, int r24, int r23, 80 int r22, int r21, int r20) 81 { 82 printk(KERN_ERR "%s(%d): Unimplemented 32 on 64 syscall #%d!\n", 83 current->comm, current->pid, r20); 84 return -ENOSYS; 85 } 86 87 #ifdef CONFIG_SYSCTL 88 89 struct __sysctl_args32 { 90 u32 name; 91 int nlen; 92 u32 oldval; 93 u32 oldlenp; 94 u32 newval; 95 u32 newlen; 96 u32 __unused[4]; 97 }; 98 99 asmlinkage long sys32_sysctl(struct __sysctl_args32 __user *args) 100 { 101 #ifndef CONFIG_SYSCTL_SYSCALL 102 return -ENOSYS; 103 #else 104 struct __sysctl_args32 tmp; 105 int error; 106 unsigned int oldlen32; 107 size_t oldlen, __user *oldlenp = NULL; 108 unsigned long addr = (((long __force)&args->__unused[0]) + 7) & ~7; 109 110 DBG(("sysctl32(%p)\n", args)); 111 112 if (copy_from_user(&tmp, args, sizeof(tmp))) 113 return -EFAULT; 114 115 if (tmp.oldval && tmp.oldlenp) { 116 /* Duh, this is ugly and might not work if sysctl_args 117 is in read-only memory, but do_sysctl does indirectly 118 a lot of uaccess in both directions and we'd have to 119 basically copy the whole sysctl.c here, and 120 glibc's __sysctl uses rw memory for the structure 121 anyway. */ 122 /* a possibly better hack than this, which will avoid the 123 * problem if the struct is read only, is to push the 124 * 'oldlen' value out to the user's stack instead. -PB 125 */ 126 if (get_user(oldlen32, (u32 *)(u64)tmp.oldlenp)) 127 return -EFAULT; 128 oldlen = oldlen32; 129 if (put_user(oldlen, (size_t *)addr)) 130 return -EFAULT; 131 oldlenp = (size_t *)addr; 132 } 133 134 lock_kernel(); 135 error = do_sysctl((int __user *)(u64)tmp.name, tmp.nlen, 136 (void __user *)(u64)tmp.oldval, oldlenp, 137 (void __user *)(u64)tmp.newval, tmp.newlen); 138 unlock_kernel(); 139 if (oldlenp) { 140 if (!error) { 141 if (get_user(oldlen, (size_t *)addr)) { 142 error = -EFAULT; 143 } else { 144 oldlen32 = oldlen; 145 if (put_user(oldlen32, (u32 *)(u64)tmp.oldlenp)) 146 error = -EFAULT; 147 } 148 } 149 if (copy_to_user(args->__unused, tmp.__unused, sizeof(tmp.__unused))) 150 error = -EFAULT; 151 } 152 return error; 153 #endif 154 } 155 156 #endif /* CONFIG_SYSCTL */ 157 158 asmlinkage long sys32_sched_rr_get_interval(pid_t pid, 159 struct compat_timespec __user *interval) 160 { 161 struct timespec t; 162 int ret; 163 164 KERNEL_SYSCALL(ret, sys_sched_rr_get_interval, pid, (struct timespec __user *)&t); 165 if (put_compat_timespec(&t, interval)) 166 return -EFAULT; 167 return ret; 168 } 169 170 struct msgbuf32 { 171 int mtype; 172 char mtext[1]; 173 }; 174 175 asmlinkage long sys32_msgsnd(int msqid, 176 struct msgbuf32 __user *umsgp32, 177 size_t msgsz, int msgflg) 178 { 179 struct msgbuf *mb; 180 struct msgbuf32 mb32; 181 int err; 182 183 if ((mb = kmalloc(msgsz + sizeof *mb + 4, GFP_KERNEL)) == NULL) 184 return -ENOMEM; 185 186 err = get_user(mb32.mtype, &umsgp32->mtype); 187 mb->mtype = mb32.mtype; 188 err |= copy_from_user(mb->mtext, &umsgp32->mtext, msgsz); 189 190 if (err) 191 err = -EFAULT; 192 else 193 KERNEL_SYSCALL(err, sys_msgsnd, msqid, (struct msgbuf __user *)mb, msgsz, msgflg); 194 195 kfree(mb); 196 return err; 197 } 198 199 asmlinkage long sys32_msgrcv(int msqid, 200 struct msgbuf32 __user *umsgp32, 201 size_t msgsz, long msgtyp, int msgflg) 202 { 203 struct msgbuf *mb; 204 struct msgbuf32 mb32; 205 int err, len; 206 207 if ((mb = kmalloc(msgsz + sizeof *mb + 4, GFP_KERNEL)) == NULL) 208 return -ENOMEM; 209 210 KERNEL_SYSCALL(err, sys_msgrcv, msqid, (struct msgbuf __user *)mb, msgsz, msgtyp, msgflg); 211 212 if (err >= 0) { 213 len = err; 214 mb32.mtype = mb->mtype; 215 err = put_user(mb32.mtype, &umsgp32->mtype); 216 err |= copy_to_user(&umsgp32->mtext, mb->mtext, len); 217 if (err) 218 err = -EFAULT; 219 else 220 err = len; 221 } 222 223 kfree(mb); 224 return err; 225 } 226 227 asmlinkage int sys32_sendfile(int out_fd, int in_fd, compat_off_t __user *offset, s32 count) 228 { 229 mm_segment_t old_fs = get_fs(); 230 int ret; 231 off_t of; 232 233 if (offset && get_user(of, offset)) 234 return -EFAULT; 235 236 set_fs(KERNEL_DS); 237 ret = sys_sendfile(out_fd, in_fd, offset ? (off_t __user *)&of : NULL, count); 238 set_fs(old_fs); 239 240 if (offset && put_user(of, offset)) 241 return -EFAULT; 242 243 return ret; 244 } 245 246 asmlinkage int sys32_sendfile64(int out_fd, int in_fd, compat_loff_t __user *offset, s32 count) 247 { 248 mm_segment_t old_fs = get_fs(); 249 int ret; 250 loff_t lof; 251 252 if (offset && get_user(lof, offset)) 253 return -EFAULT; 254 255 set_fs(KERNEL_DS); 256 ret = sys_sendfile64(out_fd, in_fd, offset ? (loff_t __user *)&lof : NULL, count); 257 set_fs(old_fs); 258 259 if (offset && put_user(lof, offset)) 260 return -EFAULT; 261 262 return ret; 263 } 264 265 266 /* lseek() needs a wrapper because 'offset' can be negative, but the top 267 * half of the argument has been zeroed by syscall.S. 268 */ 269 270 asmlinkage int sys32_lseek(unsigned int fd, int offset, unsigned int origin) 271 { 272 return sys_lseek(fd, offset, origin); 273 } 274 275 asmlinkage long sys32_semctl(int semid, int semnum, int cmd, union semun arg) 276 { 277 union semun u; 278 279 if (cmd == SETVAL) { 280 /* Ugh. arg is a union of int,ptr,ptr,ptr, so is 8 bytes. 281 * The int should be in the first 4, but our argument 282 * frobbing has left it in the last 4. 283 */ 284 u.val = *((int *)&arg + 1); 285 return sys_semctl (semid, semnum, cmd, u); 286 } 287 return sys_semctl (semid, semnum, cmd, arg); 288 } 289 290 long sys32_lookup_dcookie(u32 cookie_high, u32 cookie_low, char __user *buf, 291 size_t len) 292 { 293 return sys_lookup_dcookie((u64)cookie_high << 32 | cookie_low, 294 buf, len); 295 } 296 297 asmlinkage long compat_sys_fallocate(int fd, int mode, u32 offhi, u32 offlo, 298 u32 lenhi, u32 lenlo) 299 { 300 return sys_fallocate(fd, mode, ((loff_t)offhi << 32) | offlo, 301 ((loff_t)lenhi << 32) | lenlo); 302 } 303