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 /* Note: it is necessary to treat option as an unsigned int,
613 * with the corresponding cast to a signed int to insure that the
614 * proper conversion (sign extension) between the register representation of a signed int (msr in 32-bit mode)
615 * and the register representation of a signed int (msr in 64-bit mode) is performed.
617 asmlinkage long sys32_prctl(u32 option, u32 arg2, u32 arg3, u32 arg4, u32 arg5)
619 return sys_prctl((int)option,
620 (unsigned long) arg2,
621 (unsigned long) arg3,
622 (unsigned long) arg4,
623 (unsigned long) arg5);
626 /* Note: it is necessary to treat pid as an unsigned int,
627 * with the corresponding cast to a signed int to insure that the
628 * proper conversion (sign extension) between the register representation of a signed int (msr in 32-bit mode)
629 * and the register representation of a signed int (msr in 64-bit mode) is performed.
631 asmlinkage long sys32_sched_rr_get_interval(u32 pid, struct compat_timespec __user *interval)
635 mm_segment_t old_fs = get_fs ();
637 /* The __user pointer cast is valid because of the set_fs() */
639 ret = sys_sched_rr_get_interval((int)pid, (struct timespec __user *) &t);
641 if (put_compat_timespec(&t, interval))
646 asmlinkage int sys32_pciconfig_read(u32 bus, u32 dfn, u32 off, u32 len, u32 ubuf)
648 return sys_pciconfig_read((unsigned long) bus,
655 asmlinkage int sys32_pciconfig_write(u32 bus, u32 dfn, u32 off, u32 len, u32 ubuf)
657 return sys_pciconfig_write((unsigned long) bus,
664 asmlinkage int sys32_pciconfig_iobase(u32 which, u32 in_bus, u32 in_devfn)
666 return sys_pciconfig_iobase(which, in_bus, in_devfn);
670 /* Note: it is necessary to treat mode as an unsigned int,
671 * with the corresponding cast to a signed int to insure that the
672 * proper conversion (sign extension) between the register representation of a signed int (msr in 32-bit mode)
673 * and the register representation of a signed int (msr in 64-bit mode) is performed.
675 asmlinkage long sys32_access(const char __user * filename, u32 mode)
677 return sys_access(filename, (int)mode);
681 /* Note: it is necessary to treat mode as an unsigned int,
682 * with the corresponding cast to a signed int to insure that the
683 * proper conversion (sign extension) between the register representation of a signed int (msr in 32-bit mode)
684 * and the register representation of a signed int (msr in 64-bit mode) is performed.
686 asmlinkage long sys32_creat(const char __user * pathname, u32 mode)
688 return sys_creat(pathname, (int)mode);
692 /* Note: it is necessary to treat pid and options as unsigned ints,
693 * with the corresponding cast to a signed int to insure that the
694 * proper conversion (sign extension) between the register representation of a signed int (msr in 32-bit mode)
695 * and the register representation of a signed int (msr in 64-bit mode) is performed.
697 asmlinkage long sys32_waitpid(u32 pid, unsigned int __user * stat_addr, u32 options)
699 return sys_waitpid((int)pid, stat_addr, (int)options);
703 /* Note: it is necessary to treat gidsetsize as an unsigned int,
704 * with the corresponding cast to a signed int to insure that the
705 * proper conversion (sign extension) between the register representation of a signed int (msr in 32-bit mode)
706 * and the register representation of a signed int (msr in 64-bit mode) is performed.
708 asmlinkage long sys32_getgroups(u32 gidsetsize, gid_t __user *grouplist)
710 return sys_getgroups((int)gidsetsize, grouplist);
714 /* Note: it is necessary to treat pid as an unsigned int,
715 * with the corresponding cast to a signed int to insure that the
716 * proper conversion (sign extension) between the register representation of a signed int (msr in 32-bit mode)
717 * and the register representation of a signed int (msr in 64-bit mode) is performed.
719 asmlinkage long sys32_getpgid(u32 pid)
721 return sys_getpgid((int)pid);
726 /* Note: it is necessary to treat pid as an unsigned int,
727 * with the corresponding cast to a signed int to insure that the
728 * proper conversion (sign extension) between the register representation of a signed int (msr in 32-bit mode)
729 * and the register representation of a signed int (msr in 64-bit mode) is performed.
731 asmlinkage long sys32_getsid(u32 pid)
733 return sys_getsid((int)pid);
737 /* Note: it is necessary to treat pid and sig as unsigned ints,
738 * with the corresponding cast to a signed int to insure that the
739 * proper conversion (sign extension) between the register representation of a signed int (msr in 32-bit mode)
740 * and the register representation of a signed int (msr in 64-bit mode) is performed.
742 asmlinkage long sys32_kill(u32 pid, u32 sig)
744 return sys_kill((int)pid, (int)sig);
748 /* Note: it is necessary to treat mode as an unsigned int,
749 * with the corresponding cast to a signed int to insure that the
750 * proper conversion (sign extension) between the register representation of a signed int (msr in 32-bit mode)
751 * and the register representation of a signed int (msr in 64-bit mode) is performed.
753 asmlinkage long sys32_mkdir(const char __user * pathname, u32 mode)
755 return sys_mkdir(pathname, (int)mode);
758 long sys32_nice(u32 increment)
760 /* sign extend increment */
761 return sys_nice((int)increment);
764 off_t ppc32_lseek(unsigned int fd, u32 offset, unsigned int origin)
767 return sys_lseek(fd, (int)offset, origin);
770 /* Note: it is necessary to treat bufsiz as an unsigned int,
771 * with the corresponding cast to a signed int to insure that the
772 * proper conversion (sign extension) between the register representation of a signed int (msr in 32-bit mode)
773 * and the register representation of a signed int (msr in 64-bit mode) is performed.
775 asmlinkage long sys32_readlink(const char __user * path, char __user * buf, u32 bufsiz)
777 return sys_readlink(path, buf, (int)bufsiz);
780 /* Note: it is necessary to treat option as an unsigned int,
781 * with the corresponding cast to a signed int to insure that the
782 * proper conversion (sign extension) between the register representation of a signed int (msr in 32-bit mode)
783 * and the register representation of a signed int (msr in 64-bit mode) is performed.
785 asmlinkage long sys32_sched_get_priority_max(u32 policy)
787 return sys_sched_get_priority_max((int)policy);
791 /* Note: it is necessary to treat policy as an unsigned int,
792 * with the corresponding cast to a signed int to insure that the
793 * proper conversion (sign extension) between the register representation of a signed int (msr in 32-bit mode)
794 * and the register representation of a signed int (msr in 64-bit mode) is performed.
796 asmlinkage long sys32_sched_get_priority_min(u32 policy)
798 return sys_sched_get_priority_min((int)policy);
802 /* Note: it is necessary to treat pid as an unsigned int,
803 * with the corresponding cast to a signed int to insure that the
804 * proper conversion (sign extension) between the register representation of a signed int (msr in 32-bit mode)
805 * and the register representation of a signed int (msr in 64-bit mode) is performed.
807 asmlinkage long sys32_sched_getparam(u32 pid, struct sched_param __user *param)
809 return sys_sched_getparam((int)pid, param);
813 /* Note: it is necessary to treat pid as an unsigned int,
814 * with the corresponding cast to a signed int to insure that the
815 * proper conversion (sign extension) between the register representation of a signed int (msr in 32-bit mode)
816 * and the register representation of a signed int (msr in 64-bit mode) is performed.
818 asmlinkage long sys32_sched_getscheduler(u32 pid)
820 return sys_sched_getscheduler((int)pid);
824 /* Note: it is necessary to treat pid as an unsigned int,
825 * with the corresponding cast to a signed int to insure that the
826 * proper conversion (sign extension) between the register representation of a signed int (msr in 32-bit mode)
827 * and the register representation of a signed int (msr in 64-bit mode) is performed.
829 asmlinkage long sys32_sched_setparam(u32 pid, struct sched_param __user *param)
831 return sys_sched_setparam((int)pid, param);
835 /* Note: it is necessary to treat pid and policy as unsigned ints,
836 * with the corresponding cast to a signed int to insure that the
837 * proper conversion (sign extension) between the register representation of a signed int (msr in 32-bit mode)
838 * and the register representation of a signed int (msr in 64-bit mode) is performed.
840 asmlinkage long sys32_sched_setscheduler(u32 pid, u32 policy, struct sched_param __user *param)
842 return sys_sched_setscheduler((int)pid, (int)policy, param);
846 /* Note: it is necessary to treat len as an unsigned int,
847 * with the corresponding cast to a signed int to insure that the
848 * proper conversion (sign extension) between the register representation of a signed int (msr in 32-bit mode)
849 * and the register representation of a signed int (msr in 64-bit mode) is performed.
851 asmlinkage long sys32_setdomainname(char __user *name, u32 len)
853 return sys_setdomainname(name, (int)len);
857 /* Note: it is necessary to treat gidsetsize as an unsigned int,
858 * with the corresponding cast to a signed int to insure that the
859 * proper conversion (sign extension) between the register representation of a signed int (msr in 32-bit mode)
860 * and the register representation of a signed int (msr in 64-bit mode) is performed.
862 asmlinkage long sys32_setgroups(u32 gidsetsize, gid_t __user *grouplist)
864 return sys_setgroups((int)gidsetsize, grouplist);
868 asmlinkage long sys32_sethostname(char __user *name, u32 len)
870 /* sign extend len */
871 return sys_sethostname(name, (int)len);
875 /* Note: it is necessary to treat pid and pgid as unsigned ints,
876 * with the corresponding cast to a signed int to insure that the
877 * proper conversion (sign extension) between the register representation of a signed int (msr in 32-bit mode)
878 * and the register representation of a signed int (msr in 64-bit mode) is performed.
880 asmlinkage long sys32_setpgid(u32 pid, u32 pgid)
882 return sys_setpgid((int)pid, (int)pgid);
885 long sys32_getpriority(u32 which, u32 who)
887 /* sign extend which and who */
888 return sys_getpriority((int)which, (int)who);
891 long sys32_setpriority(u32 which, u32 who, u32 niceval)
893 /* sign extend which, who and niceval */
894 return sys_setpriority((int)which, (int)who, (int)niceval);
897 long sys32_ioprio_get(u32 which, u32 who)
899 /* sign extend which and who */
900 return sys_ioprio_get((int)which, (int)who);
903 long sys32_ioprio_set(u32 which, u32 who, u32 ioprio)
905 /* sign extend which, who and ioprio */
906 return sys_ioprio_set((int)which, (int)who, (int)ioprio);
909 /* Note: it is necessary to treat newmask as an unsigned int,
910 * with the corresponding cast to a signed int to insure that the
911 * proper conversion (sign extension) between the register representation of a signed int (msr in 32-bit mode)
912 * and the register representation of a signed int (msr in 64-bit mode) is performed.
914 asmlinkage long sys32_ssetmask(u32 newmask)
916 return sys_ssetmask((int) newmask);
919 asmlinkage long sys32_syslog(u32 type, char __user * buf, u32 len)
921 /* sign extend len */
922 return sys_syslog(type, buf, (int)len);
926 /* Note: it is necessary to treat mask as an unsigned int,
927 * with the corresponding cast to a signed int to insure that the
928 * proper conversion (sign extension) between the register representation of a signed int (msr in 32-bit mode)
929 * and the register representation of a signed int (msr in 64-bit mode) is performed.
931 asmlinkage long sys32_umask(u32 mask)
933 return sys_umask((int)mask);
937 struct __sysctl_args32 {
947 asmlinkage long sys32_sysctl(struct __sysctl_args32 __user *args)
949 struct __sysctl_args32 tmp;
952 size_t __user *oldlenp = NULL;
953 unsigned long addr = (((unsigned long)&args->__unused[0]) + 7) & ~7;
955 if (copy_from_user(&tmp, args, sizeof(tmp)))
958 if (tmp.oldval && tmp.oldlenp) {
959 /* Duh, this is ugly and might not work if sysctl_args
960 is in read-only memory, but do_sysctl does indirectly
961 a lot of uaccess in both directions and we'd have to
962 basically copy the whole sysctl.c here, and
963 glibc's __sysctl uses rw memory for the structure
965 oldlenp = (size_t __user *)addr;
966 if (get_user(oldlen, (compat_size_t __user *)compat_ptr(tmp.oldlenp)) ||
967 put_user(oldlen, oldlenp))
972 error = do_sysctl(compat_ptr(tmp.name), tmp.nlen,
973 compat_ptr(tmp.oldval), oldlenp,
974 compat_ptr(tmp.newval), tmp.newlen);
978 if (get_user(oldlen, oldlenp) ||
979 put_user(oldlen, (compat_size_t __user *)compat_ptr(tmp.oldlenp)))
982 copy_to_user(args->__unused, tmp.__unused, sizeof(tmp.__unused));
988 unsigned long sys32_mmap2(unsigned long addr, size_t len,
989 unsigned long prot, unsigned long flags,
990 unsigned long fd, unsigned long pgoff)
992 /* This should remain 12 even if PAGE_SIZE changes */
993 return sys_mmap(addr, len, prot, flags, fd, pgoff << 12);
996 int get_compat_timeval(struct timeval *tv, struct compat_timeval __user *ctv)
998 return (!access_ok(VERIFY_READ, ctv, sizeof(*ctv)) ||
999 __get_user(tv->tv_sec, &ctv->tv_sec) ||
1000 __get_user(tv->tv_usec, &ctv->tv_usec)) ? -EFAULT : 0;
1003 asmlinkage long sys32_utimes(char __user *filename, struct compat_timeval __user *tvs)
1005 struct timeval ktvs[2], *ptr;
1009 if (get_compat_timeval(&ktvs[0], &tvs[0]) ||
1010 get_compat_timeval(&ktvs[1], &tvs[1]))
1015 return do_utimes(filename, ptr);
1018 long sys32_tgkill(u32 tgid, u32 pid, int sig)
1020 /* sign extend tgid, pid */
1021 return sys_tgkill((int)tgid, (int)pid, sig);
1025 * long long munging:
1026 * The 32 bit ABI passes long longs in an odd even register pair.
1029 compat_ssize_t sys32_pread64(unsigned int fd, char __user *ubuf, compat_size_t count,
1030 u32 reg6, u32 poshi, u32 poslo)
1032 return sys_pread64(fd, ubuf, count, ((loff_t)poshi << 32) | poslo);
1035 compat_ssize_t sys32_pwrite64(unsigned int fd, char __user *ubuf, compat_size_t count,
1036 u32 reg6, u32 poshi, u32 poslo)
1038 return sys_pwrite64(fd, ubuf, count, ((loff_t)poshi << 32) | poslo);
1041 compat_ssize_t sys32_readahead(int fd, u32 r4, u32 offhi, u32 offlo, u32 count)
1043 return sys_readahead(fd, ((loff_t)offhi << 32) | offlo, count);
1046 asmlinkage int sys32_truncate64(const char __user * path, u32 reg4,
1047 unsigned long high, unsigned long low)
1049 return sys_truncate(path, (high << 32) | low);
1052 asmlinkage int sys32_ftruncate64(unsigned int fd, u32 reg4, unsigned long high,
1055 return sys_ftruncate(fd, (high << 32) | low);
1058 long ppc32_lookup_dcookie(u32 cookie_high, u32 cookie_low, char __user *buf,
1061 return sys_lookup_dcookie((u64)cookie_high << 32 | cookie_low,
1065 long ppc32_fadvise64(int fd, u32 unused, u32 offset_high, u32 offset_low,
1066 size_t len, int advice)
1068 return sys_fadvise64(fd, (u64)offset_high << 32 | offset_low, len,
1072 long ppc32_timer_create(clockid_t clock,
1073 struct compat_sigevent __user *ev32,
1074 timer_t __user *timer_id)
1079 mm_segment_t savefs;
1082 return sys_timer_create(clock, NULL, timer_id);
1084 if (get_compat_sigevent(&event, ev32))
1087 if (!access_ok(VERIFY_WRITE, timer_id, sizeof(timer_t)))
1092 /* The __user pointer casts are valid due to the set_fs() */
1093 err = sys_timer_create(clock,
1094 (sigevent_t __user *) &event,
1095 (timer_t __user *) &t);
1099 err = __put_user(t, timer_id);
1104 asmlinkage long sys32_add_key(const char __user *_type,
1105 const char __user *_description,
1106 const void __user *_payload,
1110 return sys_add_key(_type, _description, _payload, plen, ringid);
1113 asmlinkage long sys32_request_key(const char __user *_type,
1114 const char __user *_description,
1115 const char __user *_callout_info,
1118 return sys_request_key(_type, _description, _callout_info, destringid);