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/config.h>
13 #include <linux/compat.h>
14 #include <linux/kernel.h>
15 #include <linux/sched.h>
18 #include <linux/file.h>
19 #include <linux/signal.h>
20 #include <linux/resource.h>
21 #include <linux/times.h>
22 #include <linux/utsname.h>
23 #include <linux/time.h>
24 #include <linux/timex.h>
25 #include <linux/smp.h>
26 #include <linux/smp_lock.h>
27 #include <linux/sem.h>
28 #include <linux/msg.h>
29 #include <linux/shm.h>
30 #include <linux/slab.h>
31 #include <linux/uio.h>
32 #include <linux/nfs_fs.h>
33 #include <linux/ncp_fs.h>
34 #include <linux/sunrpc/svc.h>
35 #include <linux/nfsd/nfsd.h>
36 #include <linux/nfsd/cache.h>
37 #include <linux/nfsd/xdr.h>
38 #include <linux/nfsd/syscall.h>
39 #include <linux/poll.h>
40 #include <linux/personality.h>
41 #include <linux/stat.h>
42 #include <linux/highmem.h>
43 #include <linux/highuid.h>
44 #include <linux/mman.h>
45 #include <linux/binfmts.h>
46 #include <linux/namei.h>
47 #include <linux/vfs.h>
48 #include <linux/ptrace.h>
49 #include <linux/swap.h>
50 #include <linux/syscalls.h>
52 #include <asm/types.h>
53 #include <asm/uaccess.h>
54 #include <asm/semaphore.h>
55 #include <asm/mmu_context.h>
62 #define DBG(x) printk x
68 * sys32_execve() executes a new program.
71 asmlinkage int sys32_execve(struct pt_regs *regs)
76 DBG(("sys32_execve(%p) r26 = 0x%lx\n", regs, regs->gr[26]));
77 filename = getname((char *) regs->gr[26]);
78 error = PTR_ERR(filename);
81 error = compat_do_execve(filename, compat_ptr(regs->gr[25]),
82 compat_ptr(regs->gr[24]), regs);
84 current->ptrace &= ~PT_DTRACE;
91 asmlinkage long sys32_unimplemented(int r26, int r25, int r24, int r23,
92 int r22, int r21, int r20)
94 printk(KERN_ERR "%s(%d): Unimplemented 32 on 64 syscall #%d!\n",
95 current->comm, current->pid, r20);
101 struct __sysctl_args32 {
111 asmlinkage long sys32_sysctl(struct __sysctl_args32 *args)
113 struct __sysctl_args32 tmp;
115 unsigned int oldlen32;
116 size_t oldlen, *oldlenp = NULL;
117 unsigned long addr = (((long)&args->__unused[0]) + 7) & ~7;
118 extern int do_sysctl(int *name, int nlen, void *oldval, size_t *oldlenp,
119 void *newval, size_t newlen);
121 DBG(("sysctl32(%p)\n", args));
123 if (copy_from_user(&tmp, args, sizeof(tmp)))
126 if (tmp.oldval && tmp.oldlenp) {
127 /* Duh, this is ugly and might not work if sysctl_args
128 is in read-only memory, but do_sysctl does indirectly
129 a lot of uaccess in both directions and we'd have to
130 basically copy the whole sysctl.c here, and
131 glibc's __sysctl uses rw memory for the structure
133 /* a possibly better hack than this, which will avoid the
134 * problem if the struct is read only, is to push the
135 * 'oldlen' value out to the user's stack instead. -PB
137 if (get_user(oldlen32, (u32 *)(u64)tmp.oldlenp))
140 if (put_user(oldlen, (size_t *)addr))
142 oldlenp = (size_t *)addr;
146 error = do_sysctl((int *)(u64)tmp.name, tmp.nlen, (void *)(u64)tmp.oldval,
147 oldlenp, (void *)(u64)tmp.newval, tmp.newlen);
151 if (get_user(oldlen, (size_t *)addr)) {
155 if (put_user(oldlen32, (u32 *)(u64)tmp.oldlenp))
159 if (copy_to_user(args->__unused, tmp.__unused, sizeof(tmp.__unused)))
165 #else /* CONFIG_SYSCTL */
167 asmlinkage long sys32_sysctl(struct __sysctl_args *args)
171 #endif /* CONFIG_SYSCTL */
173 asmlinkage long sys32_sched_rr_get_interval(pid_t pid,
174 struct compat_timespec *interval)
179 KERNEL_SYSCALL(ret, sys_sched_rr_get_interval, pid, &t);
180 if (put_compat_timespec(&t, interval))
186 put_compat_timeval(struct compat_timeval *u, struct timeval *t)
188 struct compat_timeval t32;
189 t32.tv_sec = t->tv_sec;
190 t32.tv_usec = t->tv_usec;
191 return copy_to_user(u, &t32, sizeof t32);
194 static inline long get_ts32(struct timespec *o, struct compat_timeval *i)
198 if (__get_user(o->tv_sec, &i->tv_sec))
200 if (__get_user(usec, &i->tv_usec))
202 o->tv_nsec = usec * 1000;
206 asmlinkage long sys32_time(compat_time_t *tloc)
211 do_gettimeofday(&tv);
215 if (put_user(now32, tloc))
222 sys32_gettimeofday(struct compat_timeval *tv, struct timezone *tz)
224 extern void do_gettimeofday(struct timeval *tv);
228 do_gettimeofday(&ktv);
229 if (put_compat_timeval(tv, &ktv))
233 extern struct timezone sys_tz;
234 if (copy_to_user(tz, &sys_tz, sizeof(sys_tz)))
241 int sys32_settimeofday(struct compat_timeval *tv, struct timezone *tz)
247 if (get_ts32(&kts, tv))
251 if (copy_from_user(&ktz, tz, sizeof(ktz)))
255 return do_sys_settimeofday(tv ? &kts : NULL, tz ? &ktz : NULL);
258 int cp_compat_stat(struct kstat *stat, struct compat_stat *statbuf)
262 if (stat->size > MAX_NON_LFS || !new_valid_dev(stat->dev) ||
263 !new_valid_dev(stat->rdev))
266 err = put_user(new_encode_dev(stat->dev), &statbuf->st_dev);
267 err |= put_user(stat->ino, &statbuf->st_ino);
268 err |= put_user(stat->mode, &statbuf->st_mode);
269 err |= put_user(stat->nlink, &statbuf->st_nlink);
270 err |= put_user(0, &statbuf->st_reserved1);
271 err |= put_user(0, &statbuf->st_reserved2);
272 err |= put_user(new_encode_dev(stat->rdev), &statbuf->st_rdev);
273 err |= put_user(stat->size, &statbuf->st_size);
274 err |= put_user(stat->atime.tv_sec, &statbuf->st_atime);
275 err |= put_user(stat->atime.tv_nsec, &statbuf->st_atime_nsec);
276 err |= put_user(stat->mtime.tv_sec, &statbuf->st_mtime);
277 err |= put_user(stat->mtime.tv_nsec, &statbuf->st_mtime_nsec);
278 err |= put_user(stat->ctime.tv_sec, &statbuf->st_ctime);
279 err |= put_user(stat->ctime.tv_nsec, &statbuf->st_ctime_nsec);
280 err |= put_user(stat->blksize, &statbuf->st_blksize);
281 err |= put_user(stat->blocks, &statbuf->st_blocks);
282 err |= put_user(0, &statbuf->__unused1);
283 err |= put_user(0, &statbuf->__unused2);
284 err |= put_user(0, &statbuf->__unused3);
285 err |= put_user(0, &statbuf->__unused4);
286 err |= put_user(0, &statbuf->__unused5);
287 err |= put_user(0, &statbuf->st_fstype); /* not avail */
288 err |= put_user(0, &statbuf->st_realdev); /* not avail */
289 err |= put_user(0, &statbuf->st_basemode); /* not avail */
290 err |= put_user(0, &statbuf->st_spareshort);
291 err |= put_user(stat->uid, &statbuf->st_uid);
292 err |= put_user(stat->gid, &statbuf->st_gid);
293 err |= put_user(0, &statbuf->st_spare4[0]);
294 err |= put_user(0, &statbuf->st_spare4[1]);
295 err |= put_user(0, &statbuf->st_spare4[2]);
300 struct linux32_dirent {
307 struct old_linux32_dirent {
314 struct getdents32_callback {
315 struct linux32_dirent * current_dir;
316 struct linux32_dirent * previous;
321 struct readdir32_callback {
322 struct old_linux32_dirent * dirent;
326 #define ROUND_UP(x,a) ((__typeof__(x))(((unsigned long)(x) + ((a) - 1)) & ~((a) - 1)))
327 #define NAME_OFFSET(de) ((int) ((de)->d_name - (char *) (de)))
329 filldir32 (void *__buf, const char *name, int namlen, loff_t offset, ino_t ino,
332 struct linux32_dirent * dirent;
333 struct getdents32_callback * buf = (struct getdents32_callback *) __buf;
334 int reclen = ROUND_UP(NAME_OFFSET(dirent) + namlen + 1, 4);
336 buf->error = -EINVAL; /* only used if we fail.. */
337 if (reclen > buf->count)
339 dirent = buf->previous;
341 put_user(offset, &dirent->d_off);
342 dirent = buf->current_dir;
343 buf->previous = dirent;
344 put_user(ino, &dirent->d_ino);
345 put_user(reclen, &dirent->d_reclen);
346 copy_to_user(dirent->d_name, name, namlen);
347 put_user(0, dirent->d_name + namlen);
348 dirent = (struct linux32_dirent *)((char *)dirent + reclen);
349 buf->current_dir = dirent;
350 buf->count -= reclen;
355 sys32_getdents (unsigned int fd, void * dirent, unsigned int count)
358 struct linux32_dirent * lastdirent;
359 struct getdents32_callback buf;
367 buf.current_dir = (struct linux32_dirent *) dirent;
372 error = vfs_readdir(file, filldir32, &buf);
376 lastdirent = buf.previous;
378 put_user(file->f_pos, &lastdirent->d_off);
379 error = count - buf.count;
389 fillonedir32 (void * __buf, const char * name, int namlen, loff_t offset, ino_t ino,
392 struct readdir32_callback * buf = (struct readdir32_callback *) __buf;
393 struct old_linux32_dirent * dirent;
398 dirent = buf->dirent;
399 put_user(ino, &dirent->d_ino);
400 put_user(offset, &dirent->d_offset);
401 put_user(namlen, &dirent->d_namlen);
402 copy_to_user(dirent->d_name, name, namlen);
403 put_user(0, dirent->d_name + namlen);
408 sys32_readdir (unsigned int fd, void * dirent, unsigned int count)
412 struct readdir32_callback buf;
422 error = vfs_readdir(file, fillonedir32, &buf);
430 /*** copied from mips64 ***/
432 * Ooo, nasty. We need here to frob 32-bit unsigned longs to
433 * 64-bit unsigned longs.
437 get_fd_set32(unsigned long n, u32 *ufdset, unsigned long *fdset)
439 n = (n + 8*sizeof(u32) - 1) / (8*sizeof(u32));
443 if (verify_area(VERIFY_WRITE, ufdset, n*sizeof(u32)))
450 __get_user(l, ufdset);
451 __get_user(h, ufdset+1);
453 *fdset++ = h << 32 | l;
457 __get_user(*fdset, ufdset);
459 /* Tricky, must clear full unsigned long in the
460 * kernel fdset at the end, this makes sure that
463 memset(fdset, 0, ((n + 1) & ~1)*sizeof(u32));
469 set_fd_set32(unsigned long n, u32 *ufdset, unsigned long *fdset)
472 n = (n + 8*sizeof(u32) - 1) / (8*sizeof(u32));
483 __put_user(l, ufdset);
484 __put_user(h, ufdset+1);
489 __put_user(*fdset, ufdset);
497 asmlinkage long sys32_msgsnd(int msqid,
498 struct msgbuf32 *umsgp32,
499 size_t msgsz, int msgflg)
502 struct msgbuf32 mb32;
505 if ((mb = kmalloc(msgsz + sizeof *mb + 4, GFP_KERNEL)) == NULL)
508 err = get_user(mb32.mtype, &umsgp32->mtype);
509 mb->mtype = mb32.mtype;
510 err |= copy_from_user(mb->mtext, &umsgp32->mtext, msgsz);
515 KERNEL_SYSCALL(err, sys_msgsnd, msqid, mb, msgsz, msgflg);
521 asmlinkage long sys32_msgrcv(int msqid,
522 struct msgbuf32 *umsgp32,
523 size_t msgsz, long msgtyp, int msgflg)
526 struct msgbuf32 mb32;
529 if ((mb = kmalloc(msgsz + sizeof *mb + 4, GFP_KERNEL)) == NULL)
532 KERNEL_SYSCALL(err, sys_msgrcv, msqid, mb, msgsz, msgtyp, msgflg);
536 mb32.mtype = mb->mtype;
537 err = put_user(mb32.mtype, &umsgp32->mtype);
538 err |= copy_to_user(&umsgp32->mtext, mb->mtext, len);
549 asmlinkage int sys32_sendfile(int out_fd, int in_fd, compat_off_t *offset, s32 count)
551 mm_segment_t old_fs = get_fs();
555 if (offset && get_user(of, offset))
559 ret = sys_sendfile(out_fd, in_fd, offset ? &of : NULL, count);
562 if (offset && put_user(of, offset))
568 typedef long __kernel_loff_t32; /* move this to asm/posix_types.h? */
570 asmlinkage int sys32_sendfile64(int out_fd, int in_fd, __kernel_loff_t32 *offset, s32 count)
572 mm_segment_t old_fs = get_fs();
576 if (offset && get_user(lof, offset))
580 ret = sys_sendfile64(out_fd, in_fd, offset ? &lof : NULL, count);
583 if (offset && put_user(lof, offset))
591 unsigned int modes; /* mode selector */
592 int offset; /* time offset (usec) */
593 int freq; /* frequency offset (scaled ppm) */
594 int maxerror; /* maximum error (usec) */
595 int esterror; /* estimated error (usec) */
596 int status; /* clock command/status */
597 int constant; /* pll time constant */
598 int precision; /* clock precision (usec) (read only) */
599 int tolerance; /* clock frequency tolerance (ppm)
602 struct compat_timeval time; /* (read only) */
603 int tick; /* (modified) usecs between clock ticks */
605 int ppsfreq; /* pps frequency (scaled ppm) (ro) */
606 int jitter; /* pps jitter (us) (ro) */
607 int shift; /* interval duration (s) (shift) (ro) */
608 int stabil; /* pps stability (scaled ppm) (ro) */
609 int jitcnt; /* jitter limit exceeded (ro) */
610 int calcnt; /* calibration intervals (ro) */
611 int errcnt; /* calibration errors (ro) */
612 int stbcnt; /* stability limit exceeded (ro) */
614 int :32; int :32; int :32; int :32;
615 int :32; int :32; int :32; int :32;
616 int :32; int :32; int :32; int :32;
619 asmlinkage long sys32_adjtimex(struct timex32 *txc_p32)
624 extern int do_adjtimex(struct timex *txc);
626 if(copy_from_user(&t32, txc_p32, sizeof(struct timex32)))
629 #define CP(x) txc.x = t32.x
630 CP(modes); CP(offset); CP(freq); CP(maxerror); CP(esterror);
631 CP(status); CP(constant); CP(precision); CP(tolerance);
632 CP(time.tv_sec); CP(time.tv_usec); CP(tick); CP(ppsfreq); CP(jitter);
633 CP(shift); CP(stabil); CP(jitcnt); CP(calcnt); CP(errcnt);
635 ret = do_adjtimex(&txc);
637 #define CP(x) t32.x = txc.x
638 CP(modes); CP(offset); CP(freq); CP(maxerror); CP(esterror);
639 CP(status); CP(constant); CP(precision); CP(tolerance);
640 CP(time.tv_sec); CP(time.tv_usec); CP(tick); CP(ppsfreq); CP(jitter);
641 CP(shift); CP(stabil); CP(jitcnt); CP(calcnt); CP(errcnt);
643 return copy_to_user(txc_p32, &t32, sizeof(struct timex32)) ? -EFAULT : ret;
656 unsigned short procs;
663 /* We used to call sys_sysinfo and translate the result. But sys_sysinfo
664 * undoes the good work done elsewhere, and rather than undoing the
665 * damage, I decided to just duplicate the code from sys_sysinfo here.
668 asmlinkage int sys32_sysinfo(struct sysinfo32 *info)
674 /* We don't need a memset here because we copy the
675 * struct to userspace once element at a time.
679 seq = read_seqbegin(&xtime_lock);
680 /* requires vx virtualization */
681 val.uptime = jiffies / HZ;
683 val.loads[0] = avenrun[0] << (SI_LOAD_SHIFT - FSHIFT);
684 val.loads[1] = avenrun[1] << (SI_LOAD_SHIFT - FSHIFT);
685 val.loads[2] = avenrun[2] << (SI_LOAD_SHIFT - FSHIFT);
687 val.procs = nr_threads;
688 } while (read_seqretry(&xtime_lock, seq));
694 err = put_user (val.uptime, &info->uptime);
695 err |= __put_user (val.loads[0], &info->loads[0]);
696 err |= __put_user (val.loads[1], &info->loads[1]);
697 err |= __put_user (val.loads[2], &info->loads[2]);
698 err |= __put_user (val.totalram, &info->totalram);
699 err |= __put_user (val.freeram, &info->freeram);
700 err |= __put_user (val.sharedram, &info->sharedram);
701 err |= __put_user (val.bufferram, &info->bufferram);
702 err |= __put_user (val.totalswap, &info->totalswap);
703 err |= __put_user (val.freeswap, &info->freeswap);
704 err |= __put_user (val.procs, &info->procs);
705 err |= __put_user (val.totalhigh, &info->totalhigh);
706 err |= __put_user (val.freehigh, &info->freehigh);
707 err |= __put_user (val.mem_unit, &info->mem_unit);
708 return err ? -EFAULT : 0;
712 /* lseek() needs a wrapper because 'offset' can be negative, but the top
713 * half of the argument has been zeroed by syscall.S.
716 asmlinkage int sys32_lseek(unsigned int fd, int offset, unsigned int origin)
718 return sys_lseek(fd, offset, origin);
721 asmlinkage long sys32_semctl(int semid, int semnum, int cmd, union semun arg)
726 /* Ugh. arg is a union of int,ptr,ptr,ptr, so is 8 bytes.
727 * The int should be in the first 4, but our argument
728 * frobbing has left it in the last 4.
730 u.val = *((int *)&arg + 1);
731 return sys_semctl (semid, semnum, cmd, u);
733 return sys_semctl (semid, semnum, cmd, arg);
736 long sys32_lookup_dcookie(u32 cookie_high, u32 cookie_low, char *buf,
739 return sys_lookup_dcookie((u64)cookie_high << 32 | cookie_low,