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/poll.h>
34 #include <linux/personality.h>
35 #include <linux/stat.h>
36 #include <linux/mman.h>
38 #include <linux/syscalls.h>
39 #include <linux/unistd.h>
40 #include <linux/sysctl.h>
41 #include <linux/binfmts.h>
42 #include <linux/security.h>
43 #include <linux/compat.h>
44 #include <linux/ptrace.h>
45 #include <linux/elf.h>
47 #include <asm/ptrace.h>
48 #include <asm/types.h>
50 #include <asm/uaccess.h>
51 #include <asm/unistd.h>
52 #include <asm/semaphore.h>
54 #include <asm/mmu_context.h>
55 #include <asm/systemcfg.h>
56 #include <asm/ppc-pci.h>
58 /* readdir & getdents */
59 #define NAME_OFFSET(de) ((int) ((de)->d_name - (char __user *) (de)))
60 #define ROUND_UP(x) (((x)+sizeof(u32)-1) & ~(sizeof(u32)-1))
62 struct old_linux_dirent32 {
65 unsigned short d_namlen;
69 struct readdir_callback32 {
70 struct old_linux_dirent32 __user * dirent;
74 static int fillonedir(void * __buf, const char * name, int namlen,
75 off_t offset, ino_t ino, unsigned int d_type)
77 struct readdir_callback32 * buf = (struct readdir_callback32 *) __buf;
78 struct old_linux_dirent32 __user * dirent;
84 put_user(ino, &dirent->d_ino);
85 put_user(offset, &dirent->d_offset);
86 put_user(namlen, &dirent->d_namlen);
87 copy_to_user(dirent->d_name, name, namlen);
88 put_user(0, dirent->d_name + namlen);
92 asmlinkage int old32_readdir(unsigned int fd, struct old_linux_dirent32 __user *dirent, unsigned int count)
96 struct readdir_callback32 buf;
105 error = vfs_readdir(file, (filldir_t)fillonedir, &buf);
116 struct linux_dirent32 {
119 unsigned short d_reclen;
123 struct getdents_callback32 {
124 struct linux_dirent32 __user * current_dir;
125 struct linux_dirent32 __user * previous;
130 static int filldir(void * __buf, const char * name, int namlen, off_t offset,
131 ino_t ino, unsigned int d_type)
133 struct linux_dirent32 __user * dirent;
134 struct getdents_callback32 * buf = (struct getdents_callback32 *) __buf;
135 int reclen = ROUND_UP(NAME_OFFSET(dirent) + namlen + 2);
137 buf->error = -EINVAL; /* only used if we fail.. */
138 if (reclen > buf->count)
140 dirent = buf->previous;
142 if (__put_user(offset, &dirent->d_off))
145 dirent = buf->current_dir;
146 if (__put_user(ino, &dirent->d_ino))
148 if (__put_user(reclen, &dirent->d_reclen))
150 if (copy_to_user(dirent->d_name, name, namlen))
152 if (__put_user(0, dirent->d_name + namlen))
154 if (__put_user(d_type, (char __user *) dirent + reclen - 1))
156 buf->previous = dirent;
157 dirent = (void __user *)dirent + reclen;
158 buf->current_dir = dirent;
159 buf->count -= reclen;
162 buf->error = -EFAULT;
166 asmlinkage long sys32_getdents(unsigned int fd, struct linux_dirent32 __user *dirent,
170 struct linux_dirent32 __user * lastdirent;
171 struct getdents_callback32 buf;
175 if (!access_ok(VERIFY_WRITE, dirent, count))
183 buf.current_dir = dirent;
188 error = vfs_readdir(file, (filldir_t)filldir, &buf);
192 lastdirent = buf.previous;
194 if (put_user(file->f_pos, &lastdirent->d_off))
197 error = count - buf.count;
206 asmlinkage long ppc32_select(u32 n, compat_ulong_t __user *inp,
207 compat_ulong_t __user *outp, compat_ulong_t __user *exp,
211 return compat_sys_select((int)n, inp, outp, exp, compat_ptr(tvp_x));
214 int cp_compat_stat(struct kstat *stat, struct compat_stat __user *statbuf)
218 if (stat->size > MAX_NON_LFS || !new_valid_dev(stat->dev) ||
219 !new_valid_dev(stat->rdev))
222 err = access_ok(VERIFY_WRITE, statbuf, sizeof(*statbuf)) ? 0 : -EFAULT;
223 err |= __put_user(new_encode_dev(stat->dev), &statbuf->st_dev);
224 err |= __put_user(stat->ino, &statbuf->st_ino);
225 err |= __put_user(stat->mode, &statbuf->st_mode);
226 err |= __put_user(stat->nlink, &statbuf->st_nlink);
227 err |= __put_user(stat->uid, &statbuf->st_uid);
228 err |= __put_user(stat->gid, &statbuf->st_gid);
229 err |= __put_user(new_encode_dev(stat->rdev), &statbuf->st_rdev);
230 err |= __put_user(stat->size, &statbuf->st_size);
231 err |= __put_user(stat->atime.tv_sec, &statbuf->st_atime);
232 err |= __put_user(stat->atime.tv_nsec, &statbuf->st_atime_nsec);
233 err |= __put_user(stat->mtime.tv_sec, &statbuf->st_mtime);
234 err |= __put_user(stat->mtime.tv_nsec, &statbuf->st_mtime_nsec);
235 err |= __put_user(stat->ctime.tv_sec, &statbuf->st_ctime);
236 err |= __put_user(stat->ctime.tv_nsec, &statbuf->st_ctime_nsec);
237 err |= __put_user(stat->blksize, &statbuf->st_blksize);
238 err |= __put_user(stat->blocks, &statbuf->st_blocks);
239 err |= __put_user(0, &statbuf->__unused4[0]);
240 err |= __put_user(0, &statbuf->__unused4[1]);
245 /* Note: it is necessary to treat option as an unsigned int,
246 * with the corresponding cast to a signed int to insure that the
247 * proper conversion (sign extension) between the register representation of a signed int (msr in 32-bit mode)
248 * and the register representation of a signed int (msr in 64-bit mode) is performed.
250 asmlinkage long sys32_sysfs(u32 option, u32 arg1, u32 arg2)
252 return sys_sysfs((int)option, arg1, arg2);
255 /* Handle adjtimex compatibility. */
258 s32 offset, freq, maxerror, esterror;
259 s32 status, constant, precision, tolerance;
260 struct compat_timeval time;
262 s32 ppsfreq, jitter, shift, stabil;
263 s32 jitcnt, calcnt, errcnt, stbcnt;
264 s32 :32; s32 :32; s32 :32; s32 :32;
265 s32 :32; s32 :32; s32 :32; s32 :32;
266 s32 :32; s32 :32; s32 :32; s32 :32;
269 extern int do_adjtimex(struct timex *);
270 extern void ppc_adjtimex(void);
272 asmlinkage long sys32_adjtimex(struct timex32 __user *utp)
277 memset(&txc, 0, sizeof(struct timex));
279 if(get_user(txc.modes, &utp->modes) ||
280 __get_user(txc.offset, &utp->offset) ||
281 __get_user(txc.freq, &utp->freq) ||
282 __get_user(txc.maxerror, &utp->maxerror) ||
283 __get_user(txc.esterror, &utp->esterror) ||
284 __get_user(txc.status, &utp->status) ||
285 __get_user(txc.constant, &utp->constant) ||
286 __get_user(txc.precision, &utp->precision) ||
287 __get_user(txc.tolerance, &utp->tolerance) ||
288 __get_user(txc.time.tv_sec, &utp->time.tv_sec) ||
289 __get_user(txc.time.tv_usec, &utp->time.tv_usec) ||
290 __get_user(txc.tick, &utp->tick) ||
291 __get_user(txc.ppsfreq, &utp->ppsfreq) ||
292 __get_user(txc.jitter, &utp->jitter) ||
293 __get_user(txc.shift, &utp->shift) ||
294 __get_user(txc.stabil, &utp->stabil) ||
295 __get_user(txc.jitcnt, &utp->jitcnt) ||
296 __get_user(txc.calcnt, &utp->calcnt) ||
297 __get_user(txc.errcnt, &utp->errcnt) ||
298 __get_user(txc.stbcnt, &utp->stbcnt))
301 ret = do_adjtimex(&txc);
303 /* adjust the conversion of TB to time of day to track adjtimex */
306 if(put_user(txc.modes, &utp->modes) ||
307 __put_user(txc.offset, &utp->offset) ||
308 __put_user(txc.freq, &utp->freq) ||
309 __put_user(txc.maxerror, &utp->maxerror) ||
310 __put_user(txc.esterror, &utp->esterror) ||
311 __put_user(txc.status, &utp->status) ||
312 __put_user(txc.constant, &utp->constant) ||
313 __put_user(txc.precision, &utp->precision) ||
314 __put_user(txc.tolerance, &utp->tolerance) ||
315 __put_user(txc.time.tv_sec, &utp->time.tv_sec) ||
316 __put_user(txc.time.tv_usec, &utp->time.tv_usec) ||
317 __put_user(txc.tick, &utp->tick) ||
318 __put_user(txc.ppsfreq, &utp->ppsfreq) ||
319 __put_user(txc.jitter, &utp->jitter) ||
320 __put_user(txc.shift, &utp->shift) ||
321 __put_user(txc.stabil, &utp->stabil) ||
322 __put_user(txc.jitcnt, &utp->jitcnt) ||
323 __put_user(txc.calcnt, &utp->calcnt) ||
324 __put_user(txc.errcnt, &utp->errcnt) ||
325 __put_user(txc.stbcnt, &utp->stbcnt))
331 asmlinkage long sys32_pause(void)
333 current->state = TASK_INTERRUPTIBLE;
336 return -ERESTARTNOHAND;
339 static inline long get_ts32(struct timespec *o, struct compat_timeval __user *i)
343 if (!access_ok(VERIFY_READ, i, sizeof(*i)))
345 if (__get_user(o->tv_sec, &i->tv_sec))
347 if (__get_user(usec, &i->tv_usec))
349 o->tv_nsec = usec * 1000;
353 static inline long put_tv32(struct compat_timeval __user *o, struct timeval *i)
355 return (!access_ok(VERIFY_WRITE, o, sizeof(*o)) ||
356 (__put_user(i->tv_sec, &o->tv_sec) |
357 __put_user(i->tv_usec, &o->tv_usec)));
369 unsigned short procs;
374 char _f[20-2*sizeof(int)-sizeof(int)];
377 asmlinkage long sys32_sysinfo(struct sysinfo32 __user *info)
382 mm_segment_t old_fs = get_fs ();
384 /* The __user cast is valid due to set_fs() */
386 ret = sys_sysinfo((struct sysinfo __user *)&s);
389 /* Check to see if any memory value is too large for 32-bit and
390 * scale down if needed.
392 if ((s.totalram >> 32) || (s.totalswap >> 32)) {
393 while (s.mem_unit < PAGE_SIZE) {
397 s.totalram >>=bitcount;
398 s.freeram >>= bitcount;
399 s.sharedram >>= bitcount;
400 s.bufferram >>= bitcount;
401 s.totalswap >>= bitcount;
402 s.freeswap >>= bitcount;
403 s.totalhigh >>= bitcount;
404 s.freehigh >>= bitcount;
407 err = put_user (s.uptime, &info->uptime);
408 err |= __put_user (s.loads[0], &info->loads[0]);
409 err |= __put_user (s.loads[1], &info->loads[1]);
410 err |= __put_user (s.loads[2], &info->loads[2]);
411 err |= __put_user (s.totalram, &info->totalram);
412 err |= __put_user (s.freeram, &info->freeram);
413 err |= __put_user (s.sharedram, &info->sharedram);
414 err |= __put_user (s.bufferram, &info->bufferram);
415 err |= __put_user (s.totalswap, &info->totalswap);
416 err |= __put_user (s.freeswap, &info->freeswap);
417 err |= __put_user (s.procs, &info->procs);
418 err |= __put_user (s.totalhigh, &info->totalhigh);
419 err |= __put_user (s.freehigh, &info->freehigh);
420 err |= __put_user (s.mem_unit, &info->mem_unit);
430 /* Translations due to time_t size differences. Which affects all
431 sorts of things, like timeval and itimerval. */
432 extern struct timezone sys_tz;
434 asmlinkage long sys32_gettimeofday(struct compat_timeval __user *tv, struct timezone __user *tz)
438 do_gettimeofday(&ktv);
439 if (put_tv32(tv, &ktv))
443 if (copy_to_user(tz, &sys_tz, sizeof(sys_tz)))
452 asmlinkage long sys32_settimeofday(struct compat_timeval __user *tv, struct timezone __user *tz)
458 if (get_ts32(&kts, tv))
462 if (copy_from_user(&ktz, tz, sizeof(ktz)))
466 return do_sys_settimeofday(tv ? &kts : NULL, tz ? &ktz : NULL);
469 #ifdef CONFIG_SYSVIPC
470 long sys32_ipc(u32 call, u32 first, u32 second, u32 third, compat_uptr_t ptr,
475 version = call >> 16; /* hack for backward compatibility */
482 /* sign extend semid */
483 return compat_sys_semtimedop((int)first,
484 compat_ptr(ptr), second,
486 /* else fall through for normal semop() */
488 /* struct sembuf is the same on 32 and 64bit :)) */
489 /* sign extend semid */
490 return sys_semtimedop((int)first, compat_ptr(ptr), second,
493 /* sign extend key, nsems */
494 return sys_semget((int)first, (int)second, third);
496 /* sign extend semid, semnum */
497 return compat_sys_semctl((int)first, (int)second, third,
501 /* sign extend msqid */
502 return compat_sys_msgsnd((int)first, (int)second, third,
505 /* sign extend msqid, msgtyp */
506 return compat_sys_msgrcv((int)first, second, (int)fifth,
507 third, version, compat_ptr(ptr));
509 /* sign extend key */
510 return sys_msgget((int)first, second);
512 /* sign extend msqid */
513 return compat_sys_msgctl((int)first, second, compat_ptr(ptr));
516 /* sign extend shmid */
517 return compat_sys_shmat((int)first, second, third, version,
520 return sys_shmdt(compat_ptr(ptr));
522 /* sign extend key_t */
523 return sys_shmget((int)first, second, third);
525 /* sign extend shmid */
526 return compat_sys_shmctl((int)first, second, compat_ptr(ptr));
536 /* Note: it is necessary to treat out_fd and in_fd as unsigned ints,
537 * with the corresponding cast to a signed int to insure that the
538 * proper conversion (sign extension) between the register representation of a signed int (msr in 32-bit mode)
539 * and the register representation of a signed int (msr in 64-bit mode) is performed.
541 asmlinkage long sys32_sendfile(u32 out_fd, u32 in_fd, compat_off_t __user * offset, u32 count)
543 mm_segment_t old_fs = get_fs();
548 if (offset && get_user(of, offset))
551 /* The __user pointer cast is valid because of the set_fs() */
553 up = offset ? (off_t __user *) &of : NULL;
554 ret = sys_sendfile((int)out_fd, (int)in_fd, up, count);
557 if (offset && put_user(of, offset))
563 asmlinkage int sys32_sendfile64(int out_fd, int in_fd, compat_loff_t __user *offset, s32 count)
565 mm_segment_t old_fs = get_fs();
570 if (offset && get_user(lof, offset))
573 /* The __user pointer cast is valid because of the set_fs() */
575 up = offset ? (loff_t __user *) &lof : NULL;
576 ret = sys_sendfile64(out_fd, in_fd, up, count);
579 if (offset && put_user(lof, offset))
585 long sys32_execve(unsigned long a0, unsigned long a1, unsigned long a2,
586 unsigned long a3, unsigned long a4, unsigned long a5,
587 struct pt_regs *regs)
592 filename = getname((char __user *) a0);
593 error = PTR_ERR(filename);
594 if (IS_ERR(filename))
596 flush_fp_to_thread(current);
597 flush_altivec_to_thread(current);
599 error = compat_do_execve(filename, compat_ptr(a1), compat_ptr(a2), regs);
603 current->ptrace &= ~PT_DTRACE;
604 task_unlock(current);
612 /* Set up a thread for executing a new program. */
613 void start_thread32(struct pt_regs* regs, unsigned long nip, unsigned long sp)
618 * If we exec out of a kernel thread then thread.regs will not be
621 if (!current->thread.regs) {
622 unsigned long childregs = (unsigned long)current->thread_info +
624 childregs -= sizeof(struct pt_regs);
625 current->thread.regs = (struct pt_regs *)childregs;
629 * ELF_PLAT_INIT already clears all registers but it also sets r2.
630 * So just clear r2 here.
636 regs->msr = MSR_USER32;
638 if (last_task_used_math == current)
639 last_task_used_math = 0;
640 #endif /* CONFIG_SMP */
641 current->thread.fpscr = 0;
642 memset(current->thread.fpr, 0, sizeof(current->thread.fpr));
643 #ifdef CONFIG_ALTIVEC
645 if (last_task_used_altivec == current)
646 last_task_used_altivec = 0;
647 #endif /* CONFIG_SMP */
648 memset(current->thread.vr, 0, sizeof(current->thread.vr));
649 current->thread.vscr.u[0] = 0;
650 current->thread.vscr.u[1] = 0;
651 current->thread.vscr.u[2] = 0;
652 current->thread.vscr.u[3] = 0x00010000; /* Java mode disabled */
653 current->thread.vrsave = 0;
654 current->thread.used_vr = 0;
655 #endif /* CONFIG_ALTIVEC */
658 /* Note: it is necessary to treat option as an unsigned int,
659 * with the corresponding cast to a signed int to insure that the
660 * proper conversion (sign extension) between the register representation of a signed int (msr in 32-bit mode)
661 * and the register representation of a signed int (msr in 64-bit mode) is performed.
663 asmlinkage long sys32_prctl(u32 option, u32 arg2, u32 arg3, u32 arg4, u32 arg5)
665 return sys_prctl((int)option,
666 (unsigned long) arg2,
667 (unsigned long) arg3,
668 (unsigned long) arg4,
669 (unsigned long) arg5);
672 /* Note: it is necessary to treat pid as an unsigned int,
673 * with the corresponding cast to a signed int to insure that the
674 * proper conversion (sign extension) between the register representation of a signed int (msr in 32-bit mode)
675 * and the register representation of a signed int (msr in 64-bit mode) is performed.
677 asmlinkage long sys32_sched_rr_get_interval(u32 pid, struct compat_timespec __user *interval)
681 mm_segment_t old_fs = get_fs ();
683 /* The __user pointer cast is valid because of the set_fs() */
685 ret = sys_sched_rr_get_interval((int)pid, (struct timespec __user *) &t);
687 if (put_compat_timespec(&t, interval))
692 asmlinkage int sys32_pciconfig_read(u32 bus, u32 dfn, u32 off, u32 len, u32 ubuf)
694 return sys_pciconfig_read((unsigned long) bus,
701 asmlinkage int sys32_pciconfig_write(u32 bus, u32 dfn, u32 off, u32 len, u32 ubuf)
703 return sys_pciconfig_write((unsigned long) bus,
710 asmlinkage int sys32_pciconfig_iobase(u32 which, u32 in_bus, u32 in_devfn)
712 return sys_pciconfig_iobase(which, in_bus, in_devfn);
716 /* Note: it is necessary to treat mode as an unsigned int,
717 * with the corresponding cast to a signed int to insure that the
718 * proper conversion (sign extension) between the register representation of a signed int (msr in 32-bit mode)
719 * and the register representation of a signed int (msr in 64-bit mode) is performed.
721 asmlinkage long sys32_access(const char __user * filename, u32 mode)
723 return sys_access(filename, (int)mode);
727 /* Note: it is necessary to treat mode as an unsigned int,
728 * with the corresponding cast to a signed int to insure that the
729 * proper conversion (sign extension) between the register representation of a signed int (msr in 32-bit mode)
730 * and the register representation of a signed int (msr in 64-bit mode) is performed.
732 asmlinkage long sys32_creat(const char __user * pathname, u32 mode)
734 return sys_creat(pathname, (int)mode);
738 /* Note: it is necessary to treat pid and options as unsigned ints,
739 * with the corresponding cast to a signed int to insure that the
740 * proper conversion (sign extension) between the register representation of a signed int (msr in 32-bit mode)
741 * and the register representation of a signed int (msr in 64-bit mode) is performed.
743 asmlinkage long sys32_waitpid(u32 pid, unsigned int __user * stat_addr, u32 options)
745 return sys_waitpid((int)pid, stat_addr, (int)options);
749 /* Note: it is necessary to treat gidsetsize as an unsigned int,
750 * with the corresponding cast to a signed int to insure that the
751 * proper conversion (sign extension) between the register representation of a signed int (msr in 32-bit mode)
752 * and the register representation of a signed int (msr in 64-bit mode) is performed.
754 asmlinkage long sys32_getgroups(u32 gidsetsize, gid_t __user *grouplist)
756 return sys_getgroups((int)gidsetsize, grouplist);
760 /* Note: it is necessary to treat pid as an unsigned int,
761 * with the corresponding cast to a signed int to insure that the
762 * proper conversion (sign extension) between the register representation of a signed int (msr in 32-bit mode)
763 * and the register representation of a signed int (msr in 64-bit mode) is performed.
765 asmlinkage long sys32_getpgid(u32 pid)
767 return sys_getpgid((int)pid);
772 /* Note: it is necessary to treat pid as an unsigned int,
773 * with the corresponding cast to a signed int to insure that the
774 * proper conversion (sign extension) between the register representation of a signed int (msr in 32-bit mode)
775 * and the register representation of a signed int (msr in 64-bit mode) is performed.
777 asmlinkage long sys32_getsid(u32 pid)
779 return sys_getsid((int)pid);
783 /* Note: it is necessary to treat pid and sig as unsigned ints,
784 * with the corresponding cast to a signed int to insure that the
785 * proper conversion (sign extension) between the register representation of a signed int (msr in 32-bit mode)
786 * and the register representation of a signed int (msr in 64-bit mode) is performed.
788 asmlinkage long sys32_kill(u32 pid, u32 sig)
790 return sys_kill((int)pid, (int)sig);
794 /* Note: it is necessary to treat mode as an unsigned int,
795 * with the corresponding cast to a signed int to insure that the
796 * proper conversion (sign extension) between the register representation of a signed int (msr in 32-bit mode)
797 * and the register representation of a signed int (msr in 64-bit mode) is performed.
799 asmlinkage long sys32_mkdir(const char __user * pathname, u32 mode)
801 return sys_mkdir(pathname, (int)mode);
804 long sys32_nice(u32 increment)
806 /* sign extend increment */
807 return sys_nice((int)increment);
810 off_t ppc32_lseek(unsigned int fd, u32 offset, unsigned int origin)
813 return sys_lseek(fd, (int)offset, origin);
816 /* Note: it is necessary to treat bufsiz as an unsigned int,
817 * with the corresponding cast to a signed int to insure that the
818 * proper conversion (sign extension) between the register representation of a signed int (msr in 32-bit mode)
819 * and the register representation of a signed int (msr in 64-bit mode) is performed.
821 asmlinkage long sys32_readlink(const char __user * path, char __user * buf, u32 bufsiz)
823 return sys_readlink(path, buf, (int)bufsiz);
826 /* Note: it is necessary to treat option as an unsigned int,
827 * with the corresponding cast to a signed int to insure that the
828 * proper conversion (sign extension) between the register representation of a signed int (msr in 32-bit mode)
829 * and the register representation of a signed int (msr in 64-bit mode) is performed.
831 asmlinkage long sys32_sched_get_priority_max(u32 policy)
833 return sys_sched_get_priority_max((int)policy);
837 /* Note: it is necessary to treat policy as an unsigned int,
838 * with the corresponding cast to a signed int to insure that the
839 * proper conversion (sign extension) between the register representation of a signed int (msr in 32-bit mode)
840 * and the register representation of a signed int (msr in 64-bit mode) is performed.
842 asmlinkage long sys32_sched_get_priority_min(u32 policy)
844 return sys_sched_get_priority_min((int)policy);
848 /* Note: it is necessary to treat pid as an unsigned int,
849 * with the corresponding cast to a signed int to insure that the
850 * proper conversion (sign extension) between the register representation of a signed int (msr in 32-bit mode)
851 * and the register representation of a signed int (msr in 64-bit mode) is performed.
853 asmlinkage long sys32_sched_getparam(u32 pid, struct sched_param __user *param)
855 return sys_sched_getparam((int)pid, param);
859 /* Note: it is necessary to treat pid as an unsigned int,
860 * with the corresponding cast to a signed int to insure that the
861 * proper conversion (sign extension) between the register representation of a signed int (msr in 32-bit mode)
862 * and the register representation of a signed int (msr in 64-bit mode) is performed.
864 asmlinkage long sys32_sched_getscheduler(u32 pid)
866 return sys_sched_getscheduler((int)pid);
870 /* Note: it is necessary to treat pid as an unsigned int,
871 * with the corresponding cast to a signed int to insure that the
872 * proper conversion (sign extension) between the register representation of a signed int (msr in 32-bit mode)
873 * and the register representation of a signed int (msr in 64-bit mode) is performed.
875 asmlinkage long sys32_sched_setparam(u32 pid, struct sched_param __user *param)
877 return sys_sched_setparam((int)pid, param);
881 /* Note: it is necessary to treat pid and policy as unsigned ints,
882 * with the corresponding cast to a signed int to insure that the
883 * proper conversion (sign extension) between the register representation of a signed int (msr in 32-bit mode)
884 * and the register representation of a signed int (msr in 64-bit mode) is performed.
886 asmlinkage long sys32_sched_setscheduler(u32 pid, u32 policy, struct sched_param __user *param)
888 return sys_sched_setscheduler((int)pid, (int)policy, param);
892 /* Note: it is necessary to treat len as an unsigned int,
893 * with the corresponding cast to a signed int to insure that the
894 * proper conversion (sign extension) between the register representation of a signed int (msr in 32-bit mode)
895 * and the register representation of a signed int (msr in 64-bit mode) is performed.
897 asmlinkage long sys32_setdomainname(char __user *name, u32 len)
899 return sys_setdomainname(name, (int)len);
903 /* Note: it is necessary to treat gidsetsize as an unsigned int,
904 * with the corresponding cast to a signed int to insure that the
905 * proper conversion (sign extension) between the register representation of a signed int (msr in 32-bit mode)
906 * and the register representation of a signed int (msr in 64-bit mode) is performed.
908 asmlinkage long sys32_setgroups(u32 gidsetsize, gid_t __user *grouplist)
910 return sys_setgroups((int)gidsetsize, grouplist);
914 asmlinkage long sys32_sethostname(char __user *name, u32 len)
916 /* sign extend len */
917 return sys_sethostname(name, (int)len);
921 /* Note: it is necessary to treat pid and pgid as unsigned ints,
922 * with the corresponding cast to a signed int to insure that the
923 * proper conversion (sign extension) between the register representation of a signed int (msr in 32-bit mode)
924 * and the register representation of a signed int (msr in 64-bit mode) is performed.
926 asmlinkage long sys32_setpgid(u32 pid, u32 pgid)
928 return sys_setpgid((int)pid, (int)pgid);
931 long sys32_getpriority(u32 which, u32 who)
933 /* sign extend which and who */
934 return sys_getpriority((int)which, (int)who);
937 long sys32_setpriority(u32 which, u32 who, u32 niceval)
939 /* sign extend which, who and niceval */
940 return sys_setpriority((int)which, (int)who, (int)niceval);
943 long sys32_ioprio_get(u32 which, u32 who)
945 /* sign extend which and who */
946 return sys_ioprio_get((int)which, (int)who);
949 long sys32_ioprio_set(u32 which, u32 who, u32 ioprio)
951 /* sign extend which, who and ioprio */
952 return sys_ioprio_set((int)which, (int)who, (int)ioprio);
955 /* Note: it is necessary to treat newmask as an unsigned int,
956 * with the corresponding cast to a signed int to insure that the
957 * proper conversion (sign extension) between the register representation of a signed int (msr in 32-bit mode)
958 * and the register representation of a signed int (msr in 64-bit mode) is performed.
960 asmlinkage long sys32_ssetmask(u32 newmask)
962 return sys_ssetmask((int) newmask);
965 asmlinkage long sys32_syslog(u32 type, char __user * buf, u32 len)
967 /* sign extend len */
968 return sys_syslog(type, buf, (int)len);
972 /* Note: it is necessary to treat mask as an unsigned int,
973 * with the corresponding cast to a signed int to insure that the
974 * proper conversion (sign extension) between the register representation of a signed int (msr in 32-bit mode)
975 * and the register representation of a signed int (msr in 64-bit mode) is performed.
977 asmlinkage long sys32_umask(u32 mask)
979 return sys_umask((int)mask);
983 struct __sysctl_args32 {
993 asmlinkage long sys32_sysctl(struct __sysctl_args32 __user *args)
995 struct __sysctl_args32 tmp;
998 size_t __user *oldlenp = NULL;
999 unsigned long addr = (((unsigned long)&args->__unused[0]) + 7) & ~7;
1001 if (copy_from_user(&tmp, args, sizeof(tmp)))
1004 if (tmp.oldval && tmp.oldlenp) {
1005 /* Duh, this is ugly and might not work if sysctl_args
1006 is in read-only memory, but do_sysctl does indirectly
1007 a lot of uaccess in both directions and we'd have to
1008 basically copy the whole sysctl.c here, and
1009 glibc's __sysctl uses rw memory for the structure
1011 oldlenp = (size_t __user *)addr;
1012 if (get_user(oldlen, (compat_size_t __user *)compat_ptr(tmp.oldlenp)) ||
1013 put_user(oldlen, oldlenp))
1018 error = do_sysctl(compat_ptr(tmp.name), tmp.nlen,
1019 compat_ptr(tmp.oldval), oldlenp,
1020 compat_ptr(tmp.newval), tmp.newlen);
1024 if (get_user(oldlen, oldlenp) ||
1025 put_user(oldlen, (compat_size_t __user *)compat_ptr(tmp.oldlenp)))
1028 copy_to_user(args->__unused, tmp.__unused, sizeof(tmp.__unused));
1034 asmlinkage int sys32_uname(struct old_utsname __user * name)
1038 down_read(&uts_sem);
1039 if (copy_to_user(name, &system_utsname, sizeof(*name)))
1042 if (!err && personality(current->personality) == PER_LINUX32) {
1043 /* change "ppc64" to "ppc" */
1044 if (__put_user(0, name->machine + 3)
1045 || __put_user(0, name->machine + 4))
1051 asmlinkage int sys32_olduname(struct oldold_utsname __user * name)
1055 if (!access_ok(VERIFY_WRITE,name,sizeof(struct oldold_utsname)))
1058 down_read(&uts_sem);
1059 error = __copy_to_user(&name->sysname,&system_utsname.sysname,__OLD_UTS_LEN);
1060 error |= __put_user(0,name->sysname+__OLD_UTS_LEN);
1061 error |= __copy_to_user(&name->nodename,&system_utsname.nodename,__OLD_UTS_LEN);
1062 error |= __put_user(0,name->nodename+__OLD_UTS_LEN);
1063 error |= __copy_to_user(&name->release,&system_utsname.release,__OLD_UTS_LEN);
1064 error |= __put_user(0,name->release+__OLD_UTS_LEN);
1065 error |= __copy_to_user(&name->version,&system_utsname.version,__OLD_UTS_LEN);
1066 error |= __put_user(0,name->version+__OLD_UTS_LEN);
1067 error |= __copy_to_user(&name->machine,&system_utsname.machine,__OLD_UTS_LEN);
1068 error |= __put_user(0,name->machine+__OLD_UTS_LEN);
1069 if (personality(current->personality) == PER_LINUX32) {
1070 /* change "ppc64" to "ppc" */
1071 error |= __put_user(0, name->machine + 3);
1072 error |= __put_user(0, name->machine + 4);
1077 error = error ? -EFAULT : 0;
1082 unsigned long sys32_mmap2(unsigned long addr, size_t len,
1083 unsigned long prot, unsigned long flags,
1084 unsigned long fd, unsigned long pgoff)
1086 /* This should remain 12 even if PAGE_SIZE changes */
1087 return sys_mmap(addr, len, prot, flags, fd, pgoff << 12);
1090 int get_compat_timeval(struct timeval *tv, struct compat_timeval __user *ctv)
1092 return (!access_ok(VERIFY_READ, ctv, sizeof(*ctv)) ||
1093 __get_user(tv->tv_sec, &ctv->tv_sec) ||
1094 __get_user(tv->tv_usec, &ctv->tv_usec)) ? -EFAULT : 0;
1097 asmlinkage long sys32_utimes(char __user *filename, struct compat_timeval __user *tvs)
1099 struct timeval ktvs[2], *ptr;
1103 if (get_compat_timeval(&ktvs[0], &tvs[0]) ||
1104 get_compat_timeval(&ktvs[1], &tvs[1]))
1109 return do_utimes(filename, ptr);
1112 long sys32_tgkill(u32 tgid, u32 pid, int sig)
1114 /* sign extend tgid, pid */
1115 return sys_tgkill((int)tgid, (int)pid, sig);
1119 * long long munging:
1120 * The 32 bit ABI passes long longs in an odd even register pair.
1123 compat_ssize_t sys32_pread64(unsigned int fd, char __user *ubuf, compat_size_t count,
1124 u32 reg6, u32 poshi, u32 poslo)
1126 return sys_pread64(fd, ubuf, count, ((loff_t)poshi << 32) | poslo);
1129 compat_ssize_t sys32_pwrite64(unsigned int fd, char __user *ubuf, compat_size_t count,
1130 u32 reg6, u32 poshi, u32 poslo)
1132 return sys_pwrite64(fd, ubuf, count, ((loff_t)poshi << 32) | poslo);
1135 compat_ssize_t sys32_readahead(int fd, u32 r4, u32 offhi, u32 offlo, u32 count)
1137 return sys_readahead(fd, ((loff_t)offhi << 32) | offlo, count);
1140 asmlinkage int sys32_truncate64(const char __user * path, u32 reg4,
1141 unsigned long high, unsigned long low)
1143 return sys_truncate(path, (high << 32) | low);
1146 asmlinkage int sys32_ftruncate64(unsigned int fd, u32 reg4, unsigned long high,
1149 return sys_ftruncate(fd, (high << 32) | low);
1152 long ppc32_lookup_dcookie(u32 cookie_high, u32 cookie_low, char __user *buf,
1155 return sys_lookup_dcookie((u64)cookie_high << 32 | cookie_low,
1159 long ppc32_fadvise64(int fd, u32 unused, u32 offset_high, u32 offset_low,
1160 size_t len, int advice)
1162 return sys_fadvise64(fd, (u64)offset_high << 32 | offset_low, len,
1166 long ppc32_fadvise64_64(int fd, int advice, u32 offset_high, u32 offset_low,
1167 u32 len_high, u32 len_low)
1169 return sys_fadvise64(fd, (u64)offset_high << 32 | offset_low,
1170 (u64)len_high << 32 | len_low, advice);
1173 long ppc32_timer_create(clockid_t clock,
1174 struct compat_sigevent __user *ev32,
1175 timer_t __user *timer_id)
1180 mm_segment_t savefs;
1183 return sys_timer_create(clock, NULL, timer_id);
1185 if (get_compat_sigevent(&event, ev32))
1188 if (!access_ok(VERIFY_WRITE, timer_id, sizeof(timer_t)))
1193 /* The __user pointer casts are valid due to the set_fs() */
1194 err = sys_timer_create(clock,
1195 (sigevent_t __user *) &event,
1196 (timer_t __user *) &t);
1200 err = __put_user(t, timer_id);
1205 asmlinkage long sys32_add_key(const char __user *_type,
1206 const char __user *_description,
1207 const void __user *_payload,
1211 return sys_add_key(_type, _description, _payload, plen, ringid);
1214 asmlinkage long sys32_request_key(const char __user *_type,
1215 const char __user *_description,
1216 const char __user *_callout_info,
1219 return sys_request_key(_type, _description, _callout_info, destringid);