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 * count32() counts the number of arguments/envelopes. It is basically
69 * a copy of count() from fs/exec.c, except that it works
70 * with 32 bit argv and envp pointers.
73 static int count32(u32 *argv, int max)
82 error = get_user(p,argv);
97 * copy_strings32() is basically a copy of copy_strings() from fs/exec.c
98 * except that it works with 32 bit argv and envp pointers.
102 static int copy_strings32(int argc, u32 *argv, struct linux_binprm *bprm)
109 if (get_user(str, argv + argc) ||
111 !(len = strnlen_user((char *)compat_ptr(str), bprm->p)))
124 int offset, bytes_to_copy;
126 offset = pos % PAGE_SIZE;
128 page = bprm->page[i];
131 page = alloc_page(GFP_HIGHUSER);
132 bprm->page[i] = page;
137 kaddr = (char *)kmap(page);
140 memset(kaddr, 0, offset);
141 bytes_to_copy = PAGE_SIZE - offset;
142 if (bytes_to_copy > len) {
145 memset(kaddr+offset+len, 0, PAGE_SIZE-offset-len);
147 err = copy_from_user(kaddr + offset, (char *)compat_ptr(str), bytes_to_copy);
148 flush_dcache_page(page);
154 pos += bytes_to_copy;
155 str += bytes_to_copy;
156 len -= bytes_to_copy;
163 * do_execve32() is mostly a copy of do_execve(), with the exception
164 * that it processes 32 bit argv and envp pointers.
168 do_execve32(char * filename, u32 * argv, u32 * envp, struct pt_regs * regs)
170 struct linux_binprm bprm;
175 file = open_exec(filename);
177 retval = PTR_ERR(file);
181 bprm.p = PAGE_SIZE*MAX_ARG_PAGES-sizeof(void *);
182 memset(bprm.page, 0, MAX_ARG_PAGES*sizeof(bprm.page[0]));
184 DBG(("do_execve32(%s, %p, %p, %p)\n", filename, argv, envp, regs));
187 bprm.filename = filename;
188 bprm.interp = filename;
193 bprm.mm = mm_alloc();
198 retval = init_new_context(current, bprm.mm);
202 if ((bprm.argc = count32(argv, bprm.p / sizeof(u32))) < 0)
205 if ((bprm.envc = count32(envp, bprm.p / sizeof(u32))) < 0)
208 retval = prepare_binprm(&bprm);
212 retval = copy_strings_kernel(1, &bprm.filename, &bprm);
217 retval = copy_strings32(bprm.envc, envp, &bprm);
221 retval = copy_strings32(bprm.argc, argv, &bprm);
225 retval = search_binary_handler(&bprm,regs);
231 /* Something went wrong, return the inode and free the argument pages*/
232 for (i = 0; i < MAX_ARG_PAGES; i++) {
233 struct page *page = bprm.page[i];
243 allow_write_access(bprm.file);
251 * sys32_execve() executes a new program.
254 asmlinkage int sys32_execve(struct pt_regs *regs)
259 DBG(("sys32_execve(%p) r26 = 0x%lx\n", regs, regs->gr[26]));
260 filename = getname((char *) regs->gr[26]);
261 error = PTR_ERR(filename);
262 if (IS_ERR(filename))
264 error = do_execve32(filename, (u32 *) regs->gr[25],
265 (u32 *) regs->gr[24], regs);
267 current->ptrace &= ~PT_DTRACE;
274 asmlinkage long sys32_unimplemented(int r26, int r25, int r24, int r23,
275 int r22, int r21, int r20)
277 printk(KERN_ERR "%s(%d): Unimplemented 32 on 64 syscall #%d!\n",
278 current->comm, current->pid, r20);
284 struct __sysctl_args32 {
294 asmlinkage long sys32_sysctl(struct __sysctl_args32 *args)
296 struct __sysctl_args32 tmp;
298 unsigned int oldlen32;
299 size_t oldlen, *oldlenp = NULL;
300 unsigned long addr = (((long)&args->__unused[0]) + 7) & ~7;
301 extern int do_sysctl(int *name, int nlen, void *oldval, size_t *oldlenp,
302 void *newval, size_t newlen);
304 DBG(("sysctl32(%p)\n", args));
306 if (copy_from_user(&tmp, args, sizeof(tmp)))
309 if (tmp.oldval && tmp.oldlenp) {
310 /* Duh, this is ugly and might not work if sysctl_args
311 is in read-only memory, but do_sysctl does indirectly
312 a lot of uaccess in both directions and we'd have to
313 basically copy the whole sysctl.c here, and
314 glibc's __sysctl uses rw memory for the structure
316 /* a possibly better hack than this, which will avoid the
317 * problem if the struct is read only, is to push the
318 * 'oldlen' value out to the user's stack instead. -PB
320 if (get_user(oldlen32, (u32 *)(u64)tmp.oldlenp))
323 if (put_user(oldlen, (size_t *)addr))
325 oldlenp = (size_t *)addr;
329 error = do_sysctl((int *)(u64)tmp.name, tmp.nlen, (void *)(u64)tmp.oldval,
330 oldlenp, (void *)(u64)tmp.newval, tmp.newlen);
334 if (get_user(oldlen, (size_t *)addr)) {
338 if (put_user(oldlen32, (u32 *)(u64)tmp.oldlenp))
342 if (copy_to_user(args->__unused, tmp.__unused, sizeof(tmp.__unused)))
348 #else /* CONFIG_SYSCTL */
350 asmlinkage long sys32_sysctl(struct __sysctl_args *args)
354 #endif /* CONFIG_SYSCTL */
356 asmlinkage long sys32_sched_rr_get_interval(pid_t pid,
357 struct compat_timespec *interval)
362 KERNEL_SYSCALL(ret, sys_sched_rr_get_interval, pid, &t);
363 if (put_compat_timespec(&t, interval))
369 put_compat_timeval(struct compat_timeval *u, struct timeval *t)
371 struct compat_timeval t32;
372 t32.tv_sec = t->tv_sec;
373 t32.tv_usec = t->tv_usec;
374 return copy_to_user(u, &t32, sizeof t32);
377 static inline long get_ts32(struct timespec *o, struct compat_timeval *i)
381 if (__get_user(o->tv_sec, &i->tv_sec))
383 if (__get_user(usec, &i->tv_usec))
385 o->tv_nsec = usec * 1000;
389 asmlinkage long sys32_time(compat_time_t *tloc)
393 do_gettimeofday(&tv);
394 compat_time_t now32 = tv.tv_sec;
397 if (put_user(now32, tloc))
404 sys32_gettimeofday(struct compat_timeval *tv, struct timezone *tz)
406 extern void do_gettimeofday(struct timeval *tv);
410 do_gettimeofday(&ktv);
411 if (put_compat_timeval(tv, &ktv))
415 extern struct timezone sys_tz;
416 if (copy_to_user(tz, &sys_tz, sizeof(sys_tz)))
423 int sys32_settimeofday(struct compat_timeval *tv, struct timezone *tz)
429 if (get_ts32(&kts, tv))
433 if (copy_from_user(&ktz, tz, sizeof(ktz)))
437 return do_sys_settimeofday(tv ? &kts : NULL, tz ? &ktz : NULL);
440 int cp_compat_stat(struct kstat *stat, struct compat_stat *statbuf)
444 if (stat->size > MAX_NON_LFS || !new_valid_dev(stat->dev) ||
445 !new_valid_dev(stat->rdev))
448 err = put_user(new_encode_dev(stat->dev), &statbuf->st_dev);
449 err |= put_user(stat->ino, &statbuf->st_ino);
450 err |= put_user(stat->mode, &statbuf->st_mode);
451 err |= put_user(stat->nlink, &statbuf->st_nlink);
452 err |= put_user(0, &statbuf->st_reserved1);
453 err |= put_user(0, &statbuf->st_reserved2);
454 err |= put_user(new_encode_dev(stat->rdev), &statbuf->st_rdev);
455 err |= put_user(stat->size, &statbuf->st_size);
456 err |= put_user(stat->atime.tv_sec, &statbuf->st_atime);
457 err |= put_user(stat->atime.tv_nsec, &statbuf->st_atime_nsec);
458 err |= put_user(stat->mtime.tv_sec, &statbuf->st_mtime);
459 err |= put_user(stat->mtime.tv_nsec, &statbuf->st_mtime_nsec);
460 err |= put_user(stat->ctime.tv_sec, &statbuf->st_ctime);
461 err |= put_user(stat->ctime.tv_nsec, &statbuf->st_ctime_nsec);
462 err |= put_user(stat->blksize, &statbuf->st_blksize);
463 err |= put_user(stat->blocks, &statbuf->st_blocks);
464 err |= put_user(0, &statbuf->__unused1);
465 err |= put_user(0, &statbuf->__unused2);
466 err |= put_user(0, &statbuf->__unused3);
467 err |= put_user(0, &statbuf->__unused4);
468 err |= put_user(0, &statbuf->__unused5);
469 err |= put_user(0, &statbuf->st_fstype); /* not avail */
470 err |= put_user(0, &statbuf->st_realdev); /* not avail */
471 err |= put_user(0, &statbuf->st_basemode); /* not avail */
472 err |= put_user(0, &statbuf->st_spareshort);
473 err |= put_user(stat->uid, &statbuf->st_uid);
474 err |= put_user(stat->gid, &statbuf->st_gid);
475 err |= put_user(0, &statbuf->st_spare4[0]);
476 err |= put_user(0, &statbuf->st_spare4[1]);
477 err |= put_user(0, &statbuf->st_spare4[2]);
482 struct linux32_dirent {
489 struct old_linux32_dirent {
496 struct getdents32_callback {
497 struct linux32_dirent * current_dir;
498 struct linux32_dirent * previous;
503 struct readdir32_callback {
504 struct old_linux32_dirent * dirent;
508 #define ROUND_UP(x,a) ((__typeof__(x))(((unsigned long)(x) + ((a) - 1)) & ~((a) - 1)))
509 #define NAME_OFFSET(de) ((int) ((de)->d_name - (char *) (de)))
511 filldir32 (void *__buf, const char *name, int namlen, loff_t offset, ino_t ino,
514 struct linux32_dirent * dirent;
515 struct getdents32_callback * buf = (struct getdents32_callback *) __buf;
516 int reclen = ROUND_UP(NAME_OFFSET(dirent) + namlen + 1, 4);
518 buf->error = -EINVAL; /* only used if we fail.. */
519 if (reclen > buf->count)
521 dirent = buf->previous;
523 put_user(offset, &dirent->d_off);
524 dirent = buf->current_dir;
525 buf->previous = dirent;
526 put_user(ino, &dirent->d_ino);
527 put_user(reclen, &dirent->d_reclen);
528 copy_to_user(dirent->d_name, name, namlen);
529 put_user(0, dirent->d_name + namlen);
530 ((char *) dirent) += reclen;
531 buf->current_dir = dirent;
532 buf->count -= reclen;
537 sys32_getdents (unsigned int fd, void * dirent, unsigned int count)
540 struct linux32_dirent * lastdirent;
541 struct getdents32_callback buf;
549 buf.current_dir = (struct linux32_dirent *) dirent;
554 error = vfs_readdir(file, filldir32, &buf);
558 lastdirent = buf.previous;
560 put_user(file->f_pos, &lastdirent->d_off);
561 error = count - buf.count;
571 fillonedir32 (void * __buf, const char * name, int namlen, loff_t offset, ino_t ino,
574 struct readdir32_callback * buf = (struct readdir32_callback *) __buf;
575 struct old_linux32_dirent * dirent;
580 dirent = buf->dirent;
581 put_user(ino, &dirent->d_ino);
582 put_user(offset, &dirent->d_offset);
583 put_user(namlen, &dirent->d_namlen);
584 copy_to_user(dirent->d_name, name, namlen);
585 put_user(0, dirent->d_name + namlen);
590 sys32_readdir (unsigned int fd, void * dirent, unsigned int count)
594 struct readdir32_callback buf;
604 error = vfs_readdir(file, fillonedir32, &buf);
612 /* readv/writev stolen from mips64 */
613 typedef ssize_t (*IO_fn_t)(struct file *, char *, size_t, loff_t *);
616 do_readv_writev32(int type, struct file *file, const struct compat_iovec *vector,
619 unsigned long tot_len;
620 struct iovec iovstack[UIO_FASTIOV];
621 struct iovec *iov=iovstack, *ivp;
626 /* First get the "struct iovec" from user memory and
627 * verify all the pointers
631 if(verify_area(VERIFY_READ, vector, sizeof(struct compat_iovec)*count))
633 if (count > UIO_MAXIOV)
635 if (count > UIO_FASTIOV) {
636 iov = kmalloc(count*sizeof(struct iovec), GFP_KERNEL);
648 __get_user(len, &vector->iov_len);
649 __get_user(buf, &vector->iov_base);
651 ivp->iov_base = compat_ptr(buf);
652 ivp->iov_len = (compat_size_t) len;
658 inode = file->f_dentry->d_inode;
659 /* VERIFY_WRITE actually means a read, as we write to user space */
660 retval = locks_verify_area((type == VERIFY_WRITE
661 ? FLOCK_VERIFY_READ : FLOCK_VERIFY_WRITE),
662 inode, file, file->f_pos, tot_len);
669 /* Then do the actual IO. Note that sockets need to be handled
670 * specially as they have atomicity guarantees and can handle
675 err = sock_readv_writev(type, inode, file, iov, count, tot_len);
686 /* VERIFY_WRITE actually means a read, as we write to user space */
687 fn = file->f_op->read;
688 if (type == VERIFY_READ)
689 fn = (IO_fn_t) file->f_op->write;
695 base = ivp->iov_base;
699 nr = fn(file, base, len, &file->f_pos);
717 sys32_readv(int fd, struct compat_iovec *vector, u32 count)
726 if (file->f_op && (file->f_mode & FMODE_READ) &&
727 (file->f_op->readv || file->f_op->read))
728 ret = do_readv_writev32(VERIFY_WRITE, file, vector, count);
737 sys32_writev(int fd, struct compat_iovec *vector, u32 count)
746 if (file->f_op && (file->f_mode & FMODE_WRITE) &&
747 (file->f_op->writev || file->f_op->write))
748 ret = do_readv_writev32(VERIFY_READ, file, vector, count);
755 /*** copied from mips64 ***/
757 * Ooo, nasty. We need here to frob 32-bit unsigned longs to
758 * 64-bit unsigned longs.
762 get_fd_set32(unsigned long n, u32 *ufdset, unsigned long *fdset)
764 n = (n + 8*sizeof(u32) - 1) / (8*sizeof(u32));
768 if (verify_area(VERIFY_WRITE, ufdset, n*sizeof(u32)))
775 __get_user(l, ufdset);
776 __get_user(h, ufdset+1);
778 *fdset++ = h << 32 | l;
782 __get_user(*fdset, ufdset);
784 /* Tricky, must clear full unsigned long in the
785 * kernel fdset at the end, this makes sure that
788 memset(fdset, 0, ((n + 1) & ~1)*sizeof(u32));
794 set_fd_set32(unsigned long n, u32 *ufdset, unsigned long *fdset)
797 n = (n + 8*sizeof(u32) - 1) / (8*sizeof(u32));
808 __put_user(l, ufdset);
809 __put_user(h, ufdset+1);
814 __put_user(*fdset, ufdset);
817 /*** This is a virtual copy of sys_select from fs/select.c and probably
818 *** should be compared to it from time to time
820 static inline void *select_bits_alloc(int size)
822 return kmalloc(6 * size, GFP_KERNEL);
825 static inline void select_bits_free(void *bits, int size)
831 * We can actually return ERESTARTSYS instead of EINTR, but I'd
832 * like to be certain this leads to no problems. So I return
833 * EINTR just for safety.
835 * Update: ERESTARTSYS breaks at least the xview clock binary, so
836 * I'm trying ERESTARTNOHAND which restart only when you want to.
838 #define MAX_SELECT_SECONDS \
839 ((unsigned long) (MAX_SCHEDULE_TIMEOUT / HZ)-1)
840 #define DIVIDE_ROUND_UP(x,y) (((x)+(y)-1)/(y))
843 sys32_select(int n, u32 *inp, u32 *outp, u32 *exp, struct compat_timeval *tvp)
850 timeout = MAX_SCHEDULE_TIMEOUT;
852 struct compat_timeval tv32;
855 if ((ret = copy_from_user(&tv32, tvp, sizeof tv32)))
862 if (sec < 0 || usec < 0)
865 if ((unsigned long) sec < MAX_SELECT_SECONDS) {
866 timeout = DIVIDE_ROUND_UP(usec, 1000000/HZ);
867 timeout += sec * (unsigned long) HZ;
875 if (n > current->files->max_fdset)
876 n = current->files->max_fdset;
879 * We need 6 bitmaps (in/out/ex for both incoming and outgoing),
880 * since we used fdset we need to allocate memory in units of
885 bits = select_bits_alloc(size);
888 fds.in = (unsigned long *) bits;
889 fds.out = (unsigned long *) (bits + size);
890 fds.ex = (unsigned long *) (bits + 2*size);
891 fds.res_in = (unsigned long *) (bits + 3*size);
892 fds.res_out = (unsigned long *) (bits + 4*size);
893 fds.res_ex = (unsigned long *) (bits + 5*size);
895 if ((ret = get_fd_set32(n, inp, fds.in)) ||
896 (ret = get_fd_set32(n, outp, fds.out)) ||
897 (ret = get_fd_set32(n, exp, fds.ex)))
899 zero_fd_set(n, fds.res_in);
900 zero_fd_set(n, fds.res_out);
901 zero_fd_set(n, fds.res_ex);
903 ret = do_select(n, &fds, &timeout);
905 if (tvp && !(current->personality & STICKY_TIMEOUTS)) {
906 time_t sec = 0, usec = 0;
910 usec *= (1000000/HZ);
912 err = put_user(sec, &tvp->tv_sec);
913 err |= __put_user(usec, &tvp->tv_usec);
921 ret = -ERESTARTNOHAND;
922 if (signal_pending(current))
927 set_fd_set32(n, inp, fds.res_in);
928 set_fd_set32(n, outp, fds.res_out);
929 set_fd_set32(n, exp, fds.res_ex);
932 select_bits_free(bits, size);
942 asmlinkage long sys32_msgsnd(int msqid,
943 struct msgbuf32 *umsgp32,
944 size_t msgsz, int msgflg)
947 struct msgbuf32 mb32;
950 if ((mb = kmalloc(msgsz + sizeof *mb + 4, GFP_KERNEL)) == NULL)
953 err = get_user(mb32.mtype, &umsgp32->mtype);
954 mb->mtype = mb32.mtype;
955 err |= copy_from_user(mb->mtext, &umsgp32->mtext, msgsz);
960 KERNEL_SYSCALL(err, sys_msgsnd, msqid, mb, msgsz, msgflg);
966 asmlinkage long sys32_msgrcv(int msqid,
967 struct msgbuf32 *umsgp32,
968 size_t msgsz, long msgtyp, int msgflg)
971 struct msgbuf32 mb32;
974 if ((mb = kmalloc(msgsz + sizeof *mb + 4, GFP_KERNEL)) == NULL)
977 KERNEL_SYSCALL(err, sys_msgrcv, msqid, mb, msgsz, msgtyp, msgflg);
981 mb32.mtype = mb->mtype;
982 err = put_user(mb32.mtype, &umsgp32->mtype);
983 err |= copy_to_user(&umsgp32->mtext, mb->mtext, len);
995 asmlinkage int sys32_sendfile(int out_fd, int in_fd, compat_off_t *offset, s32 count)
997 mm_segment_t old_fs = get_fs();
1001 if (offset && get_user(of, offset))
1005 ret = sys_sendfile(out_fd, in_fd, offset ? &of : NULL, count);
1008 if (offset && put_user(of, offset))
1014 /* EXPORT/UNEXPORT */
1015 struct nfsctl_export32 {
1016 char ex_client[NFSCLNT_IDMAX+1];
1017 char ex_path[NFS_MAXPATHLEN+1];
1018 __kernel_old_dev_t ex_dev;
1019 compat_ino_t ex_ino;
1021 __kernel_uid_t ex_anon_uid;
1022 __kernel_gid_t ex_anon_gid;
1025 struct nfsctl_arg32 {
1026 int ca_version; /* safeguard */
1027 /* wide kernel places this union on 8-byte boundary, narrow on 4 */
1029 struct nfsctl_svc u_svc;
1030 struct nfsctl_client u_client;
1031 struct nfsctl_export32 u_export;
1032 struct nfsctl_fdparm u_getfd;
1033 struct nfsctl_fsparm u_getfs;
1037 asmlinkage int sys32_nfsservctl(int cmd, void *argp, void *resp)
1040 struct nfsctl_arg32 n32;
1041 struct nfsctl_arg n;
1043 ret = copy_from_user(&n, argp, sizeof n.ca_version);
1047 /* adjust argp to point at the union inside the user's n32 struct */
1048 tmp = (unsigned long)&n32.u - (unsigned long)&n32;
1049 argp = (void *)((unsigned long)argp + tmp);
1052 ret = copy_from_user(&n.u, argp, sizeof n.u.u_svc);
1055 case NFSCTL_ADDCLIENT:
1056 case NFSCTL_DELCLIENT:
1057 ret = copy_from_user(&n.u, argp, sizeof n.u.u_client);
1061 ret = copy_from_user(&n.u, argp, sizeof n.u.u_getfd);
1065 ret = copy_from_user(&n.u, argp, sizeof n.u.u_getfs);
1068 case NFSCTL_UNEXPORT: /* nfsctl_export */
1069 case NFSCTL_EXPORT: /* nfsctl_export */
1070 ret = copy_from_user(&n32.u, argp, sizeof n32.u.u_export);
1072 #define CP(x) n.u.u_export.ex_##x = n32.u.u_export.ex_##x
1073 memcpy(n.u.u_export.ex_client, n32.u.u_export.ex_client, sizeof n32.u.u_export.ex_client);
1074 memcpy(n.u.u_export.ex_path, n32.u.u_export.ex_path, sizeof n32.u.u_export.ex_path);
1083 /* lockd probes for some other values (0x10000);
1090 unsigned char rbuf[NFS_FHSIZE + sizeof (struct knfsd_fh)];
1091 KERNEL_SYSCALL(ret, sys_nfsservctl, cmd, &n, &rbuf);
1092 if (cmd == NFSCTL_GETFD) {
1093 ret = copy_to_user(resp, rbuf, NFS_FHSIZE);
1094 } else if (cmd == NFSCTL_GETFS) {
1095 ret = copy_to_user(resp, rbuf, sizeof (struct knfsd_fh));
1102 typedef long __kernel_loff_t32; /* move this to asm/posix_types.h? */
1104 asmlinkage int sys32_sendfile64(int out_fd, int in_fd, __kernel_loff_t32 *offset, s32 count)
1106 mm_segment_t old_fs = get_fs();
1110 if (offset && get_user(lof, offset))
1114 ret = sys_sendfile64(out_fd, in_fd, offset ? &lof : NULL, count);
1117 if (offset && put_user(lof, offset))
1125 unsigned int modes; /* mode selector */
1126 int offset; /* time offset (usec) */
1127 int freq; /* frequency offset (scaled ppm) */
1128 int maxerror; /* maximum error (usec) */
1129 int esterror; /* estimated error (usec) */
1130 int status; /* clock command/status */
1131 int constant; /* pll time constant */
1132 int precision; /* clock precision (usec) (read only) */
1133 int tolerance; /* clock frequency tolerance (ppm)
1136 struct compat_timeval time; /* (read only) */
1137 int tick; /* (modified) usecs between clock ticks */
1139 int ppsfreq; /* pps frequency (scaled ppm) (ro) */
1140 int jitter; /* pps jitter (us) (ro) */
1141 int shift; /* interval duration (s) (shift) (ro) */
1142 int stabil; /* pps stability (scaled ppm) (ro) */
1143 int jitcnt; /* jitter limit exceeded (ro) */
1144 int calcnt; /* calibration intervals (ro) */
1145 int errcnt; /* calibration errors (ro) */
1146 int stbcnt; /* stability limit exceeded (ro) */
1148 int :32; int :32; int :32; int :32;
1149 int :32; int :32; int :32; int :32;
1150 int :32; int :32; int :32; int :32;
1153 asmlinkage long sys32_adjtimex(struct timex32 *txc_p32)
1158 extern int do_adjtimex(struct timex *txc);
1160 if(copy_from_user(&t32, txc_p32, sizeof(struct timex32)))
1163 #define CP(x) txc.x = t32.x
1164 CP(modes); CP(offset); CP(freq); CP(maxerror); CP(esterror);
1165 CP(status); CP(constant); CP(precision); CP(tolerance);
1166 CP(time.tv_sec); CP(time.tv_usec); CP(tick); CP(ppsfreq); CP(jitter);
1167 CP(shift); CP(stabil); CP(jitcnt); CP(calcnt); CP(errcnt);
1169 ret = do_adjtimex(&txc);
1171 #define CP(x) t32.x = txc.x
1172 CP(modes); CP(offset); CP(freq); CP(maxerror); CP(esterror);
1173 CP(status); CP(constant); CP(precision); CP(tolerance);
1174 CP(time.tv_sec); CP(time.tv_usec); CP(tick); CP(ppsfreq); CP(jitter);
1175 CP(shift); CP(stabil); CP(jitcnt); CP(calcnt); CP(errcnt);
1177 return copy_to_user(txc_p32, &t32, sizeof(struct timex32)) ? -EFAULT : ret;
1190 unsigned short procs;
1197 /* We used to call sys_sysinfo and translate the result. But sys_sysinfo
1198 * undoes the good work done elsewhere, and rather than undoing the
1199 * damage, I decided to just duplicate the code from sys_sysinfo here.
1202 asmlinkage int sys32_sysinfo(struct sysinfo32 *info)
1208 /* We don't need a memset here because we copy the
1209 * struct to userspace once element at a time.
1213 seq = read_seqbegin(&xtime_lock);
1214 val.uptime = jiffies / HZ;
1216 val.loads[0] = avenrun[0] << (SI_LOAD_SHIFT - FSHIFT);
1217 val.loads[1] = avenrun[1] << (SI_LOAD_SHIFT - FSHIFT);
1218 val.loads[2] = avenrun[2] << (SI_LOAD_SHIFT - FSHIFT);
1220 val.procs = nr_threads;
1221 } while (read_seqretry(&xtime_lock, seq));
1227 err = put_user (val.uptime, &info->uptime);
1228 err |= __put_user (val.loads[0], &info->loads[0]);
1229 err |= __put_user (val.loads[1], &info->loads[1]);
1230 err |= __put_user (val.loads[2], &info->loads[2]);
1231 err |= __put_user (val.totalram, &info->totalram);
1232 err |= __put_user (val.freeram, &info->freeram);
1233 err |= __put_user (val.sharedram, &info->sharedram);
1234 err |= __put_user (val.bufferram, &info->bufferram);
1235 err |= __put_user (val.totalswap, &info->totalswap);
1236 err |= __put_user (val.freeswap, &info->freeswap);
1237 err |= __put_user (val.procs, &info->procs);
1238 err |= __put_user (val.totalhigh, &info->totalhigh);
1239 err |= __put_user (val.freehigh, &info->freehigh);
1240 err |= __put_user (val.mem_unit, &info->mem_unit);
1241 return err ? -EFAULT : 0;
1245 /* lseek() needs a wrapper because 'offset' can be negative, but the top
1246 * half of the argument has been zeroed by syscall.S.
1249 asmlinkage int sys32_lseek(unsigned int fd, int offset, unsigned int origin)
1251 return sys_lseek(fd, offset, origin);
1254 asmlinkage long sys32_semctl(int semid, int semnum, int cmd, union semun arg)
1258 if (cmd == SETVAL) {
1259 /* Ugh. arg is a union of int,ptr,ptr,ptr, so is 8 bytes.
1260 * The int should be in the first 4, but our argument
1261 * frobbing has left it in the last 4.
1263 u.val = *((int *)&arg + 1);
1264 return sys_semctl (semid, semnum, cmd, u);
1266 return sys_semctl (semid, semnum, cmd, arg);
1269 long sys32_lookup_dcookie(u32 cookie_high, u32 cookie_low, char *buf,
1272 return sys_lookup_dcookie((u64)cookie_high << 32 | cookie_low,