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 asmlinkage long sys32_sched_rr_get_interval(pid_t pid, 88 struct compat_timespec __user *interval) 89 { 90 struct timespec t; 91 int ret; 92 93 KERNEL_SYSCALL(ret, sys_sched_rr_get_interval, pid, (struct timespec __user *)&t); 94 if (put_compat_timespec(&t, interval)) 95 return -EFAULT; 96 return ret; 97 } 98 99 struct msgbuf32 { 100 int mtype; 101 char mtext[1]; 102 }; 103 104 asmlinkage long sys32_msgsnd(int msqid, 105 struct msgbuf32 __user *umsgp32, 106 size_t msgsz, int msgflg) 107 { 108 struct msgbuf *mb; 109 struct msgbuf32 mb32; 110 int err; 111 112 if ((mb = kmalloc(msgsz + sizeof *mb + 4, GFP_KERNEL)) == NULL) 113 return -ENOMEM; 114 115 err = get_user(mb32.mtype, &umsgp32->mtype); 116 mb->mtype = mb32.mtype; 117 err |= copy_from_user(mb->mtext, &umsgp32->mtext, msgsz); 118 119 if (err) 120 err = -EFAULT; 121 else 122 KERNEL_SYSCALL(err, sys_msgsnd, msqid, (struct msgbuf __user *)mb, msgsz, msgflg); 123 124 kfree(mb); 125 return err; 126 } 127 128 asmlinkage long sys32_msgrcv(int msqid, 129 struct msgbuf32 __user *umsgp32, 130 size_t msgsz, long msgtyp, int msgflg) 131 { 132 struct msgbuf *mb; 133 struct msgbuf32 mb32; 134 int err, len; 135 136 if ((mb = kmalloc(msgsz + sizeof *mb + 4, GFP_KERNEL)) == NULL) 137 return -ENOMEM; 138 139 KERNEL_SYSCALL(err, sys_msgrcv, msqid, (struct msgbuf __user *)mb, msgsz, msgtyp, msgflg); 140 141 if (err >= 0) { 142 len = err; 143 mb32.mtype = mb->mtype; 144 err = put_user(mb32.mtype, &umsgp32->mtype); 145 err |= copy_to_user(&umsgp32->mtext, mb->mtext, len); 146 if (err) 147 err = -EFAULT; 148 else 149 err = len; 150 } 151 152 kfree(mb); 153 return err; 154 } 155 156 asmlinkage int sys32_sendfile(int out_fd, int in_fd, compat_off_t __user *offset, s32 count) 157 { 158 mm_segment_t old_fs = get_fs(); 159 int ret; 160 off_t of; 161 162 if (offset && get_user(of, offset)) 163 return -EFAULT; 164 165 set_fs(KERNEL_DS); 166 ret = sys_sendfile(out_fd, in_fd, offset ? (off_t __user *)&of : NULL, count); 167 set_fs(old_fs); 168 169 if (offset && put_user(of, offset)) 170 return -EFAULT; 171 172 return ret; 173 } 174 175 asmlinkage int sys32_sendfile64(int out_fd, int in_fd, compat_loff_t __user *offset, s32 count) 176 { 177 mm_segment_t old_fs = get_fs(); 178 int ret; 179 loff_t lof; 180 181 if (offset && get_user(lof, offset)) 182 return -EFAULT; 183 184 set_fs(KERNEL_DS); 185 ret = sys_sendfile64(out_fd, in_fd, offset ? (loff_t __user *)&lof : NULL, count); 186 set_fs(old_fs); 187 188 if (offset && put_user(lof, offset)) 189 return -EFAULT; 190 191 return ret; 192 } 193 194 195 /* lseek() needs a wrapper because 'offset' can be negative, but the top 196 * half of the argument has been zeroed by syscall.S. 197 */ 198 199 asmlinkage int sys32_lseek(unsigned int fd, int offset, unsigned int origin) 200 { 201 return sys_lseek(fd, offset, origin); 202 } 203 204 asmlinkage long sys32_semctl(int semid, int semnum, int cmd, union semun arg) 205 { 206 union semun u; 207 208 if (cmd == SETVAL) { 209 /* Ugh. arg is a union of int,ptr,ptr,ptr, so is 8 bytes. 210 * The int should be in the first 4, but our argument 211 * frobbing has left it in the last 4. 212 */ 213 u.val = *((int *)&arg + 1); 214 return sys_semctl (semid, semnum, cmd, u); 215 } 216 return sys_semctl (semid, semnum, cmd, arg); 217 } 218 219 long sys32_lookup_dcookie(u32 cookie_high, u32 cookie_low, char __user *buf, 220 size_t len) 221 { 222 return sys_lookup_dcookie((u64)cookie_high << 32 | cookie_low, 223 buf, len); 224 } 225 226 asmlinkage long compat_sys_fallocate(int fd, int mode, u32 offhi, u32 offlo, 227 u32 lenhi, u32 lenlo) 228 { 229 return sys_fallocate(fd, mode, ((loff_t)offhi << 32) | offlo, 230 ((loff_t)lenhi << 32) | lenlo); 231 } 232