2 * sys_ppc32.c: Conversion between 32bit and 64bit native syscalls.
4 * Copyright (C) 2001 IBM
5 * Copyright (C) 1997,1998 Jakub Jelinek (jj@sunsite.mff.cuni.cz)
6 * Copyright (C) 1997 David S. Miller (davem@caip.rutgers.edu)
8 * These routines maintain argument size conversion between 32bit and 64bit
11 * This program is free software; you can redistribute it and/or
12 * modify it under the terms of the GNU General Public License
13 * as published by the Free Software Foundation; either version
14 * 2 of the License, or (at your option) any later version.
17 #include <linux/config.h>
18 #include <linux/kernel.h>
19 #include <linux/sched.h>
22 #include <linux/file.h>
23 #include <linux/signal.h>
24 #include <linux/resource.h>
25 #include <linux/times.h>
26 #include <linux/utsname.h>
27 #include <linux/timex.h>
28 #include <linux/smp.h>
29 #include <linux/smp_lock.h>
30 #include <linux/sem.h>
31 #include <linux/msg.h>
32 #include <linux/shm.h>
33 #include <linux/slab.h>
34 #include <linux/uio.h>
35 #include <linux/aio.h>
36 #include <linux/nfs_fs.h>
37 #include <linux/module.h>
38 #include <linux/sunrpc/svc.h>
39 #include <linux/nfsd/nfsd.h>
40 #include <linux/nfsd/cache.h>
41 #include <linux/nfsd/xdr.h>
42 #include <linux/nfsd/syscall.h>
43 #include <linux/poll.h>
44 #include <linux/personality.h>
45 #include <linux/stat.h>
46 #include <linux/filter.h>
47 #include <linux/highmem.h>
48 #include <linux/highuid.h>
49 #include <linux/mman.h>
50 #include <linux/ipv6.h>
52 #include <linux/icmpv6.h>
53 #include <linux/syscalls.h>
54 #include <linux/unistd.h>
55 #include <linux/sysctl.h>
56 #include <linux/binfmts.h>
57 #include <linux/dnotify.h>
58 #include <linux/security.h>
59 #include <linux/compat.h>
60 #include <linux/ptrace.h>
61 #include <linux/aio_abi.h>
62 #include <linux/elf.h>
63 #include <linux/vs_cvirt.h>
68 #include <asm/ptrace.h>
69 #include <asm/types.h>
71 #include <asm/uaccess.h>
72 #include <asm/unistd.h>
73 #include <asm/semaphore.h>
74 #include <asm/ppcdebug.h>
76 #include <asm/mmu_context.h>
77 #include <asm/systemcfg.h>
81 /* readdir & getdents */
82 #define NAME_OFFSET(de) ((int) ((de)->d_name - (char __user *) (de)))
83 #define ROUND_UP(x) (((x)+sizeof(u32)-1) & ~(sizeof(u32)-1))
85 struct old_linux_dirent32 {
88 unsigned short d_namlen;
92 struct readdir_callback32 {
93 struct old_linux_dirent32 __user * dirent;
97 static int fillonedir(void * __buf, const char * name, int namlen,
98 off_t offset, ino_t ino, unsigned int d_type)
100 struct readdir_callback32 * buf = (struct readdir_callback32 *) __buf;
101 struct old_linux_dirent32 __user * dirent;
106 dirent = buf->dirent;
107 put_user(ino, &dirent->d_ino);
108 put_user(offset, &dirent->d_offset);
109 put_user(namlen, &dirent->d_namlen);
110 copy_to_user(dirent->d_name, name, namlen);
111 put_user(0, dirent->d_name + namlen);
115 asmlinkage int old32_readdir(unsigned int fd, struct old_linux_dirent32 __user *dirent, unsigned int count)
119 struct readdir_callback32 buf;
128 error = vfs_readdir(file, (filldir_t)fillonedir, &buf);
139 struct linux_dirent32 {
142 unsigned short d_reclen;
146 struct getdents_callback32 {
147 struct linux_dirent32 __user * current_dir;
148 struct linux_dirent32 __user * previous;
153 static int filldir(void * __buf, const char * name, int namlen, off_t offset,
154 ino_t ino, unsigned int d_type)
156 struct linux_dirent32 __user * dirent;
157 struct getdents_callback32 * buf = (struct getdents_callback32 *) __buf;
158 int reclen = ROUND_UP(NAME_OFFSET(dirent) + namlen + 2);
160 buf->error = -EINVAL; /* only used if we fail.. */
161 if (reclen > buf->count)
163 dirent = buf->previous;
165 if (__put_user(offset, &dirent->d_off))
168 dirent = buf->current_dir;
169 if (__put_user(ino, &dirent->d_ino))
171 if (__put_user(reclen, &dirent->d_reclen))
173 if (copy_to_user(dirent->d_name, name, namlen))
175 if (__put_user(0, dirent->d_name + namlen))
177 if (__put_user(d_type, (char __user *) dirent + reclen - 1))
179 buf->previous = dirent;
180 dirent = (void __user *)dirent + reclen;
181 buf->current_dir = dirent;
182 buf->count -= reclen;
185 buf->error = -EFAULT;
189 asmlinkage long sys32_getdents(unsigned int fd, struct linux_dirent32 __user *dirent,
193 struct linux_dirent32 __user * lastdirent;
194 struct getdents_callback32 buf;
198 if (!access_ok(VERIFY_WRITE, dirent, count))
206 buf.current_dir = dirent;
211 error = vfs_readdir(file, (filldir_t)filldir, &buf);
215 lastdirent = buf.previous;
217 if (put_user(file->f_pos, &lastdirent->d_off))
220 error = count - buf.count;
229 asmlinkage long ppc32_select(u32 n, compat_ulong_t __user *inp,
230 compat_ulong_t __user *outp, compat_ulong_t __user *exp,
234 return compat_sys_select((int)n, inp, outp, exp, compat_ptr(tvp_x));
237 int cp_compat_stat(struct kstat *stat, struct compat_stat __user *statbuf)
241 if (stat->size > MAX_NON_LFS || !new_valid_dev(stat->dev) ||
242 !new_valid_dev(stat->rdev))
245 err = access_ok(VERIFY_WRITE, statbuf, sizeof(*statbuf)) ? 0 : -EFAULT;
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(stat->uid, &statbuf->st_uid);
251 err |= __put_user(stat->gid, &statbuf->st_gid);
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->__unused4[0]);
263 err |= __put_user(0, &statbuf->__unused4[1]);
268 /* Note: it is necessary to treat option as an unsigned int,
269 * with the corresponding cast to a signed int to insure that the
270 * proper conversion (sign extension) between the register representation of a signed int (msr in 32-bit mode)
271 * and the register representation of a signed int (msr in 64-bit mode) is performed.
273 asmlinkage long sys32_sysfs(u32 option, u32 arg1, u32 arg2)
275 return sys_sysfs((int)option, arg1, arg2);
278 /* Handle adjtimex compatibility. */
281 s32 offset, freq, maxerror, esterror;
282 s32 status, constant, precision, tolerance;
283 struct compat_timeval time;
285 s32 ppsfreq, jitter, shift, stabil;
286 s32 jitcnt, calcnt, errcnt, stbcnt;
287 s32 :32; s32 :32; s32 :32; s32 :32;
288 s32 :32; s32 :32; s32 :32; s32 :32;
289 s32 :32; s32 :32; s32 :32; s32 :32;
292 extern int do_adjtimex(struct timex *);
293 extern void ppc_adjtimex(void);
295 asmlinkage long sys32_adjtimex(struct timex32 __user *utp)
300 memset(&txc, 0, sizeof(struct timex));
302 if(get_user(txc.modes, &utp->modes) ||
303 __get_user(txc.offset, &utp->offset) ||
304 __get_user(txc.freq, &utp->freq) ||
305 __get_user(txc.maxerror, &utp->maxerror) ||
306 __get_user(txc.esterror, &utp->esterror) ||
307 __get_user(txc.status, &utp->status) ||
308 __get_user(txc.constant, &utp->constant) ||
309 __get_user(txc.precision, &utp->precision) ||
310 __get_user(txc.tolerance, &utp->tolerance) ||
311 __get_user(txc.time.tv_sec, &utp->time.tv_sec) ||
312 __get_user(txc.time.tv_usec, &utp->time.tv_usec) ||
313 __get_user(txc.tick, &utp->tick) ||
314 __get_user(txc.ppsfreq, &utp->ppsfreq) ||
315 __get_user(txc.jitter, &utp->jitter) ||
316 __get_user(txc.shift, &utp->shift) ||
317 __get_user(txc.stabil, &utp->stabil) ||
318 __get_user(txc.jitcnt, &utp->jitcnt) ||
319 __get_user(txc.calcnt, &utp->calcnt) ||
320 __get_user(txc.errcnt, &utp->errcnt) ||
321 __get_user(txc.stbcnt, &utp->stbcnt))
324 ret = do_adjtimex(&txc);
326 /* adjust the conversion of TB to time of day to track adjtimex */
329 if(put_user(txc.modes, &utp->modes) ||
330 __put_user(txc.offset, &utp->offset) ||
331 __put_user(txc.freq, &utp->freq) ||
332 __put_user(txc.maxerror, &utp->maxerror) ||
333 __put_user(txc.esterror, &utp->esterror) ||
334 __put_user(txc.status, &utp->status) ||
335 __put_user(txc.constant, &utp->constant) ||
336 __put_user(txc.precision, &utp->precision) ||
337 __put_user(txc.tolerance, &utp->tolerance) ||
338 __put_user(txc.time.tv_sec, &utp->time.tv_sec) ||
339 __put_user(txc.time.tv_usec, &utp->time.tv_usec) ||
340 __put_user(txc.tick, &utp->tick) ||
341 __put_user(txc.ppsfreq, &utp->ppsfreq) ||
342 __put_user(txc.jitter, &utp->jitter) ||
343 __put_user(txc.shift, &utp->shift) ||
344 __put_user(txc.stabil, &utp->stabil) ||
345 __put_user(txc.jitcnt, &utp->jitcnt) ||
346 __put_user(txc.calcnt, &utp->calcnt) ||
347 __put_user(txc.errcnt, &utp->errcnt) ||
348 __put_user(txc.stbcnt, &utp->stbcnt))
355 /* These are here just in case some old sparc32 binary calls it. */
356 asmlinkage long sys32_pause(void)
358 current->state = TASK_INTERRUPTIBLE;
361 return -ERESTARTNOHAND;
366 static inline long get_ts32(struct timespec *o, struct compat_timeval __user *i)
370 if (!access_ok(VERIFY_READ, i, sizeof(*i)))
372 if (__get_user(o->tv_sec, &i->tv_sec))
374 if (__get_user(usec, &i->tv_usec))
376 o->tv_nsec = usec * 1000;
380 static inline long put_tv32(struct compat_timeval __user *o, struct timeval *i)
382 return (!access_ok(VERIFY_WRITE, o, sizeof(*o)) ||
383 (__put_user(i->tv_sec, &o->tv_sec) |
384 __put_user(i->tv_usec, &o->tv_usec)));
396 unsigned short procs;
401 char _f[20-2*sizeof(int)-sizeof(int)];
404 asmlinkage long sys32_sysinfo(struct sysinfo32 __user *info)
409 mm_segment_t old_fs = get_fs ();
411 /* The __user cast is valid due to set_fs() */
413 ret = sys_sysinfo((struct sysinfo __user *)&s);
416 /* Check to see if any memory value is too large for 32-bit and
417 * scale down if needed.
419 if ((s.totalram >> 32) || (s.totalswap >> 32)) {
420 while (s.mem_unit < PAGE_SIZE) {
424 s.totalram >>=bitcount;
425 s.freeram >>= bitcount;
426 s.sharedram >>= bitcount;
427 s.bufferram >>= bitcount;
428 s.totalswap >>= bitcount;
429 s.freeswap >>= bitcount;
430 s.totalhigh >>= bitcount;
431 s.freehigh >>= bitcount;
434 err = put_user (s.uptime, &info->uptime);
435 err |= __put_user (s.loads[0], &info->loads[0]);
436 err |= __put_user (s.loads[1], &info->loads[1]);
437 err |= __put_user (s.loads[2], &info->loads[2]);
438 err |= __put_user (s.totalram, &info->totalram);
439 err |= __put_user (s.freeram, &info->freeram);
440 err |= __put_user (s.sharedram, &info->sharedram);
441 err |= __put_user (s.bufferram, &info->bufferram);
442 err |= __put_user (s.totalswap, &info->totalswap);
443 err |= __put_user (s.freeswap, &info->freeswap);
444 err |= __put_user (s.procs, &info->procs);
445 err |= __put_user (s.totalhigh, &info->totalhigh);
446 err |= __put_user (s.freehigh, &info->freehigh);
447 err |= __put_user (s.mem_unit, &info->mem_unit);
457 /* Translations due to time_t size differences. Which affects all
458 sorts of things, like timeval and itimerval. */
459 extern struct timezone sys_tz;
461 asmlinkage long sys32_gettimeofday(struct compat_timeval __user *tv, struct timezone __user *tz)
465 do_gettimeofday(&ktv);
466 if (put_tv32(tv, &ktv))
470 if (copy_to_user(tz, &sys_tz, sizeof(sys_tz)))
479 asmlinkage long sys32_settimeofday(struct compat_timeval __user *tv, struct timezone __user *tz)
485 if (get_ts32(&kts, tv))
489 if (copy_from_user(&ktz, tz, sizeof(ktz)))
493 return do_sys_settimeofday(tv ? &kts : NULL, tz ? &ktz : NULL);
496 #ifdef CONFIG_SYSVIPC
497 long sys32_ipc(u32 call, u32 first, u32 second, u32 third, compat_uptr_t ptr,
502 version = call >> 16; /* hack for backward compatibility */
509 /* sign extend semid */
510 return compat_sys_semtimedop((int)first,
511 compat_ptr(ptr), second,
513 /* else fall through for normal semop() */
515 /* struct sembuf is the same on 32 and 64bit :)) */
516 /* sign extend semid */
517 return sys_semtimedop((int)first, compat_ptr(ptr), second,
520 /* sign extend key, nsems */
521 return sys_semget((int)first, (int)second, third);
523 /* sign extend semid, semnum */
524 return compat_sys_semctl((int)first, (int)second, third,
528 /* sign extend msqid */
529 return compat_sys_msgsnd((int)first, (int)second, third,
532 /* sign extend msqid, msgtyp */
533 return compat_sys_msgrcv((int)first, second, (int)fifth,
534 third, version, compat_ptr(ptr));
536 /* sign extend key */
537 return sys_msgget((int)first, second);
539 /* sign extend msqid */
540 return compat_sys_msgctl((int)first, second, compat_ptr(ptr));
543 /* sign extend shmid */
544 return compat_sys_shmat((int)first, second, third, version,
547 return sys_shmdt(compat_ptr(ptr));
549 /* sign extend key_t */
550 return sys_shmget((int)first, second, third);
552 /* sign extend shmid */
553 return compat_sys_shmctl((int)first, second, compat_ptr(ptr));
563 /* Note: it is necessary to treat out_fd and in_fd as unsigned ints,
564 * with the corresponding cast to a signed int to insure that the
565 * proper conversion (sign extension) between the register representation of a signed int (msr in 32-bit mode)
566 * and the register representation of a signed int (msr in 64-bit mode) is performed.
568 asmlinkage long sys32_sendfile(u32 out_fd, u32 in_fd, compat_off_t __user * offset, u32 count)
570 mm_segment_t old_fs = get_fs();
575 if (offset && get_user(of, offset))
578 /* The __user pointer cast is valid because of the set_fs() */
580 up = offset ? (off_t __user *) &of : NULL;
581 ret = sys_sendfile((int)out_fd, (int)in_fd, up, count);
584 if (offset && put_user(of, offset))
590 asmlinkage int sys32_sendfile64(int out_fd, int in_fd, compat_loff_t __user *offset, s32 count)
592 mm_segment_t old_fs = get_fs();
597 if (offset && get_user(lof, offset))
600 /* The __user pointer cast is valid because of the set_fs() */
602 up = offset ? (loff_t __user *) &lof : NULL;
603 ret = sys_sendfile64(out_fd, in_fd, up, count);
606 if (offset && put_user(lof, offset))
612 long sys32_execve(unsigned long a0, unsigned long a1, unsigned long a2,
613 unsigned long a3, unsigned long a4, unsigned long a5,
614 struct pt_regs *regs)
619 filename = getname((char __user *) a0);
620 error = PTR_ERR(filename);
621 if (IS_ERR(filename))
623 flush_fp_to_thread(current);
624 flush_altivec_to_thread(current);
626 error = compat_do_execve(filename, compat_ptr(a1), compat_ptr(a2), regs);
630 current->ptrace &= ~PT_DTRACE;
631 task_unlock(current);
639 /* Set up a thread for executing a new program. */
640 void start_thread32(struct pt_regs* regs, unsigned long nip, unsigned long sp)
645 * If we exec out of a kernel thread then thread.regs will not be
648 if (!current->thread.regs) {
649 unsigned long childregs = (unsigned long)current->thread_info +
651 childregs -= sizeof(struct pt_regs);
652 current->thread.regs = (struct pt_regs *)childregs;
656 * ELF_PLAT_INIT already clears all registers but it also sets r2.
657 * So just clear r2 here.
663 regs->msr = MSR_USER32;
665 if (last_task_used_math == current)
666 last_task_used_math = 0;
667 #endif /* CONFIG_SMP */
668 current->thread.fpscr = 0;
669 memset(current->thread.fpr, 0, sizeof(current->thread.fpr));
670 #ifdef CONFIG_ALTIVEC
672 if (last_task_used_altivec == current)
673 last_task_used_altivec = 0;
674 #endif /* CONFIG_SMP */
675 memset(current->thread.vr, 0, sizeof(current->thread.vr));
676 current->thread.vscr.u[0] = 0;
677 current->thread.vscr.u[1] = 0;
678 current->thread.vscr.u[2] = 0;
679 current->thread.vscr.u[3] = 0x00010000; /* Java mode disabled */
680 current->thread.vrsave = 0;
681 current->thread.used_vr = 0;
682 #endif /* CONFIG_ALTIVEC */
685 /* Note: it is necessary to treat option as an unsigned int,
686 * with the corresponding cast to a signed int to insure that the
687 * proper conversion (sign extension) between the register representation of a signed int (msr in 32-bit mode)
688 * and the register representation of a signed int (msr in 64-bit mode) is performed.
690 asmlinkage long sys32_prctl(u32 option, u32 arg2, u32 arg3, u32 arg4, u32 arg5)
692 return sys_prctl((int)option,
693 (unsigned long) arg2,
694 (unsigned long) arg3,
695 (unsigned long) arg4,
696 (unsigned long) arg5);
699 /* Note: it is necessary to treat pid as an unsigned int,
700 * with the corresponding cast to a signed int to insure that the
701 * proper conversion (sign extension) between the register representation of a signed int (msr in 32-bit mode)
702 * and the register representation of a signed int (msr in 64-bit mode) is performed.
704 asmlinkage long sys32_sched_rr_get_interval(u32 pid, struct compat_timespec __user *interval)
708 mm_segment_t old_fs = get_fs ();
710 /* The __user pointer cast is valid because of the set_fs() */
712 ret = sys_sched_rr_get_interval((int)pid, (struct timespec __user *) &t);
714 if (put_compat_timespec(&t, interval))
719 asmlinkage int sys32_pciconfig_read(u32 bus, u32 dfn, u32 off, u32 len, u32 ubuf)
721 return sys_pciconfig_read((unsigned long) bus,
728 asmlinkage int sys32_pciconfig_write(u32 bus, u32 dfn, u32 off, u32 len, u32 ubuf)
730 return sys_pciconfig_write((unsigned long) bus,
737 #define IOBASE_BRIDGE_NUMBER 0
738 #define IOBASE_MEMORY 1
740 #define IOBASE_ISA_IO 3
741 #define IOBASE_ISA_MEM 4
743 asmlinkage int sys32_pciconfig_iobase(u32 which, u32 in_bus, u32 in_devfn)
745 struct pci_controller* hose;
746 struct list_head *ln;
747 struct pci_bus *bus = NULL;
748 struct device_node *hose_node;
750 /* Argh ! Please forgive me for that hack, but that's the
751 * simplest way to get existing XFree to not lockup on some
752 * G5 machines... So when something asks for bus 0 io base
753 * (bus 0 is HT root), we return the AGP one instead.
755 #ifdef CONFIG_PPC_PMAC
756 if (systemcfg->platform == PLATFORM_POWERMAC &&
757 machine_is_compatible("MacRISC4"))
760 #endif /* CONFIG_PPC_PMAC */
762 /* That syscall isn't quite compatible with PCI domains, but it's
763 * used on pre-domains setup. We return the first match
766 for (ln = pci_root_buses.next; ln != &pci_root_buses; ln = ln->next) {
768 if (in_bus >= bus->number && in_bus < (bus->number + bus->subordinate))
772 if (bus == NULL || bus->sysdata == NULL)
775 hose_node = (struct device_node *)bus->sysdata;
776 hose = hose_node->phb;
779 case IOBASE_BRIDGE_NUMBER:
780 return (long)hose->first_busno;
782 return (long)hose->pci_mem_offset;
784 return (long)hose->io_base_phys;
786 return (long)isa_io_base;
795 /* Note: it is necessary to treat mode as an unsigned int,
796 * with the corresponding cast to a signed int to insure that the
797 * proper conversion (sign extension) between the register representation of a signed int (msr in 32-bit mode)
798 * and the register representation of a signed int (msr in 64-bit mode) is performed.
800 asmlinkage long sys32_access(const char __user * filename, u32 mode)
802 return sys_access(filename, (int)mode);
806 /* Note: it is necessary to treat mode as an unsigned int,
807 * with the corresponding cast to a signed int to insure that the
808 * proper conversion (sign extension) between the register representation of a signed int (msr in 32-bit mode)
809 * and the register representation of a signed int (msr in 64-bit mode) is performed.
811 asmlinkage long sys32_creat(const char __user * pathname, u32 mode)
813 return sys_creat(pathname, (int)mode);
817 /* Note: it is necessary to treat pid and options as unsigned ints,
818 * with the corresponding cast to a signed int to insure that the
819 * proper conversion (sign extension) between the register representation of a signed int (msr in 32-bit mode)
820 * and the register representation of a signed int (msr in 64-bit mode) is performed.
822 asmlinkage long sys32_waitpid(u32 pid, unsigned int __user * stat_addr, u32 options)
824 return sys_waitpid((int)pid, stat_addr, (int)options);
828 /* Note: it is necessary to treat gidsetsize as an unsigned int,
829 * with the corresponding cast to a signed int to insure that the
830 * proper conversion (sign extension) between the register representation of a signed int (msr in 32-bit mode)
831 * and the register representation of a signed int (msr in 64-bit mode) is performed.
833 asmlinkage long sys32_getgroups(u32 gidsetsize, gid_t __user *grouplist)
835 return sys_getgroups((int)gidsetsize, grouplist);
839 /* Note: it is necessary to treat pid as an unsigned int,
840 * with the corresponding cast to a signed int to insure that the
841 * proper conversion (sign extension) between the register representation of a signed int (msr in 32-bit mode)
842 * and the register representation of a signed int (msr in 64-bit mode) is performed.
844 asmlinkage long sys32_getpgid(u32 pid)
846 return sys_getpgid((int)pid);
850 /* Note: it is necessary to treat which and who as unsigned ints,
851 * with the corresponding cast to a signed int to insure that the
852 * proper conversion (sign extension) between the register representation of a signed int (msr in 32-bit mode)
853 * and the register representation of a signed int (msr in 64-bit mode) is performed.
855 asmlinkage long sys32_getpriority(u32 which, u32 who)
857 return sys_getpriority((int)which, (int)who);
861 /* Note: it is necessary to treat pid as an unsigned int,
862 * with the corresponding cast to a signed int to insure that the
863 * proper conversion (sign extension) between the register representation of a signed int (msr in 32-bit mode)
864 * and the register representation of a signed int (msr in 64-bit mode) is performed.
866 asmlinkage long sys32_getsid(u32 pid)
868 return sys_getsid((int)pid);
872 /* Note: it is necessary to treat pid and sig as unsigned ints,
873 * with the corresponding cast to a signed int to insure that the
874 * proper conversion (sign extension) between the register representation of a signed int (msr in 32-bit mode)
875 * and the register representation of a signed int (msr in 64-bit mode) is performed.
877 asmlinkage long sys32_kill(u32 pid, u32 sig)
879 return sys_kill((int)pid, (int)sig);
883 /* Note: it is necessary to treat mode as an unsigned int,
884 * with the corresponding cast to a signed int to insure that the
885 * proper conversion (sign extension) between the register representation of a signed int (msr in 32-bit mode)
886 * and the register representation of a signed int (msr in 64-bit mode) is performed.
888 asmlinkage long sys32_mkdir(const char __user * pathname, u32 mode)
890 return sys_mkdir(pathname, (int)mode);
893 long sys32_nice(u32 increment)
895 /* sign extend increment */
896 return sys_nice((int)increment);
899 off_t ppc32_lseek(unsigned int fd, u32 offset, unsigned int origin)
902 return sys_lseek(fd, (int)offset, origin);
906 * This is just a version for 32-bit applications which does
907 * not force O_LARGEFILE on.
909 asmlinkage long sys32_open(const char __user * filename, int flags, int mode)
914 tmp = getname(filename);
917 fd = get_unused_fd();
919 struct file * f = filp_open(tmp, flags, mode);
936 /* Note: it is necessary to treat bufsiz as an unsigned int,
937 * with the corresponding cast to a signed int to insure that the
938 * proper conversion (sign extension) between the register representation of a signed int (msr in 32-bit mode)
939 * and the register representation of a signed int (msr in 64-bit mode) is performed.
941 asmlinkage long sys32_readlink(const char __user * path, char __user * buf, u32 bufsiz)
943 return sys_readlink(path, buf, (int)bufsiz);
946 /* Note: it is necessary to treat option as an unsigned int,
947 * with the corresponding cast to a signed int to insure that the
948 * proper conversion (sign extension) between the register representation of a signed int (msr in 32-bit mode)
949 * and the register representation of a signed int (msr in 64-bit mode) is performed.
951 asmlinkage long sys32_sched_get_priority_max(u32 policy)
953 return sys_sched_get_priority_max((int)policy);
957 /* Note: it is necessary to treat policy as an unsigned int,
958 * with the corresponding cast to a signed int to insure that the
959 * proper conversion (sign extension) between the register representation of a signed int (msr in 32-bit mode)
960 * and the register representation of a signed int (msr in 64-bit mode) is performed.
962 asmlinkage long sys32_sched_get_priority_min(u32 policy)
964 return sys_sched_get_priority_min((int)policy);
968 /* Note: it is necessary to treat pid as an unsigned int,
969 * with the corresponding cast to a signed int to insure that the
970 * proper conversion (sign extension) between the register representation of a signed int (msr in 32-bit mode)
971 * and the register representation of a signed int (msr in 64-bit mode) is performed.
973 asmlinkage long sys32_sched_getparam(u32 pid, struct sched_param __user *param)
975 return sys_sched_getparam((int)pid, param);
979 /* Note: it is necessary to treat pid as an unsigned int,
980 * with the corresponding cast to a signed int to insure that the
981 * proper conversion (sign extension) between the register representation of a signed int (msr in 32-bit mode)
982 * and the register representation of a signed int (msr in 64-bit mode) is performed.
984 asmlinkage long sys32_sched_getscheduler(u32 pid)
986 return sys_sched_getscheduler((int)pid);
990 /* Note: it is necessary to treat pid as an unsigned int,
991 * with the corresponding cast to a signed int to insure that the
992 * proper conversion (sign extension) between the register representation of a signed int (msr in 32-bit mode)
993 * and the register representation of a signed int (msr in 64-bit mode) is performed.
995 asmlinkage long sys32_sched_setparam(u32 pid, struct sched_param __user *param)
997 return sys_sched_setparam((int)pid, param);
1001 /* Note: it is necessary to treat pid and policy as unsigned ints,
1002 * with the corresponding cast to a signed int to insure that the
1003 * proper conversion (sign extension) between the register representation of a signed int (msr in 32-bit mode)
1004 * and the register representation of a signed int (msr in 64-bit mode) is performed.
1006 asmlinkage long sys32_sched_setscheduler(u32 pid, u32 policy, struct sched_param __user *param)
1008 return sys_sched_setscheduler((int)pid, (int)policy, param);
1012 /* Note: it is necessary to treat len as an unsigned int,
1013 * with the corresponding cast to a signed int to insure that the
1014 * proper conversion (sign extension) between the register representation of a signed int (msr in 32-bit mode)
1015 * and the register representation of a signed int (msr in 64-bit mode) is performed.
1017 asmlinkage long sys32_setdomainname(char __user *name, u32 len)
1019 return sys_setdomainname(name, (int)len);
1023 /* Note: it is necessary to treat gidsetsize as an unsigned int,
1024 * with the corresponding cast to a signed int to insure that the
1025 * proper conversion (sign extension) between the register representation of a signed int (msr in 32-bit mode)
1026 * and the register representation of a signed int (msr in 64-bit mode) is performed.
1028 asmlinkage long sys32_setgroups(u32 gidsetsize, gid_t __user *grouplist)
1030 return sys_setgroups((int)gidsetsize, grouplist);
1034 asmlinkage long sys32_sethostname(char __user *name, u32 len)
1036 /* sign extend len */
1037 return sys_sethostname(name, (int)len);
1041 /* Note: it is necessary to treat pid and pgid as unsigned ints,
1042 * with the corresponding cast to a signed int to insure that the
1043 * proper conversion (sign extension) between the register representation of a signed int (msr in 32-bit mode)
1044 * and the register representation of a signed int (msr in 64-bit mode) is performed.
1046 asmlinkage long sys32_setpgid(u32 pid, u32 pgid)
1048 return sys_setpgid((int)pid, (int)pgid);
1052 long sys32_setpriority(u32 which, u32 who, u32 niceval)
1054 /* sign extend which, who and niceval */
1055 return sys_setpriority((int)which, (int)who, (int)niceval);
1058 /* Note: it is necessary to treat newmask as an unsigned int,
1059 * with the corresponding cast to a signed int to insure that the
1060 * proper conversion (sign extension) between the register representation of a signed int (msr in 32-bit mode)
1061 * and the register representation of a signed int (msr in 64-bit mode) is performed.
1063 asmlinkage long sys32_ssetmask(u32 newmask)
1065 return sys_ssetmask((int) newmask);
1068 asmlinkage long sys32_syslog(u32 type, char __user * buf, u32 len)
1070 /* sign extend len */
1071 return sys_syslog(type, buf, (int)len);
1075 /* Note: it is necessary to treat mask as an unsigned int,
1076 * with the corresponding cast to a signed int to insure that the
1077 * proper conversion (sign extension) between the register representation of a signed int (msr in 32-bit mode)
1078 * and the register representation of a signed int (msr in 64-bit mode) is performed.
1080 asmlinkage long sys32_umask(u32 mask)
1082 return sys_umask((int)mask);
1085 #ifdef CONFIG_SYSCTL
1086 struct __sysctl_args32 {
1096 asmlinkage long sys32_sysctl(struct __sysctl_args32 __user *args)
1098 struct __sysctl_args32 tmp;
1101 size_t __user *oldlenp = NULL;
1102 unsigned long addr = (((unsigned long)&args->__unused[0]) + 7) & ~7;
1104 if (copy_from_user(&tmp, args, sizeof(tmp)))
1107 if (tmp.oldval && tmp.oldlenp) {
1108 /* Duh, this is ugly and might not work if sysctl_args
1109 is in read-only memory, but do_sysctl does indirectly
1110 a lot of uaccess in both directions and we'd have to
1111 basically copy the whole sysctl.c here, and
1112 glibc's __sysctl uses rw memory for the structure
1114 oldlenp = (size_t __user *)addr;
1115 if (get_user(oldlen, (compat_size_t __user *)compat_ptr(tmp.oldlenp)) ||
1116 put_user(oldlen, oldlenp))
1121 error = do_sysctl(compat_ptr(tmp.name), tmp.nlen,
1122 compat_ptr(tmp.oldval), oldlenp,
1123 compat_ptr(tmp.newval), tmp.newlen);
1127 if (get_user(oldlen, oldlenp) ||
1128 put_user(oldlen, (compat_size_t __user *)compat_ptr(tmp.oldlenp)))
1131 copy_to_user(args->__unused, tmp.__unused, sizeof(tmp.__unused));
1137 asmlinkage int sys32_uname(struct old_utsname __user * name)
1141 down_read(&uts_sem);
1142 if (copy_to_user(name, vx_new_utsname(), sizeof(*name)))
1145 if (!err && personality(current->personality) == PER_LINUX32) {
1146 /* change "ppc64" to "ppc" */
1147 if (__put_user(0, name->machine + 3)
1148 || __put_user(0, name->machine + 4))
1154 asmlinkage int sys32_olduname(struct oldold_utsname __user * name)
1157 struct new_utsname *ptr;
1159 if (!access_ok(VERIFY_WRITE,name,sizeof(struct oldold_utsname)))
1162 down_read(&uts_sem);
1163 ptr = vx_new_utsname();
1164 error = __copy_to_user(&name->sysname,ptr->sysname,__OLD_UTS_LEN);
1165 error |= __put_user(0,name->sysname+__OLD_UTS_LEN);
1166 error |= __copy_to_user(&name->nodename,ptr->nodename,__OLD_UTS_LEN);
1167 error |= __put_user(0,name->nodename+__OLD_UTS_LEN);
1168 error |= __copy_to_user(&name->release,ptr->release,__OLD_UTS_LEN);
1169 error |= __put_user(0,name->release+__OLD_UTS_LEN);
1170 error |= __copy_to_user(&name->version,ptr->version,__OLD_UTS_LEN);
1171 error |= __put_user(0,name->version+__OLD_UTS_LEN);
1172 error |= __copy_to_user(&name->machine,ptr->machine,__OLD_UTS_LEN);
1173 error |= __put_user(0,name->machine+__OLD_UTS_LEN);
1174 if (personality(current->personality) == PER_LINUX32) {
1175 /* change "ppc64" to "ppc" */
1176 error |= __put_user(0, name->machine + 3);
1177 error |= __put_user(0, name->machine + 4);
1182 error = error ? -EFAULT : 0;
1187 unsigned long sys32_mmap2(unsigned long addr, size_t len,
1188 unsigned long prot, unsigned long flags,
1189 unsigned long fd, unsigned long pgoff)
1191 /* This should remain 12 even if PAGE_SIZE changes */
1192 return sys_mmap(addr, len, prot, flags, fd, pgoff << 12);
1195 int get_compat_timeval(struct timeval *tv, struct compat_timeval __user *ctv)
1197 return (!access_ok(VERIFY_READ, ctv, sizeof(*ctv)) ||
1198 __get_user(tv->tv_sec, &ctv->tv_sec) ||
1199 __get_user(tv->tv_usec, &ctv->tv_usec)) ? -EFAULT : 0;
1202 asmlinkage long sys32_utimes(char __user *filename, struct compat_timeval __user *tvs)
1204 struct timeval ktvs[2], *ptr;
1208 if (get_compat_timeval(&ktvs[0], &tvs[0]) ||
1209 get_compat_timeval(&ktvs[1], &tvs[1]))
1214 return do_utimes(filename, ptr);
1217 long sys32_tgkill(u32 tgid, u32 pid, int sig)
1219 /* sign extend tgid, pid */
1220 return sys_tgkill((int)tgid, (int)pid, sig);
1224 * long long munging:
1225 * The 32 bit ABI passes long longs in an odd even register pair.
1228 compat_ssize_t sys32_pread64(unsigned int fd, char __user *ubuf, compat_size_t count,
1229 u32 reg6, u32 poshi, u32 poslo)
1231 return sys_pread64(fd, ubuf, count, ((loff_t)poshi << 32) | poslo);
1234 compat_ssize_t sys32_pwrite64(unsigned int fd, char __user *ubuf, compat_size_t count,
1235 u32 reg6, u32 poshi, u32 poslo)
1237 return sys_pwrite64(fd, ubuf, count, ((loff_t)poshi << 32) | poslo);
1240 compat_ssize_t sys32_readahead(int fd, u32 r4, u32 offhi, u32 offlo, u32 count)
1242 return sys_readahead(fd, ((loff_t)offhi << 32) | offlo, count);
1245 asmlinkage int sys32_truncate64(const char __user * path, u32 reg4,
1246 unsigned long high, unsigned long low)
1248 return sys_truncate(path, (high << 32) | low);
1251 asmlinkage int sys32_ftruncate64(unsigned int fd, u32 reg4, unsigned long high,
1254 return sys_ftruncate(fd, (high << 32) | low);
1257 long ppc32_lookup_dcookie(u32 cookie_high, u32 cookie_low, char __user *buf,
1260 return sys_lookup_dcookie((u64)cookie_high << 32 | cookie_low,
1264 long ppc32_fadvise64(int fd, u32 unused, u32 offset_high, u32 offset_low,
1265 size_t len, int advice)
1267 return sys_fadvise64(fd, (u64)offset_high << 32 | offset_low, len,
1271 long ppc32_fadvise64_64(int fd, int advice, u32 offset_high, u32 offset_low,
1272 u32 len_high, u32 len_low)
1274 return sys_fadvise64(fd, (u64)offset_high << 32 | offset_low,
1275 (u64)len_high << 32 | len_low, advice);
1278 extern asmlinkage long sys_timer_create(clockid_t, sigevent_t __user *, timer_t __user *);
1280 long ppc32_timer_create(clockid_t clock,
1281 struct compat_sigevent __user *ev32,
1282 timer_t __user *timer_id)
1287 mm_segment_t savefs;
1290 return sys_timer_create(clock, NULL, timer_id);
1292 if (get_compat_sigevent(&event, ev32))
1295 if (!access_ok(VERIFY_WRITE, timer_id, sizeof(timer_t)))
1300 /* The __user pointer casts are valid due to the set_fs() */
1301 err = sys_timer_create(clock,
1302 (sigevent_t __user *) &event,
1303 (timer_t __user *) &t);
1307 err = __put_user(t, timer_id);
1312 asmlinkage long sys32_add_key(const char __user *_type,
1313 const char __user *_description,
1314 const void __user *_payload,
1318 return sys_add_key(_type, _description, _payload, plen, ringid);
1321 asmlinkage long sys32_request_key(const char __user *_type,
1322 const char __user *_description,
1323 const char __user *_callout_info,
1326 return sys_request_key(_type, _description, _callout_info, destringid);