2 * sys_parisc32.c: Conversion between 32bit and 64bit native syscalls.
4 * Copyright (C) 2000-2001 Hewlett Packard Company
5 * Copyright (C) 2000 John Marvin
6 * Copyright (C) 2001 Matthew Wilcox
8 * These routines maintain argument size conversion between 32bit and 64bit
9 * environment. Based heavily on sys_ia32.c and sys_sparc32.c.
12 #include <linux/compat.h>
13 #include <linux/kernel.h>
14 #include <linux/sched.h>
17 #include <linux/file.h>
18 #include <linux/signal.h>
19 #include <linux/resource.h>
20 #include <linux/times.h>
21 #include <linux/utsname.h>
22 #include <linux/time.h>
23 #include <linux/smp.h>
24 #include <linux/smp_lock.h>
25 #include <linux/sem.h>
26 #include <linux/msg.h>
27 #include <linux/shm.h>
28 #include <linux/slab.h>
29 #include <linux/uio.h>
30 #include <linux/nfs_fs.h>
31 #include <linux/ncp_fs.h>
32 #include <linux/sunrpc/svc.h>
33 #include <linux/nfsd/nfsd.h>
34 #include <linux/nfsd/cache.h>
35 #include <linux/nfsd/xdr.h>
36 #include <linux/nfsd/syscall.h>
37 #include <linux/poll.h>
38 #include <linux/personality.h>
39 #include <linux/stat.h>
40 #include <linux/highmem.h>
41 #include <linux/highuid.h>
42 #include <linux/mman.h>
43 #include <linux/binfmts.h>
44 #include <linux/namei.h>
45 #include <linux/vfs.h>
46 #include <linux/ptrace.h>
47 #include <linux/swap.h>
48 #include <linux/syscalls.h>
50 #include <asm/types.h>
51 #include <asm/uaccess.h>
52 #include <asm/semaphore.h>
53 #include <asm/mmu_context.h>
60 #define DBG(x) printk x
66 * sys32_execve() executes a new program.
69 asmlinkage int sys32_execve(struct pt_regs *regs)
74 DBG(("sys32_execve(%p) r26 = 0x%lx\n", regs, regs->gr[26]));
75 filename = getname((const char __user *) regs->gr[26]);
76 error = PTR_ERR(filename);
79 error = compat_do_execve(filename, compat_ptr(regs->gr[25]),
80 compat_ptr(regs->gr[24]), regs);
83 current->ptrace &= ~PT_DTRACE;
92 asmlinkage long sys32_unimplemented(int r26, int r25, int r24, int r23,
93 int r22, int r21, int r20)
95 printk(KERN_ERR "%s(%d): Unimplemented 32 on 64 syscall #%d!\n",
96 current->comm, current->pid, r20);
102 struct __sysctl_args32 {
112 asmlinkage long sys32_sysctl(struct __sysctl_args32 __user *args)
114 struct __sysctl_args32 tmp;
116 unsigned int oldlen32;
117 size_t oldlen, *oldlenp = NULL;
118 unsigned long addr = (((long __force)&args->__unused[0]) + 7) & ~7;
119 extern int do_sysctl(int *name, int nlen, void *oldval, size_t *oldlenp,
120 void *newval, size_t newlen);
122 DBG(("sysctl32(%p)\n", args));
124 if (copy_from_user(&tmp, args, sizeof(tmp)))
127 if (tmp.oldval && tmp.oldlenp) {
128 /* Duh, this is ugly and might not work if sysctl_args
129 is in read-only memory, but do_sysctl does indirectly
130 a lot of uaccess in both directions and we'd have to
131 basically copy the whole sysctl.c here, and
132 glibc's __sysctl uses rw memory for the structure
134 /* a possibly better hack than this, which will avoid the
135 * problem if the struct is read only, is to push the
136 * 'oldlen' value out to the user's stack instead. -PB
138 if (get_user(oldlen32, (u32 *)(u64)tmp.oldlenp))
141 if (put_user(oldlen, (size_t *)addr))
143 oldlenp = (size_t *)addr;
147 error = do_sysctl((int *)(u64)tmp.name, tmp.nlen, (void *)(u64)tmp.oldval,
148 oldlenp, (void *)(u64)tmp.newval, tmp.newlen);
152 if (get_user(oldlen, (size_t *)addr)) {
156 if (put_user(oldlen32, (u32 *)(u64)tmp.oldlenp))
160 if (copy_to_user(&args->__unused[0], tmp.__unused, sizeof(tmp.__unused)))
166 #endif /* CONFIG_SYSCTL */
168 asmlinkage long sys32_sched_rr_get_interval(pid_t pid,
169 struct compat_timespec __user *interval)
174 KERNEL_SYSCALL(ret, sys_sched_rr_get_interval, pid, (struct timespec __user *)&t);
175 if (put_compat_timespec(&t, interval))
181 put_compat_timeval(struct compat_timeval __user *u, struct timeval *t)
183 struct compat_timeval t32;
184 t32.tv_sec = t->tv_sec;
185 t32.tv_usec = t->tv_usec;
186 return copy_to_user(u, &t32, sizeof t32);
189 static inline long get_ts32(struct timespec *o, struct compat_timeval __user *i)
193 if (__get_user(o->tv_sec, &i->tv_sec))
195 if (__get_user(usec, &i->tv_usec))
197 o->tv_nsec = usec * 1000;
202 sys32_gettimeofday(struct compat_timeval __user *tv, struct timezone __user *tz)
204 extern void do_gettimeofday(struct timeval *tv);
208 do_gettimeofday(&ktv);
209 if (put_compat_timeval(tv, &ktv))
213 extern struct timezone sys_tz;
214 if (copy_to_user(tz, &sys_tz, sizeof(sys_tz)))
221 int sys32_settimeofday(struct compat_timeval __user *tv, struct timezone __user *tz)
227 if (get_ts32(&kts, tv))
231 if (copy_from_user(&ktz, tz, sizeof(ktz)))
235 return do_sys_settimeofday(tv ? &kts : NULL, tz ? &ktz : NULL);
238 int cp_compat_stat(struct kstat *stat, struct compat_stat __user *statbuf)
242 if (stat->size > MAX_NON_LFS || !new_valid_dev(stat->dev) ||
243 !new_valid_dev(stat->rdev))
246 err = put_user(new_encode_dev(stat->dev), &statbuf->st_dev);
247 err |= put_user(stat->ino, &statbuf->st_ino);
248 err |= put_user(stat->mode, &statbuf->st_mode);
249 err |= put_user(stat->nlink, &statbuf->st_nlink);
250 err |= put_user(0, &statbuf->st_reserved1);
251 err |= put_user(0, &statbuf->st_reserved2);
252 err |= put_user(new_encode_dev(stat->rdev), &statbuf->st_rdev);
253 err |= put_user(stat->size, &statbuf->st_size);
254 err |= put_user(stat->atime.tv_sec, &statbuf->st_atime);
255 err |= put_user(stat->atime.tv_nsec, &statbuf->st_atime_nsec);
256 err |= put_user(stat->mtime.tv_sec, &statbuf->st_mtime);
257 err |= put_user(stat->mtime.tv_nsec, &statbuf->st_mtime_nsec);
258 err |= put_user(stat->ctime.tv_sec, &statbuf->st_ctime);
259 err |= put_user(stat->ctime.tv_nsec, &statbuf->st_ctime_nsec);
260 err |= put_user(stat->blksize, &statbuf->st_blksize);
261 err |= put_user(stat->blocks, &statbuf->st_blocks);
262 err |= put_user(0, &statbuf->__unused1);
263 err |= put_user(0, &statbuf->__unused2);
264 err |= put_user(0, &statbuf->__unused3);
265 err |= put_user(0, &statbuf->__unused4);
266 err |= put_user(0, &statbuf->__unused5);
267 err |= put_user(0, &statbuf->st_fstype); /* not avail */
268 err |= put_user(0, &statbuf->st_realdev); /* not avail */
269 err |= put_user(0, &statbuf->st_basemode); /* not avail */
270 err |= put_user(0, &statbuf->st_spareshort);
271 err |= put_user(stat->uid, &statbuf->st_uid);
272 err |= put_user(stat->gid, &statbuf->st_gid);
273 err |= put_user(0, &statbuf->st_spare4[0]);
274 err |= put_user(0, &statbuf->st_spare4[1]);
275 err |= put_user(0, &statbuf->st_spare4[2]);
280 struct linux32_dirent {
287 struct old_linux32_dirent {
294 struct getdents32_callback {
295 struct linux32_dirent __user * current_dir;
296 struct linux32_dirent __user * previous;
301 struct readdir32_callback {
302 struct old_linux32_dirent __user * dirent;
306 #define ROUND_UP(x,a) ((__typeof__(x))(((unsigned long)(x) + ((a) - 1)) & ~((a) - 1)))
307 #define NAME_OFFSET(de) ((int) ((de)->d_name - (char __user *) (de)))
309 filldir32 (void *__buf, const char *name, int namlen, loff_t offset, ino_t ino,
312 struct linux32_dirent __user * dirent;
313 struct getdents32_callback * buf = (struct getdents32_callback *) __buf;
314 int reclen = ROUND_UP(NAME_OFFSET(dirent) + namlen + 1, 4);
316 buf->error = -EINVAL; /* only used if we fail.. */
317 if (reclen > buf->count)
319 dirent = buf->previous;
321 put_user(offset, &dirent->d_off);
322 dirent = buf->current_dir;
323 buf->previous = dirent;
324 put_user(ino, &dirent->d_ino);
325 put_user(reclen, &dirent->d_reclen);
326 copy_to_user(dirent->d_name, name, namlen);
327 put_user(0, dirent->d_name + namlen);
328 dirent = ((void __user *)dirent) + reclen;
329 buf->current_dir = dirent;
330 buf->count -= reclen;
335 sys32_getdents (unsigned int fd, void __user * dirent, unsigned int count)
338 struct linux32_dirent __user * lastdirent;
339 struct getdents32_callback buf;
347 buf.current_dir = (struct linux32_dirent __user *) dirent;
352 error = vfs_readdir(file, filldir32, &buf);
356 lastdirent = buf.previous;
358 put_user(file->f_pos, &lastdirent->d_off);
359 error = count - buf.count;
369 fillonedir32 (void * __buf, const char * name, int namlen, loff_t offset, ino_t ino,
372 struct readdir32_callback * buf = (struct readdir32_callback *) __buf;
373 struct old_linux32_dirent __user * dirent;
378 dirent = buf->dirent;
379 put_user(ino, &dirent->d_ino);
380 put_user(offset, &dirent->d_offset);
381 put_user(namlen, &dirent->d_namlen);
382 copy_to_user(dirent->d_name, name, namlen);
383 put_user(0, dirent->d_name + namlen);
388 sys32_readdir (unsigned int fd, void __user * dirent, unsigned int count)
392 struct readdir32_callback buf;
402 error = vfs_readdir(file, fillonedir32, &buf);
410 /*** copied from mips64 ***/
412 * Ooo, nasty. We need here to frob 32-bit unsigned longs to
413 * 64-bit unsigned longs.
417 get_fd_set32(unsigned long n, u32 *ufdset, unsigned long *fdset)
419 n = (n + 8*sizeof(u32) - 1) / (8*sizeof(u32));
423 if (!access_ok(VERIFY_WRITE, ufdset, n*sizeof(u32)))
430 __get_user(l, ufdset);
431 __get_user(h, ufdset+1);
433 *fdset++ = h << 32 | l;
437 __get_user(*fdset, ufdset);
439 /* Tricky, must clear full unsigned long in the
440 * kernel fdset at the end, this makes sure that
443 memset(fdset, 0, ((n + 1) & ~1)*sizeof(u32));
449 set_fd_set32(unsigned long n, u32 *ufdset, unsigned long *fdset)
452 n = (n + 8*sizeof(u32) - 1) / (8*sizeof(u32));
463 __put_user(l, ufdset);
464 __put_user(h, ufdset+1);
469 __put_user(*fdset, ufdset);
477 asmlinkage long sys32_msgsnd(int msqid,
478 struct msgbuf32 __user *umsgp32,
479 size_t msgsz, int msgflg)
482 struct msgbuf32 mb32;
485 if ((mb = kmalloc(msgsz + sizeof *mb + 4, GFP_KERNEL)) == NULL)
488 err = get_user(mb32.mtype, &umsgp32->mtype);
489 mb->mtype = mb32.mtype;
490 err |= copy_from_user(mb->mtext, &umsgp32->mtext, msgsz);
495 KERNEL_SYSCALL(err, sys_msgsnd, msqid, (struct msgbuf __user *)mb, msgsz, msgflg);
501 asmlinkage long sys32_msgrcv(int msqid,
502 struct msgbuf32 __user *umsgp32,
503 size_t msgsz, long msgtyp, int msgflg)
506 struct msgbuf32 mb32;
509 if ((mb = kmalloc(msgsz + sizeof *mb + 4, GFP_KERNEL)) == NULL)
512 KERNEL_SYSCALL(err, sys_msgrcv, msqid, (struct msgbuf __user *)mb, msgsz, msgtyp, msgflg);
516 mb32.mtype = mb->mtype;
517 err = put_user(mb32.mtype, &umsgp32->mtype);
518 err |= copy_to_user(&umsgp32->mtext, mb->mtext, len);
529 asmlinkage int sys32_sendfile(int out_fd, int in_fd, compat_off_t __user *offset, s32 count)
531 mm_segment_t old_fs = get_fs();
535 if (offset && get_user(of, offset))
539 ret = sys_sendfile(out_fd, in_fd, offset ? (off_t __user *)&of : NULL, count);
542 if (offset && put_user(of, offset))
548 asmlinkage int sys32_sendfile64(int out_fd, int in_fd, compat_loff_t __user *offset, s32 count)
550 mm_segment_t old_fs = get_fs();
554 if (offset && get_user(lof, offset))
558 ret = sys_sendfile64(out_fd, in_fd, offset ? (loff_t __user *)&lof : NULL, count);
561 if (offset && put_user(lof, offset))
577 unsigned short procs;
584 /* We used to call sys_sysinfo and translate the result. But sys_sysinfo
585 * undoes the good work done elsewhere, and rather than undoing the
586 * damage, I decided to just duplicate the code from sys_sysinfo here.
589 asmlinkage int sys32_sysinfo(struct sysinfo32 __user *info)
595 /* We don't need a memset here because we copy the
596 * struct to userspace once element at a time.
600 seq = read_seqbegin(&xtime_lock);
601 val.uptime = jiffies / HZ;
603 val.loads[0] = avenrun[0] << (SI_LOAD_SHIFT - FSHIFT);
604 val.loads[1] = avenrun[1] << (SI_LOAD_SHIFT - FSHIFT);
605 val.loads[2] = avenrun[2] << (SI_LOAD_SHIFT - FSHIFT);
607 val.procs = nr_threads;
608 } while (read_seqretry(&xtime_lock, seq));
614 err = put_user (val.uptime, &info->uptime);
615 err |= __put_user (val.loads[0], &info->loads[0]);
616 err |= __put_user (val.loads[1], &info->loads[1]);
617 err |= __put_user (val.loads[2], &info->loads[2]);
618 err |= __put_user (val.totalram, &info->totalram);
619 err |= __put_user (val.freeram, &info->freeram);
620 err |= __put_user (val.sharedram, &info->sharedram);
621 err |= __put_user (val.bufferram, &info->bufferram);
622 err |= __put_user (val.totalswap, &info->totalswap);
623 err |= __put_user (val.freeswap, &info->freeswap);
624 err |= __put_user (val.procs, &info->procs);
625 err |= __put_user (val.totalhigh, &info->totalhigh);
626 err |= __put_user (val.freehigh, &info->freehigh);
627 err |= __put_user (val.mem_unit, &info->mem_unit);
628 return err ? -EFAULT : 0;
632 /* lseek() needs a wrapper because 'offset' can be negative, but the top
633 * half of the argument has been zeroed by syscall.S.
636 asmlinkage int sys32_lseek(unsigned int fd, int offset, unsigned int origin)
638 return sys_lseek(fd, offset, origin);
641 asmlinkage long sys32_semctl(int semid, int semnum, int cmd, union semun arg)
646 /* Ugh. arg is a union of int,ptr,ptr,ptr, so is 8 bytes.
647 * The int should be in the first 4, but our argument
648 * frobbing has left it in the last 4.
650 u.val = *((int *)&arg + 1);
651 return sys_semctl (semid, semnum, cmd, u);
653 return sys_semctl (semid, semnum, cmd, arg);
656 long sys32_lookup_dcookie(u32 cookie_high, u32 cookie_low, char __user *buf,
659 return sys_lookup_dcookie((u64)cookie_high << 32 | cookie_low,