xref: /openbmc/linux/arch/mips/kernel/linux32.c (revision f3468e0c34c8de919062582575a01e2434c8e727)
11da177e4SLinus Torvalds /*
21da177e4SLinus Torvalds  * Conversion between 32-bit and 64-bit native system calls.
31da177e4SLinus Torvalds  *
41da177e4SLinus Torvalds  * Copyright (C) 2000 Silicon Graphics, Inc.
51da177e4SLinus Torvalds  * Written by Ulf Carlsson (ulfc@engr.sgi.com)
61da177e4SLinus Torvalds  * sys32_execve from ia64/ia32 code, Feb 2000, Kanoj Sarcar (kanoj@sgi.com)
71da177e4SLinus Torvalds  */
81da177e4SLinus Torvalds #include <linux/config.h>
91da177e4SLinus Torvalds #include <linux/compiler.h>
101da177e4SLinus Torvalds #include <linux/mm.h>
111da177e4SLinus Torvalds #include <linux/errno.h>
121da177e4SLinus Torvalds #include <linux/file.h>
131da177e4SLinus Torvalds #include <linux/smp_lock.h>
141da177e4SLinus Torvalds #include <linux/highuid.h>
151da177e4SLinus Torvalds #include <linux/dirent.h>
161da177e4SLinus Torvalds #include <linux/resource.h>
171da177e4SLinus Torvalds #include <linux/highmem.h>
181da177e4SLinus Torvalds #include <linux/time.h>
191da177e4SLinus Torvalds #include <linux/times.h>
201da177e4SLinus Torvalds #include <linux/poll.h>
211da177e4SLinus Torvalds #include <linux/slab.h>
221da177e4SLinus Torvalds #include <linux/skbuff.h>
231da177e4SLinus Torvalds #include <linux/filter.h>
241da177e4SLinus Torvalds #include <linux/shm.h>
251da177e4SLinus Torvalds #include <linux/sem.h>
261da177e4SLinus Torvalds #include <linux/msg.h>
271da177e4SLinus Torvalds #include <linux/icmpv6.h>
281da177e4SLinus Torvalds #include <linux/syscalls.h>
291da177e4SLinus Torvalds #include <linux/sysctl.h>
301da177e4SLinus Torvalds #include <linux/utime.h>
311da177e4SLinus Torvalds #include <linux/utsname.h>
321da177e4SLinus Torvalds #include <linux/personality.h>
331da177e4SLinus Torvalds #include <linux/timex.h>
341da177e4SLinus Torvalds #include <linux/dnotify.h>
351da177e4SLinus Torvalds #include <linux/module.h>
361da177e4SLinus Torvalds #include <linux/binfmts.h>
371da177e4SLinus Torvalds #include <linux/security.h>
381da177e4SLinus Torvalds #include <linux/compat.h>
391da177e4SLinus Torvalds #include <linux/vfs.h>
401da177e4SLinus Torvalds 
411da177e4SLinus Torvalds #include <net/sock.h>
421da177e4SLinus Torvalds #include <net/scm.h>
431da177e4SLinus Torvalds 
441da177e4SLinus Torvalds #include <asm/ipc.h>
451da177e4SLinus Torvalds #include <asm/sim.h>
461da177e4SLinus Torvalds #include <asm/uaccess.h>
471da177e4SLinus Torvalds #include <asm/mmu_context.h>
481da177e4SLinus Torvalds #include <asm/mman.h>
491da177e4SLinus Torvalds 
501da177e4SLinus Torvalds /* Use this to get at 32-bit user passed pointers. */
511da177e4SLinus Torvalds /* A() macro should be used for places where you e.g.
521da177e4SLinus Torvalds    have some internal variable u32 and just want to get
531da177e4SLinus Torvalds    rid of a compiler warning. AA() has to be used in
541da177e4SLinus Torvalds    places where you want to convert a function argument
551da177e4SLinus Torvalds    to 32bit pointer or when you e.g. access pt_regs
561da177e4SLinus Torvalds    structure and want to consider 32bit registers only.
571da177e4SLinus Torvalds  */
581da177e4SLinus Torvalds #define A(__x) ((unsigned long)(__x))
591da177e4SLinus Torvalds #define AA(__x) ((unsigned long)((int)__x))
601da177e4SLinus Torvalds 
611da177e4SLinus Torvalds #ifdef __MIPSEB__
621da177e4SLinus Torvalds #define merge_64(r1,r2)	((((r1) & 0xffffffffUL) << 32) + ((r2) & 0xffffffffUL))
631da177e4SLinus Torvalds #endif
641da177e4SLinus Torvalds #ifdef __MIPSEL__
651da177e4SLinus Torvalds #define merge_64(r1,r2)	((((r2) & 0xffffffffUL) << 32) + ((r1) & 0xffffffffUL))
661da177e4SLinus Torvalds #endif
671da177e4SLinus Torvalds 
681da177e4SLinus Torvalds /*
691da177e4SLinus Torvalds  * Revalidate the inode. This is required for proper NFS attribute caching.
701da177e4SLinus Torvalds  */
711da177e4SLinus Torvalds 
721da177e4SLinus Torvalds int cp_compat_stat(struct kstat *stat, struct compat_stat *statbuf)
731da177e4SLinus Torvalds {
741da177e4SLinus Torvalds 	struct compat_stat tmp;
751da177e4SLinus Torvalds 
761da177e4SLinus Torvalds 	if (!new_valid_dev(stat->dev) || !new_valid_dev(stat->rdev))
771da177e4SLinus Torvalds 		return -EOVERFLOW;
781da177e4SLinus Torvalds 
791da177e4SLinus Torvalds 	memset(&tmp, 0, sizeof(tmp));
801da177e4SLinus Torvalds 	tmp.st_dev = new_encode_dev(stat->dev);
811da177e4SLinus Torvalds 	tmp.st_ino = stat->ino;
821da177e4SLinus Torvalds 	tmp.st_mode = stat->mode;
831da177e4SLinus Torvalds 	tmp.st_nlink = stat->nlink;
841da177e4SLinus Torvalds 	SET_UID(tmp.st_uid, stat->uid);
851da177e4SLinus Torvalds 	SET_GID(tmp.st_gid, stat->gid);
861da177e4SLinus Torvalds 	tmp.st_rdev = new_encode_dev(stat->rdev);
871da177e4SLinus Torvalds 	tmp.st_size = stat->size;
881da177e4SLinus Torvalds 	tmp.st_atime = stat->atime.tv_sec;
891da177e4SLinus Torvalds 	tmp.st_mtime = stat->mtime.tv_sec;
901da177e4SLinus Torvalds 	tmp.st_ctime = stat->ctime.tv_sec;
911da177e4SLinus Torvalds #ifdef STAT_HAVE_NSEC
921da177e4SLinus Torvalds 	tmp.st_atime_nsec = stat->atime.tv_nsec;
931da177e4SLinus Torvalds 	tmp.st_mtime_nsec = stat->mtime.tv_nsec;
941da177e4SLinus Torvalds 	tmp.st_ctime_nsec = stat->ctime.tv_nsec;
951da177e4SLinus Torvalds #endif
961da177e4SLinus Torvalds 	tmp.st_blocks = stat->blocks;
971da177e4SLinus Torvalds 	tmp.st_blksize = stat->blksize;
981da177e4SLinus Torvalds 	return copy_to_user(statbuf,&tmp,sizeof(tmp)) ? -EFAULT : 0;
991da177e4SLinus Torvalds }
1001da177e4SLinus Torvalds 
1011da177e4SLinus Torvalds asmlinkage unsigned long
1021da177e4SLinus Torvalds sys32_mmap2(unsigned long addr, unsigned long len, unsigned long prot,
1031da177e4SLinus Torvalds          unsigned long flags, unsigned long fd, unsigned long pgoff)
1041da177e4SLinus Torvalds {
1051da177e4SLinus Torvalds 	struct file * file = NULL;
1061da177e4SLinus Torvalds 	unsigned long error;
1071da177e4SLinus Torvalds 
1081da177e4SLinus Torvalds 	error = -EINVAL;
1091da177e4SLinus Torvalds 	if (!(flags & MAP_ANONYMOUS)) {
1101da177e4SLinus Torvalds 		error = -EBADF;
1111da177e4SLinus Torvalds 		file = fget(fd);
1121da177e4SLinus Torvalds 		if (!file)
1131da177e4SLinus Torvalds 			goto out;
1141da177e4SLinus Torvalds 	}
1151da177e4SLinus Torvalds 	flags &= ~(MAP_EXECUTABLE | MAP_DENYWRITE);
1161da177e4SLinus Torvalds 
1171da177e4SLinus Torvalds 	down_write(&current->mm->mmap_sem);
1181da177e4SLinus Torvalds 	error = do_mmap_pgoff(file, addr, len, prot, flags, pgoff);
1191da177e4SLinus Torvalds 	up_write(&current->mm->mmap_sem);
1201da177e4SLinus Torvalds 	if (file)
1211da177e4SLinus Torvalds 		fput(file);
1221da177e4SLinus Torvalds 
1231da177e4SLinus Torvalds out:
1241da177e4SLinus Torvalds 	return error;
1251da177e4SLinus Torvalds }
1261da177e4SLinus Torvalds 
1271da177e4SLinus Torvalds 
1281da177e4SLinus Torvalds asmlinkage int sys_truncate64(const char *path, unsigned int high,
1291da177e4SLinus Torvalds 			      unsigned int low)
1301da177e4SLinus Torvalds {
1311da177e4SLinus Torvalds 	if ((int)high < 0)
1321da177e4SLinus Torvalds 		return -EINVAL;
1331da177e4SLinus Torvalds 	return sys_truncate(path, ((long) high << 32) | low);
1341da177e4SLinus Torvalds }
1351da177e4SLinus Torvalds 
1361da177e4SLinus Torvalds asmlinkage int sys_ftruncate64(unsigned int fd, unsigned int high,
1371da177e4SLinus Torvalds 			       unsigned int low)
1381da177e4SLinus Torvalds {
1391da177e4SLinus Torvalds 	if ((int)high < 0)
1401da177e4SLinus Torvalds 		return -EINVAL;
1411da177e4SLinus Torvalds 	return sys_ftruncate(fd, ((long) high << 32) | low);
1421da177e4SLinus Torvalds }
1431da177e4SLinus Torvalds 
1441da177e4SLinus Torvalds /*
1451da177e4SLinus Torvalds  * sys_execve() executes a new program.
1461da177e4SLinus Torvalds  */
1471da177e4SLinus Torvalds asmlinkage int sys32_execve(nabi_no_regargs struct pt_regs regs)
1481da177e4SLinus Torvalds {
1491da177e4SLinus Torvalds 	int error;
1501da177e4SLinus Torvalds 	char * filename;
1511da177e4SLinus Torvalds 
1521da177e4SLinus Torvalds 	filename = getname(compat_ptr(regs.regs[4]));
1531da177e4SLinus Torvalds 	error = PTR_ERR(filename);
1541da177e4SLinus Torvalds 	if (IS_ERR(filename))
1551da177e4SLinus Torvalds 		goto out;
1561da177e4SLinus Torvalds 	error = compat_do_execve(filename, compat_ptr(regs.regs[5]),
1571da177e4SLinus Torvalds 				 compat_ptr(regs.regs[6]), &regs);
1581da177e4SLinus Torvalds 	putname(filename);
1591da177e4SLinus Torvalds 
1601da177e4SLinus Torvalds out:
1611da177e4SLinus Torvalds 	return error;
1621da177e4SLinus Torvalds }
1631da177e4SLinus Torvalds 
1641da177e4SLinus Torvalds struct dirent32 {
1651da177e4SLinus Torvalds 	unsigned int	d_ino;
1661da177e4SLinus Torvalds 	unsigned int	d_off;
1671da177e4SLinus Torvalds 	unsigned short	d_reclen;
1681da177e4SLinus Torvalds 	char		d_name[NAME_MAX + 1];
1691da177e4SLinus Torvalds };
1701da177e4SLinus Torvalds 
1711da177e4SLinus Torvalds static void
1721da177e4SLinus Torvalds xlate_dirent(void *dirent64, void *dirent32, long n)
1731da177e4SLinus Torvalds {
1741da177e4SLinus Torvalds 	long off;
1751da177e4SLinus Torvalds 	struct dirent *dirp;
1761da177e4SLinus Torvalds 	struct dirent32 *dirp32;
1771da177e4SLinus Torvalds 
1781da177e4SLinus Torvalds 	off = 0;
1791da177e4SLinus Torvalds 	while (off < n) {
1801da177e4SLinus Torvalds 		dirp = (struct dirent *)(dirent64 + off);
1811da177e4SLinus Torvalds 		dirp32 = (struct dirent32 *)(dirent32 + off);
1821da177e4SLinus Torvalds 		off += dirp->d_reclen;
1831da177e4SLinus Torvalds 		dirp32->d_ino = dirp->d_ino;
1841da177e4SLinus Torvalds 		dirp32->d_off = (unsigned int)dirp->d_off;
1851da177e4SLinus Torvalds 		dirp32->d_reclen = dirp->d_reclen;
1861da177e4SLinus Torvalds 		strncpy(dirp32->d_name, dirp->d_name, dirp->d_reclen - ((3 * 4) + 2));
1871da177e4SLinus Torvalds 	}
1881da177e4SLinus Torvalds 	return;
1891da177e4SLinus Torvalds }
1901da177e4SLinus Torvalds 
1911da177e4SLinus Torvalds asmlinkage long
1921da177e4SLinus Torvalds sys32_getdents(unsigned int fd, void * dirent32, unsigned int count)
1931da177e4SLinus Torvalds {
1941da177e4SLinus Torvalds 	long n;
1951da177e4SLinus Torvalds 	void *dirent64;
1961da177e4SLinus Torvalds 
1971da177e4SLinus Torvalds 	dirent64 = (void *)((unsigned long)(dirent32 + (sizeof(long) - 1)) & ~(sizeof(long) - 1));
1981da177e4SLinus Torvalds 	if ((n = sys_getdents(fd, dirent64, count - (dirent64 - dirent32))) < 0)
1991da177e4SLinus Torvalds 		return(n);
2001da177e4SLinus Torvalds 	xlate_dirent(dirent64, dirent32, n);
2011da177e4SLinus Torvalds 	return(n);
2021da177e4SLinus Torvalds }
2031da177e4SLinus Torvalds 
2041da177e4SLinus Torvalds asmlinkage int old_readdir(unsigned int fd, void * dirent, unsigned int count);
2051da177e4SLinus Torvalds 
2061da177e4SLinus Torvalds asmlinkage int
2071da177e4SLinus Torvalds sys32_readdir(unsigned int fd, void * dirent32, unsigned int count)
2081da177e4SLinus Torvalds {
2091da177e4SLinus Torvalds 	int n;
2101da177e4SLinus Torvalds 	struct dirent dirent64;
2111da177e4SLinus Torvalds 
2121da177e4SLinus Torvalds 	if ((n = old_readdir(fd, &dirent64, count)) < 0)
2131da177e4SLinus Torvalds 		return(n);
2141da177e4SLinus Torvalds 	xlate_dirent(&dirent64, dirent32, dirent64.d_reclen);
2151da177e4SLinus Torvalds 	return(n);
2161da177e4SLinus Torvalds }
2171da177e4SLinus Torvalds 
2181da177e4SLinus Torvalds asmlinkage int
2191da177e4SLinus Torvalds sys32_waitpid(compat_pid_t pid, unsigned int *stat_addr, int options)
2201da177e4SLinus Torvalds {
221b6e203d8SRalf Baechle 	return compat_sys_wait4(pid, stat_addr, options, NULL);
2221da177e4SLinus Torvalds }
2231da177e4SLinus Torvalds 
22454f2da75SRalf Baechle asmlinkage long
22554f2da75SRalf Baechle sysn32_waitid(int which, compat_pid_t pid,
22654f2da75SRalf Baechle 	      siginfo_t __user *uinfo, int options,
22754f2da75SRalf Baechle 	      struct compat_rusage __user *uru)
22854f2da75SRalf Baechle {
22954f2da75SRalf Baechle 	struct rusage ru;
23054f2da75SRalf Baechle 	long ret;
23154f2da75SRalf Baechle 	mm_segment_t old_fs = get_fs();
23254f2da75SRalf Baechle 
233*f3468e0cSRalf Baechle 	if (!access_ok(VERIFY_WRITE, uinfo, sizeof(*uinfo)))
234*f3468e0cSRalf Baechle 		return -EFAULT;
235*f3468e0cSRalf Baechle 
23654f2da75SRalf Baechle 	set_fs (KERNEL_DS);
23754f2da75SRalf Baechle 	ret = sys_waitid(which, pid, uinfo, options,
23854f2da75SRalf Baechle 			 uru ? (struct rusage __user *) &ru : NULL);
23954f2da75SRalf Baechle 	set_fs (old_fs);
24054f2da75SRalf Baechle 
24154f2da75SRalf Baechle 	if (ret < 0 || uinfo->si_signo == 0)
24254f2da75SRalf Baechle 		return ret;
24354f2da75SRalf Baechle 
24454f2da75SRalf Baechle 	if (uru)
24554f2da75SRalf Baechle 		ret = put_compat_rusage(&ru, uru);
24654f2da75SRalf Baechle 	return ret;
24754f2da75SRalf Baechle }
24854f2da75SRalf Baechle 
2491da177e4SLinus Torvalds struct sysinfo32 {
2501da177e4SLinus Torvalds         s32 uptime;
2511da177e4SLinus Torvalds         u32 loads[3];
2521da177e4SLinus Torvalds         u32 totalram;
2531da177e4SLinus Torvalds         u32 freeram;
2541da177e4SLinus Torvalds         u32 sharedram;
2551da177e4SLinus Torvalds         u32 bufferram;
2561da177e4SLinus Torvalds         u32 totalswap;
2571da177e4SLinus Torvalds         u32 freeswap;
2581da177e4SLinus Torvalds         u16 procs;
2591da177e4SLinus Torvalds 	u32 totalhigh;
2601da177e4SLinus Torvalds 	u32 freehigh;
2611da177e4SLinus Torvalds 	u32 mem_unit;
2621da177e4SLinus Torvalds 	char _f[8];
2631da177e4SLinus Torvalds };
2641da177e4SLinus Torvalds 
2651da177e4SLinus Torvalds asmlinkage int sys32_sysinfo(struct sysinfo32 *info)
2661da177e4SLinus Torvalds {
2671da177e4SLinus Torvalds 	struct sysinfo s;
2681da177e4SLinus Torvalds 	int ret, err;
2691da177e4SLinus Torvalds 	mm_segment_t old_fs = get_fs ();
2701da177e4SLinus Torvalds 
2711da177e4SLinus Torvalds 	set_fs (KERNEL_DS);
2721da177e4SLinus Torvalds 	ret = sys_sysinfo(&s);
2731da177e4SLinus Torvalds 	set_fs (old_fs);
2741da177e4SLinus Torvalds 	err = put_user (s.uptime, &info->uptime);
2751da177e4SLinus Torvalds 	err |= __put_user (s.loads[0], &info->loads[0]);
2761da177e4SLinus Torvalds 	err |= __put_user (s.loads[1], &info->loads[1]);
2771da177e4SLinus Torvalds 	err |= __put_user (s.loads[2], &info->loads[2]);
2781da177e4SLinus Torvalds 	err |= __put_user (s.totalram, &info->totalram);
2791da177e4SLinus Torvalds 	err |= __put_user (s.freeram, &info->freeram);
2801da177e4SLinus Torvalds 	err |= __put_user (s.sharedram, &info->sharedram);
2811da177e4SLinus Torvalds 	err |= __put_user (s.bufferram, &info->bufferram);
2821da177e4SLinus Torvalds 	err |= __put_user (s.totalswap, &info->totalswap);
2831da177e4SLinus Torvalds 	err |= __put_user (s.freeswap, &info->freeswap);
2841da177e4SLinus Torvalds 	err |= __put_user (s.procs, &info->procs);
2851da177e4SLinus Torvalds 	err |= __put_user (s.totalhigh, &info->totalhigh);
2861da177e4SLinus Torvalds 	err |= __put_user (s.freehigh, &info->freehigh);
2871da177e4SLinus Torvalds 	err |= __put_user (s.mem_unit, &info->mem_unit);
2881da177e4SLinus Torvalds 	if (err)
2891da177e4SLinus Torvalds 		return -EFAULT;
2901da177e4SLinus Torvalds 	return ret;
2911da177e4SLinus Torvalds }
2921da177e4SLinus Torvalds 
2931da177e4SLinus Torvalds #define RLIM_INFINITY32	0x7fffffff
2941da177e4SLinus Torvalds #define RESOURCE32(x) ((x > RLIM_INFINITY32) ? RLIM_INFINITY32 : x)
2951da177e4SLinus Torvalds 
2961da177e4SLinus Torvalds struct rlimit32 {
2971da177e4SLinus Torvalds 	int	rlim_cur;
2981da177e4SLinus Torvalds 	int	rlim_max;
2991da177e4SLinus Torvalds };
3001da177e4SLinus Torvalds 
3011da177e4SLinus Torvalds #ifdef __MIPSEB__
3021da177e4SLinus Torvalds asmlinkage long sys32_truncate64(const char * path, unsigned long __dummy,
3031da177e4SLinus Torvalds 	int length_hi, int length_lo)
3041da177e4SLinus Torvalds #endif
3051da177e4SLinus Torvalds #ifdef __MIPSEL__
3061da177e4SLinus Torvalds asmlinkage long sys32_truncate64(const char * path, unsigned long __dummy,
3071da177e4SLinus Torvalds 	int length_lo, int length_hi)
3081da177e4SLinus Torvalds #endif
3091da177e4SLinus Torvalds {
3101da177e4SLinus Torvalds 	loff_t length;
3111da177e4SLinus Torvalds 
3121da177e4SLinus Torvalds 	length = ((unsigned long) length_hi << 32) | (unsigned int) length_lo;
3131da177e4SLinus Torvalds 
3141da177e4SLinus Torvalds 	return sys_truncate(path, length);
3151da177e4SLinus Torvalds }
3161da177e4SLinus Torvalds 
3171da177e4SLinus Torvalds #ifdef __MIPSEB__
3181da177e4SLinus Torvalds asmlinkage long sys32_ftruncate64(unsigned int fd, unsigned long __dummy,
3191da177e4SLinus Torvalds 	int length_hi, int length_lo)
3201da177e4SLinus Torvalds #endif
3211da177e4SLinus Torvalds #ifdef __MIPSEL__
3221da177e4SLinus Torvalds asmlinkage long sys32_ftruncate64(unsigned int fd, unsigned long __dummy,
3231da177e4SLinus Torvalds 	int length_lo, int length_hi)
3241da177e4SLinus Torvalds #endif
3251da177e4SLinus Torvalds {
3261da177e4SLinus Torvalds 	loff_t length;
3271da177e4SLinus Torvalds 
3281da177e4SLinus Torvalds 	length = ((unsigned long) length_hi << 32) | (unsigned int) length_lo;
3291da177e4SLinus Torvalds 
3301da177e4SLinus Torvalds 	return sys_ftruncate(fd, length);
3311da177e4SLinus Torvalds }
3321da177e4SLinus Torvalds 
3331da177e4SLinus Torvalds static inline long
3341da177e4SLinus Torvalds get_tv32(struct timeval *o, struct compat_timeval *i)
3351da177e4SLinus Torvalds {
3361da177e4SLinus Torvalds 	return (!access_ok(VERIFY_READ, i, sizeof(*i)) ||
3371da177e4SLinus Torvalds 		(__get_user(o->tv_sec, &i->tv_sec) |
3381da177e4SLinus Torvalds 		 __get_user(o->tv_usec, &i->tv_usec)));
3391da177e4SLinus Torvalds }
3401da177e4SLinus Torvalds 
3411da177e4SLinus Torvalds static inline long
3421da177e4SLinus Torvalds put_tv32(struct compat_timeval *o, struct timeval *i)
3431da177e4SLinus Torvalds {
3441da177e4SLinus Torvalds 	return (!access_ok(VERIFY_WRITE, o, sizeof(*o)) ||
3451da177e4SLinus Torvalds 		(__put_user(i->tv_sec, &o->tv_sec) |
3461da177e4SLinus Torvalds 		 __put_user(i->tv_usec, &o->tv_usec)));
3471da177e4SLinus Torvalds }
3481da177e4SLinus Torvalds 
3491da177e4SLinus Torvalds extern struct timezone sys_tz;
3501da177e4SLinus Torvalds 
3511da177e4SLinus Torvalds asmlinkage int
3521da177e4SLinus Torvalds sys32_gettimeofday(struct compat_timeval *tv, struct timezone *tz)
3531da177e4SLinus Torvalds {
3541da177e4SLinus Torvalds 	if (tv) {
3551da177e4SLinus Torvalds 		struct timeval ktv;
3561da177e4SLinus Torvalds 		do_gettimeofday(&ktv);
3571da177e4SLinus Torvalds 		if (put_tv32(tv, &ktv))
3581da177e4SLinus Torvalds 			return -EFAULT;
3591da177e4SLinus Torvalds 	}
3601da177e4SLinus Torvalds 	if (tz) {
3611da177e4SLinus Torvalds 		if (copy_to_user(tz, &sys_tz, sizeof(sys_tz)))
3621da177e4SLinus Torvalds 			return -EFAULT;
3631da177e4SLinus Torvalds 	}
3641da177e4SLinus Torvalds 	return 0;
3651da177e4SLinus Torvalds }
3661da177e4SLinus Torvalds 
3671da177e4SLinus Torvalds static inline long get_ts32(struct timespec *o, struct compat_timeval *i)
3681da177e4SLinus Torvalds {
3691da177e4SLinus Torvalds 	long usec;
3701da177e4SLinus Torvalds 
3711da177e4SLinus Torvalds 	if (!access_ok(VERIFY_READ, i, sizeof(*i)))
3721da177e4SLinus Torvalds 		return -EFAULT;
3731da177e4SLinus Torvalds 	if (__get_user(o->tv_sec, &i->tv_sec))
3741da177e4SLinus Torvalds 		return -EFAULT;
3751da177e4SLinus Torvalds 	if (__get_user(usec, &i->tv_usec))
3761da177e4SLinus Torvalds 		return -EFAULT;
3771da177e4SLinus Torvalds 	o->tv_nsec = usec * 1000;
3781da177e4SLinus Torvalds 		return 0;
3791da177e4SLinus Torvalds }
3801da177e4SLinus Torvalds 
3811da177e4SLinus Torvalds asmlinkage int
3821da177e4SLinus Torvalds sys32_settimeofday(struct compat_timeval *tv, struct timezone *tz)
3831da177e4SLinus Torvalds {
3841da177e4SLinus Torvalds 	struct timespec kts;
3851da177e4SLinus Torvalds 	struct timezone ktz;
3861da177e4SLinus Torvalds 
3871da177e4SLinus Torvalds  	if (tv) {
3881da177e4SLinus Torvalds 		if (get_ts32(&kts, tv))
3891da177e4SLinus Torvalds 			return -EFAULT;
3901da177e4SLinus Torvalds 	}
3911da177e4SLinus Torvalds 	if (tz) {
3921da177e4SLinus Torvalds 		if (copy_from_user(&ktz, tz, sizeof(ktz)))
3931da177e4SLinus Torvalds 			return -EFAULT;
3941da177e4SLinus Torvalds 	}
3951da177e4SLinus Torvalds 
3961da177e4SLinus Torvalds 	return do_sys_settimeofday(tv ? &kts : NULL, tz ? &ktz : NULL);
3971da177e4SLinus Torvalds }
3981da177e4SLinus Torvalds 
3991da177e4SLinus Torvalds asmlinkage int sys32_llseek(unsigned int fd, unsigned int offset_high,
4001da177e4SLinus Torvalds 			    unsigned int offset_low, loff_t * result,
4011da177e4SLinus Torvalds 			    unsigned int origin)
4021da177e4SLinus Torvalds {
4031da177e4SLinus Torvalds 	return sys_llseek(fd, offset_high, offset_low, result, origin);
4041da177e4SLinus Torvalds }
4051da177e4SLinus Torvalds 
4061da177e4SLinus Torvalds /* From the Single Unix Spec: pread & pwrite act like lseek to pos + op +
4071da177e4SLinus Torvalds    lseek back to original location.  They fail just like lseek does on
4081da177e4SLinus Torvalds    non-seekable files.  */
4091da177e4SLinus Torvalds 
4101da177e4SLinus Torvalds asmlinkage ssize_t sys32_pread(unsigned int fd, char * buf,
4111da177e4SLinus Torvalds 			       size_t count, u32 unused, u64 a4, u64 a5)
4121da177e4SLinus Torvalds {
4131da177e4SLinus Torvalds 	ssize_t ret;
4141da177e4SLinus Torvalds 	struct file * file;
4151da177e4SLinus Torvalds 	ssize_t (*read)(struct file *, char *, size_t, loff_t *);
4161da177e4SLinus Torvalds 	loff_t pos;
4171da177e4SLinus Torvalds 
4181da177e4SLinus Torvalds 	ret = -EBADF;
4191da177e4SLinus Torvalds 	file = fget(fd);
4201da177e4SLinus Torvalds 	if (!file)
4211da177e4SLinus Torvalds 		goto bad_file;
4221da177e4SLinus Torvalds 	if (!(file->f_mode & FMODE_READ))
4231da177e4SLinus Torvalds 		goto out;
4241da177e4SLinus Torvalds 	pos = merge_64(a4, a5);
4251da177e4SLinus Torvalds 	ret = rw_verify_area(READ, file, &pos, count);
426e28cc715SLinus Torvalds 	if (ret < 0)
4271da177e4SLinus Torvalds 		goto out;
4281da177e4SLinus Torvalds 	ret = -EINVAL;
4291da177e4SLinus Torvalds 	if (!file->f_op || !(read = file->f_op->read))
4301da177e4SLinus Torvalds 		goto out;
4311da177e4SLinus Torvalds 	if (pos < 0)
4321da177e4SLinus Torvalds 		goto out;
4331da177e4SLinus Torvalds 	ret = -ESPIPE;
4341da177e4SLinus Torvalds 	if (!(file->f_mode & FMODE_PREAD))
4351da177e4SLinus Torvalds 		goto out;
4361da177e4SLinus Torvalds 	ret = read(file, buf, count, &pos);
4371da177e4SLinus Torvalds 	if (ret > 0)
4381da177e4SLinus Torvalds 		dnotify_parent(file->f_dentry, DN_ACCESS);
4391da177e4SLinus Torvalds out:
4401da177e4SLinus Torvalds 	fput(file);
4411da177e4SLinus Torvalds bad_file:
4421da177e4SLinus Torvalds 	return ret;
4431da177e4SLinus Torvalds }
4441da177e4SLinus Torvalds 
4451da177e4SLinus Torvalds asmlinkage ssize_t sys32_pwrite(unsigned int fd, const char * buf,
4461da177e4SLinus Torvalds 			        size_t count, u32 unused, u64 a4, u64 a5)
4471da177e4SLinus Torvalds {
4481da177e4SLinus Torvalds 	ssize_t ret;
4491da177e4SLinus Torvalds 	struct file * file;
4501da177e4SLinus Torvalds 	ssize_t (*write)(struct file *, const char *, size_t, loff_t *);
4511da177e4SLinus Torvalds 	loff_t pos;
4521da177e4SLinus Torvalds 
4531da177e4SLinus Torvalds 	ret = -EBADF;
4541da177e4SLinus Torvalds 	file = fget(fd);
4551da177e4SLinus Torvalds 	if (!file)
4561da177e4SLinus Torvalds 		goto bad_file;
4571da177e4SLinus Torvalds 	if (!(file->f_mode & FMODE_WRITE))
4581da177e4SLinus Torvalds 		goto out;
4591da177e4SLinus Torvalds 	pos = merge_64(a4, a5);
4601da177e4SLinus Torvalds 	ret = rw_verify_area(WRITE, file, &pos, count);
461e28cc715SLinus Torvalds 	if (ret < 0)
4621da177e4SLinus Torvalds 		goto out;
4631da177e4SLinus Torvalds 	ret = -EINVAL;
4641da177e4SLinus Torvalds 	if (!file->f_op || !(write = file->f_op->write))
4651da177e4SLinus Torvalds 		goto out;
4661da177e4SLinus Torvalds 	if (pos < 0)
4671da177e4SLinus Torvalds 		goto out;
4681da177e4SLinus Torvalds 
4691da177e4SLinus Torvalds 	ret = -ESPIPE;
4701da177e4SLinus Torvalds 	if (!(file->f_mode & FMODE_PWRITE))
4711da177e4SLinus Torvalds 		goto out;
4721da177e4SLinus Torvalds 
4731da177e4SLinus Torvalds 	ret = write(file, buf, count, &pos);
4741da177e4SLinus Torvalds 	if (ret > 0)
4751da177e4SLinus Torvalds 		dnotify_parent(file->f_dentry, DN_MODIFY);
4761da177e4SLinus Torvalds out:
4771da177e4SLinus Torvalds 	fput(file);
4781da177e4SLinus Torvalds bad_file:
4791da177e4SLinus Torvalds 	return ret;
4801da177e4SLinus Torvalds }
4811da177e4SLinus Torvalds 
4821da177e4SLinus Torvalds asmlinkage int sys32_sched_rr_get_interval(compat_pid_t pid,
4831da177e4SLinus Torvalds 	struct compat_timespec *interval)
4841da177e4SLinus Torvalds {
4851da177e4SLinus Torvalds 	struct timespec t;
4861da177e4SLinus Torvalds 	int ret;
4871da177e4SLinus Torvalds 	mm_segment_t old_fs = get_fs ();
4881da177e4SLinus Torvalds 
4891da177e4SLinus Torvalds 	set_fs (KERNEL_DS);
4901da177e4SLinus Torvalds 	ret = sys_sched_rr_get_interval(pid, &t);
4911da177e4SLinus Torvalds 	set_fs (old_fs);
4921da177e4SLinus Torvalds 	if (put_user (t.tv_sec, &interval->tv_sec) ||
4931da177e4SLinus Torvalds 	    __put_user (t.tv_nsec, &interval->tv_nsec))
4941da177e4SLinus Torvalds 		return -EFAULT;
4951da177e4SLinus Torvalds 	return ret;
4961da177e4SLinus Torvalds }
4971da177e4SLinus Torvalds 
4981da177e4SLinus Torvalds struct msgbuf32 { s32 mtype; char mtext[1]; };
4991da177e4SLinus Torvalds 
5001da177e4SLinus Torvalds struct ipc_perm32
5011da177e4SLinus Torvalds {
5021da177e4SLinus Torvalds 	key_t    	  key;
503202e5979SStephen Rothwell         __compat_uid_t  uid;
504202e5979SStephen Rothwell         __compat_gid_t  gid;
505202e5979SStephen Rothwell         __compat_uid_t  cuid;
506202e5979SStephen Rothwell         __compat_gid_t  cgid;
5071da177e4SLinus Torvalds         compat_mode_t	mode;
5081da177e4SLinus Torvalds         unsigned short  seq;
5091da177e4SLinus Torvalds };
5101da177e4SLinus Torvalds 
5111da177e4SLinus Torvalds struct ipc64_perm32 {
5121da177e4SLinus Torvalds 	key_t key;
513202e5979SStephen Rothwell 	__compat_uid_t uid;
514202e5979SStephen Rothwell 	__compat_gid_t gid;
515202e5979SStephen Rothwell 	__compat_uid_t cuid;
516202e5979SStephen Rothwell 	__compat_gid_t cgid;
5171da177e4SLinus Torvalds 	compat_mode_t	mode;
5181da177e4SLinus Torvalds 	unsigned short	seq;
5191da177e4SLinus Torvalds 	unsigned short __pad1;
5201da177e4SLinus Torvalds 	unsigned int __unused1;
5211da177e4SLinus Torvalds 	unsigned int __unused2;
5221da177e4SLinus Torvalds };
5231da177e4SLinus Torvalds 
5241da177e4SLinus Torvalds struct semid_ds32 {
5251da177e4SLinus Torvalds         struct ipc_perm32 sem_perm;               /* permissions .. see ipc.h */
5261da177e4SLinus Torvalds         compat_time_t   sem_otime;              /* last semop time */
5271da177e4SLinus Torvalds         compat_time_t   sem_ctime;              /* last change time */
5281da177e4SLinus Torvalds         u32 sem_base;              /* ptr to first semaphore in array */
5291da177e4SLinus Torvalds         u32 sem_pending;          /* pending operations to be processed */
5301da177e4SLinus Torvalds         u32 sem_pending_last;    /* last pending operation */
5311da177e4SLinus Torvalds         u32 undo;                  /* undo requests on this array */
5321da177e4SLinus Torvalds         unsigned short  sem_nsems;              /* no. of semaphores in array */
5331da177e4SLinus Torvalds };
5341da177e4SLinus Torvalds 
5351da177e4SLinus Torvalds struct semid64_ds32 {
5361da177e4SLinus Torvalds 	struct ipc64_perm32	sem_perm;
5371da177e4SLinus Torvalds 	compat_time_t	sem_otime;
5381da177e4SLinus Torvalds 	compat_time_t	sem_ctime;
5391da177e4SLinus Torvalds 	unsigned int		sem_nsems;
5401da177e4SLinus Torvalds 	unsigned int		__unused1;
5411da177e4SLinus Torvalds 	unsigned int		__unused2;
5421da177e4SLinus Torvalds };
5431da177e4SLinus Torvalds 
5441da177e4SLinus Torvalds struct msqid_ds32
5451da177e4SLinus Torvalds {
5461da177e4SLinus Torvalds         struct ipc_perm32 msg_perm;
5471da177e4SLinus Torvalds         u32 msg_first;
5481da177e4SLinus Torvalds         u32 msg_last;
5491da177e4SLinus Torvalds         compat_time_t   msg_stime;
5501da177e4SLinus Torvalds         compat_time_t   msg_rtime;
5511da177e4SLinus Torvalds         compat_time_t   msg_ctime;
5521da177e4SLinus Torvalds         u32 wwait;
5531da177e4SLinus Torvalds         u32 rwait;
5541da177e4SLinus Torvalds         unsigned short msg_cbytes;
5551da177e4SLinus Torvalds         unsigned short msg_qnum;
5561da177e4SLinus Torvalds         unsigned short msg_qbytes;
5571da177e4SLinus Torvalds         compat_ipc_pid_t msg_lspid;
5581da177e4SLinus Torvalds         compat_ipc_pid_t msg_lrpid;
5591da177e4SLinus Torvalds };
5601da177e4SLinus Torvalds 
5611da177e4SLinus Torvalds struct msqid64_ds32 {
5621da177e4SLinus Torvalds 	struct ipc64_perm32 msg_perm;
5631da177e4SLinus Torvalds 	compat_time_t msg_stime;
5641da177e4SLinus Torvalds 	unsigned int __unused1;
5651da177e4SLinus Torvalds 	compat_time_t msg_rtime;
5661da177e4SLinus Torvalds 	unsigned int __unused2;
5671da177e4SLinus Torvalds 	compat_time_t msg_ctime;
5681da177e4SLinus Torvalds 	unsigned int __unused3;
5691da177e4SLinus Torvalds 	unsigned int msg_cbytes;
5701da177e4SLinus Torvalds 	unsigned int msg_qnum;
5711da177e4SLinus Torvalds 	unsigned int msg_qbytes;
5721da177e4SLinus Torvalds 	compat_pid_t msg_lspid;
5731da177e4SLinus Torvalds 	compat_pid_t msg_lrpid;
5741da177e4SLinus Torvalds 	unsigned int __unused4;
5751da177e4SLinus Torvalds 	unsigned int __unused5;
5761da177e4SLinus Torvalds };
5771da177e4SLinus Torvalds 
5781da177e4SLinus Torvalds struct shmid_ds32 {
5791da177e4SLinus Torvalds         struct ipc_perm32       shm_perm;
5801da177e4SLinus Torvalds         int                     shm_segsz;
5811da177e4SLinus Torvalds         compat_time_t		shm_atime;
5821da177e4SLinus Torvalds         compat_time_t		shm_dtime;
5831da177e4SLinus Torvalds         compat_time_t		shm_ctime;
5841da177e4SLinus Torvalds         compat_ipc_pid_t    shm_cpid;
5851da177e4SLinus Torvalds         compat_ipc_pid_t    shm_lpid;
5861da177e4SLinus Torvalds         unsigned short          shm_nattch;
5871da177e4SLinus Torvalds };
5881da177e4SLinus Torvalds 
5891da177e4SLinus Torvalds struct shmid64_ds32 {
5901da177e4SLinus Torvalds 	struct ipc64_perm32	shm_perm;
5911da177e4SLinus Torvalds 	compat_size_t		shm_segsz;
5921da177e4SLinus Torvalds 	compat_time_t		shm_atime;
5931da177e4SLinus Torvalds 	compat_time_t		shm_dtime;
5941da177e4SLinus Torvalds 	compat_time_t shm_ctime;
5951da177e4SLinus Torvalds 	compat_pid_t shm_cpid;
5961da177e4SLinus Torvalds 	compat_pid_t shm_lpid;
5971da177e4SLinus Torvalds 	unsigned int shm_nattch;
5981da177e4SLinus Torvalds 	unsigned int __unused1;
5991da177e4SLinus Torvalds 	unsigned int __unused2;
6001da177e4SLinus Torvalds };
6011da177e4SLinus Torvalds 
6021da177e4SLinus Torvalds struct ipc_kludge32 {
6031da177e4SLinus Torvalds 	u32 msgp;
6041da177e4SLinus Torvalds 	s32 msgtyp;
6051da177e4SLinus Torvalds };
6061da177e4SLinus Torvalds 
6071da177e4SLinus Torvalds static int
6081da177e4SLinus Torvalds do_sys32_semctl(int first, int second, int third, void *uptr)
6091da177e4SLinus Torvalds {
6101da177e4SLinus Torvalds 	union semun fourth;
6111da177e4SLinus Torvalds 	u32 pad;
6121da177e4SLinus Torvalds 	int err, err2;
6131da177e4SLinus Torvalds 	struct semid64_ds s;
6141da177e4SLinus Torvalds 	mm_segment_t old_fs;
6151da177e4SLinus Torvalds 
6161da177e4SLinus Torvalds 	if (!uptr)
6171da177e4SLinus Torvalds 		return -EINVAL;
6181da177e4SLinus Torvalds 	err = -EFAULT;
6191da177e4SLinus Torvalds 	if (get_user (pad, (u32 *)uptr))
6201da177e4SLinus Torvalds 		return err;
6211da177e4SLinus Torvalds 	if ((third & ~IPC_64) == SETVAL)
6221da177e4SLinus Torvalds 		fourth.val = (int)pad;
6231da177e4SLinus Torvalds 	else
6241da177e4SLinus Torvalds 		fourth.__pad = (void *)A(pad);
6251da177e4SLinus Torvalds 	switch (third & ~IPC_64) {
6261da177e4SLinus Torvalds 	case IPC_INFO:
6271da177e4SLinus Torvalds 	case IPC_RMID:
6281da177e4SLinus Torvalds 	case IPC_SET:
6291da177e4SLinus Torvalds 	case SEM_INFO:
6301da177e4SLinus Torvalds 	case GETVAL:
6311da177e4SLinus Torvalds 	case GETPID:
6321da177e4SLinus Torvalds 	case GETNCNT:
6331da177e4SLinus Torvalds 	case GETZCNT:
6341da177e4SLinus Torvalds 	case GETALL:
6351da177e4SLinus Torvalds 	case SETVAL:
6361da177e4SLinus Torvalds 	case SETALL:
6371da177e4SLinus Torvalds 		err = sys_semctl (first, second, third, fourth);
6381da177e4SLinus Torvalds 		break;
6391da177e4SLinus Torvalds 
6401da177e4SLinus Torvalds 	case IPC_STAT:
6411da177e4SLinus Torvalds 	case SEM_STAT:
6421da177e4SLinus Torvalds 		fourth.__pad = &s;
6431da177e4SLinus Torvalds 		old_fs = get_fs();
6441da177e4SLinus Torvalds 		set_fs(KERNEL_DS);
6451da177e4SLinus Torvalds 		err = sys_semctl(first, second, third | IPC_64, fourth);
6461da177e4SLinus Torvalds 		set_fs(old_fs);
6471da177e4SLinus Torvalds 
6481da177e4SLinus Torvalds 		if (third & IPC_64) {
6491da177e4SLinus Torvalds 			struct semid64_ds32 *usp64 = (struct semid64_ds32 *) A(pad);
6501da177e4SLinus Torvalds 
6511da177e4SLinus Torvalds 			if (!access_ok(VERIFY_WRITE, usp64, sizeof(*usp64))) {
6521da177e4SLinus Torvalds 				err = -EFAULT;
6531da177e4SLinus Torvalds 				break;
6541da177e4SLinus Torvalds 			}
6551da177e4SLinus Torvalds 			err2 = __put_user(s.sem_perm.key, &usp64->sem_perm.key);
6561da177e4SLinus Torvalds 			err2 |= __put_user(s.sem_perm.uid, &usp64->sem_perm.uid);
6571da177e4SLinus Torvalds 			err2 |= __put_user(s.sem_perm.gid, &usp64->sem_perm.gid);
6581da177e4SLinus Torvalds 			err2 |= __put_user(s.sem_perm.cuid, &usp64->sem_perm.cuid);
6591da177e4SLinus Torvalds 			err2 |= __put_user(s.sem_perm.cgid, &usp64->sem_perm.cgid);
6601da177e4SLinus Torvalds 			err2 |= __put_user(s.sem_perm.mode, &usp64->sem_perm.mode);
6611da177e4SLinus Torvalds 			err2 |= __put_user(s.sem_perm.seq, &usp64->sem_perm.seq);
6621da177e4SLinus Torvalds 			err2 |= __put_user(s.sem_otime, &usp64->sem_otime);
6631da177e4SLinus Torvalds 			err2 |= __put_user(s.sem_ctime, &usp64->sem_ctime);
6641da177e4SLinus Torvalds 			err2 |= __put_user(s.sem_nsems, &usp64->sem_nsems);
6651da177e4SLinus Torvalds 		} else {
6661da177e4SLinus Torvalds 			struct semid_ds32 *usp32 = (struct semid_ds32 *) A(pad);
6671da177e4SLinus Torvalds 
6681da177e4SLinus Torvalds 			if (!access_ok(VERIFY_WRITE, usp32, sizeof(*usp32))) {
6691da177e4SLinus Torvalds 				err = -EFAULT;
6701da177e4SLinus Torvalds 				break;
6711da177e4SLinus Torvalds 			}
6721da177e4SLinus Torvalds 			err2 = __put_user(s.sem_perm.key, &usp32->sem_perm.key);
6731da177e4SLinus Torvalds 			err2 |= __put_user(s.sem_perm.uid, &usp32->sem_perm.uid);
6741da177e4SLinus Torvalds 			err2 |= __put_user(s.sem_perm.gid, &usp32->sem_perm.gid);
6751da177e4SLinus Torvalds 			err2 |= __put_user(s.sem_perm.cuid, &usp32->sem_perm.cuid);
6761da177e4SLinus Torvalds 			err2 |= __put_user(s.sem_perm.cgid, &usp32->sem_perm.cgid);
6771da177e4SLinus Torvalds 			err2 |= __put_user(s.sem_perm.mode, &usp32->sem_perm.mode);
6781da177e4SLinus Torvalds 			err2 |= __put_user(s.sem_perm.seq, &usp32->sem_perm.seq);
6791da177e4SLinus Torvalds 			err2 |= __put_user(s.sem_otime, &usp32->sem_otime);
6801da177e4SLinus Torvalds 			err2 |= __put_user(s.sem_ctime, &usp32->sem_ctime);
6811da177e4SLinus Torvalds 			err2 |= __put_user(s.sem_nsems, &usp32->sem_nsems);
6821da177e4SLinus Torvalds 		}
6831da177e4SLinus Torvalds 		if (err2)
6841da177e4SLinus Torvalds 			err = -EFAULT;
6851da177e4SLinus Torvalds 		break;
6861da177e4SLinus Torvalds 
6871da177e4SLinus Torvalds 	default:
6881da177e4SLinus Torvalds 		err = - EINVAL;
6891da177e4SLinus Torvalds 		break;
6901da177e4SLinus Torvalds 	}
6911da177e4SLinus Torvalds 
6921da177e4SLinus Torvalds 	return err;
6931da177e4SLinus Torvalds }
6941da177e4SLinus Torvalds 
6951da177e4SLinus Torvalds static int
6961da177e4SLinus Torvalds do_sys32_msgsnd (int first, int second, int third, void *uptr)
6971da177e4SLinus Torvalds {
6981da177e4SLinus Torvalds 	struct msgbuf32 *up = (struct msgbuf32 *)uptr;
6991da177e4SLinus Torvalds 	struct msgbuf *p;
7001da177e4SLinus Torvalds 	mm_segment_t old_fs;
7011da177e4SLinus Torvalds 	int err;
7021da177e4SLinus Torvalds 
7031da177e4SLinus Torvalds 	if (second < 0)
7041da177e4SLinus Torvalds 		return -EINVAL;
7051da177e4SLinus Torvalds 	p = kmalloc (second + sizeof (struct msgbuf)
7061da177e4SLinus Torvalds 				    + 4, GFP_USER);
7071da177e4SLinus Torvalds 	if (!p)
7081da177e4SLinus Torvalds 		return -ENOMEM;
7091da177e4SLinus Torvalds 	err = get_user (p->mtype, &up->mtype);
7101da177e4SLinus Torvalds 	if (err)
7111da177e4SLinus Torvalds 		goto out;
7121da177e4SLinus Torvalds 	err |= __copy_from_user (p->mtext, &up->mtext, second);
7131da177e4SLinus Torvalds 	if (err)
7141da177e4SLinus Torvalds 		goto out;
7151da177e4SLinus Torvalds 	old_fs = get_fs ();
7161da177e4SLinus Torvalds 	set_fs (KERNEL_DS);
7171da177e4SLinus Torvalds 	err = sys_msgsnd (first, p, second, third);
7181da177e4SLinus Torvalds 	set_fs (old_fs);
7191da177e4SLinus Torvalds out:
7201da177e4SLinus Torvalds 	kfree (p);
7211da177e4SLinus Torvalds 
7221da177e4SLinus Torvalds 	return err;
7231da177e4SLinus Torvalds }
7241da177e4SLinus Torvalds 
7251da177e4SLinus Torvalds static int
7261da177e4SLinus Torvalds do_sys32_msgrcv (int first, int second, int msgtyp, int third,
7271da177e4SLinus Torvalds 		 int version, void *uptr)
7281da177e4SLinus Torvalds {
7291da177e4SLinus Torvalds 	struct msgbuf32 *up;
7301da177e4SLinus Torvalds 	struct msgbuf *p;
7311da177e4SLinus Torvalds 	mm_segment_t old_fs;
7321da177e4SLinus Torvalds 	int err;
7331da177e4SLinus Torvalds 
7341da177e4SLinus Torvalds 	if (!version) {
7351da177e4SLinus Torvalds 		struct ipc_kludge32 *uipck = (struct ipc_kludge32 *)uptr;
7361da177e4SLinus Torvalds 		struct ipc_kludge32 ipck;
7371da177e4SLinus Torvalds 
7381da177e4SLinus Torvalds 		err = -EINVAL;
7391da177e4SLinus Torvalds 		if (!uptr)
7401da177e4SLinus Torvalds 			goto out;
7411da177e4SLinus Torvalds 		err = -EFAULT;
7421da177e4SLinus Torvalds 		if (copy_from_user (&ipck, uipck, sizeof (struct ipc_kludge32)))
7431da177e4SLinus Torvalds 			goto out;
7441da177e4SLinus Torvalds 		uptr = (void *)AA(ipck.msgp);
7451da177e4SLinus Torvalds 		msgtyp = ipck.msgtyp;
7461da177e4SLinus Torvalds 	}
7471da177e4SLinus Torvalds 
7481da177e4SLinus Torvalds 	if (second < 0)
7491da177e4SLinus Torvalds 		return -EINVAL;
7501da177e4SLinus Torvalds 	err = -ENOMEM;
7511da177e4SLinus Torvalds 	p = kmalloc (second + sizeof (struct msgbuf) + 4, GFP_USER);
7521da177e4SLinus Torvalds 	if (!p)
7531da177e4SLinus Torvalds 		goto out;
7541da177e4SLinus Torvalds 	old_fs = get_fs ();
7551da177e4SLinus Torvalds 	set_fs (KERNEL_DS);
7561da177e4SLinus Torvalds 	err = sys_msgrcv (first, p, second + 4, msgtyp, third);
7571da177e4SLinus Torvalds 	set_fs (old_fs);
7581da177e4SLinus Torvalds 	if (err < 0)
7591da177e4SLinus Torvalds 		goto free_then_out;
7601da177e4SLinus Torvalds 	up = (struct msgbuf32 *)uptr;
7611da177e4SLinus Torvalds 	if (put_user (p->mtype, &up->mtype) ||
7621da177e4SLinus Torvalds 	    __copy_to_user (&up->mtext, p->mtext, err))
7631da177e4SLinus Torvalds 		err = -EFAULT;
7641da177e4SLinus Torvalds free_then_out:
7651da177e4SLinus Torvalds 	kfree (p);
7661da177e4SLinus Torvalds out:
7671da177e4SLinus Torvalds 	return err;
7681da177e4SLinus Torvalds }
7691da177e4SLinus Torvalds 
7701da177e4SLinus Torvalds static int
7711da177e4SLinus Torvalds do_sys32_msgctl (int first, int second, void *uptr)
7721da177e4SLinus Torvalds {
7731da177e4SLinus Torvalds 	int err = -EINVAL, err2;
7741da177e4SLinus Torvalds 	struct msqid64_ds m;
7751da177e4SLinus Torvalds 	struct msqid_ds32 *up32 = (struct msqid_ds32 *)uptr;
7761da177e4SLinus Torvalds 	struct msqid64_ds32 *up64 = (struct msqid64_ds32 *)uptr;
7771da177e4SLinus Torvalds 	mm_segment_t old_fs;
7781da177e4SLinus Torvalds 
7791da177e4SLinus Torvalds 	switch (second & ~IPC_64) {
7801da177e4SLinus Torvalds 	case IPC_INFO:
7811da177e4SLinus Torvalds 	case IPC_RMID:
7821da177e4SLinus Torvalds 	case MSG_INFO:
7831da177e4SLinus Torvalds 		err = sys_msgctl (first, second, (struct msqid_ds *)uptr);
7841da177e4SLinus Torvalds 		break;
7851da177e4SLinus Torvalds 
7861da177e4SLinus Torvalds 	case IPC_SET:
7871da177e4SLinus Torvalds 		if (second & IPC_64) {
7881da177e4SLinus Torvalds 			if (!access_ok(VERIFY_READ, up64, sizeof(*up64))) {
7891da177e4SLinus Torvalds 				err = -EFAULT;
7901da177e4SLinus Torvalds 				break;
7911da177e4SLinus Torvalds 			}
7921da177e4SLinus Torvalds 			err = __get_user(m.msg_perm.uid, &up64->msg_perm.uid);
7931da177e4SLinus Torvalds 			err |= __get_user(m.msg_perm.gid, &up64->msg_perm.gid);
7941da177e4SLinus Torvalds 			err |= __get_user(m.msg_perm.mode, &up64->msg_perm.mode);
7951da177e4SLinus Torvalds 			err |= __get_user(m.msg_qbytes, &up64->msg_qbytes);
7961da177e4SLinus Torvalds 		} else {
7971da177e4SLinus Torvalds 			if (!access_ok(VERIFY_READ, up32, sizeof(*up32))) {
7981da177e4SLinus Torvalds 				err = -EFAULT;
7991da177e4SLinus Torvalds 				break;
8001da177e4SLinus Torvalds 			}
8011da177e4SLinus Torvalds 			err = __get_user(m.msg_perm.uid, &up32->msg_perm.uid);
8021da177e4SLinus Torvalds 			err |= __get_user(m.msg_perm.gid, &up32->msg_perm.gid);
8031da177e4SLinus Torvalds 			err |= __get_user(m.msg_perm.mode, &up32->msg_perm.mode);
8041da177e4SLinus Torvalds 			err |= __get_user(m.msg_qbytes, &up32->msg_qbytes);
8051da177e4SLinus Torvalds 		}
8061da177e4SLinus Torvalds 		if (err)
8071da177e4SLinus Torvalds 			break;
8081da177e4SLinus Torvalds 		old_fs = get_fs();
8091da177e4SLinus Torvalds 		set_fs(KERNEL_DS);
8101da177e4SLinus Torvalds 		err = sys_msgctl(first, second | IPC_64, (struct msqid_ds *)&m);
8111da177e4SLinus Torvalds 		set_fs(old_fs);
8121da177e4SLinus Torvalds 		break;
8131da177e4SLinus Torvalds 
8141da177e4SLinus Torvalds 	case IPC_STAT:
8151da177e4SLinus Torvalds 	case MSG_STAT:
8161da177e4SLinus Torvalds 		old_fs = get_fs();
8171da177e4SLinus Torvalds 		set_fs(KERNEL_DS);
8181da177e4SLinus Torvalds 		err = sys_msgctl(first, second | IPC_64, (struct msqid_ds *)&m);
8191da177e4SLinus Torvalds 		set_fs(old_fs);
8201da177e4SLinus Torvalds 		if (second & IPC_64) {
8211da177e4SLinus Torvalds 			if (!access_ok(VERIFY_WRITE, up64, sizeof(*up64))) {
8221da177e4SLinus Torvalds 				err = -EFAULT;
8231da177e4SLinus Torvalds 				break;
8241da177e4SLinus Torvalds 			}
8251da177e4SLinus Torvalds 			err2 = __put_user(m.msg_perm.key, &up64->msg_perm.key);
8261da177e4SLinus Torvalds 			err2 |= __put_user(m.msg_perm.uid, &up64->msg_perm.uid);
8271da177e4SLinus Torvalds 			err2 |= __put_user(m.msg_perm.gid, &up64->msg_perm.gid);
8281da177e4SLinus Torvalds 			err2 |= __put_user(m.msg_perm.cuid, &up64->msg_perm.cuid);
8291da177e4SLinus Torvalds 			err2 |= __put_user(m.msg_perm.cgid, &up64->msg_perm.cgid);
8301da177e4SLinus Torvalds 			err2 |= __put_user(m.msg_perm.mode, &up64->msg_perm.mode);
8311da177e4SLinus Torvalds 			err2 |= __put_user(m.msg_perm.seq, &up64->msg_perm.seq);
8321da177e4SLinus Torvalds 			err2 |= __put_user(m.msg_stime, &up64->msg_stime);
8331da177e4SLinus Torvalds 			err2 |= __put_user(m.msg_rtime, &up64->msg_rtime);
8341da177e4SLinus Torvalds 			err2 |= __put_user(m.msg_ctime, &up64->msg_ctime);
8351da177e4SLinus Torvalds 			err2 |= __put_user(m.msg_cbytes, &up64->msg_cbytes);
8361da177e4SLinus Torvalds 			err2 |= __put_user(m.msg_qnum, &up64->msg_qnum);
8371da177e4SLinus Torvalds 			err2 |= __put_user(m.msg_qbytes, &up64->msg_qbytes);
8381da177e4SLinus Torvalds 			err2 |= __put_user(m.msg_lspid, &up64->msg_lspid);
8391da177e4SLinus Torvalds 			err2 |= __put_user(m.msg_lrpid, &up64->msg_lrpid);
8401da177e4SLinus Torvalds 			if (err2)
8411da177e4SLinus Torvalds 				err = -EFAULT;
8421da177e4SLinus Torvalds 		} else {
8431da177e4SLinus Torvalds 			if (!access_ok(VERIFY_WRITE, up32, sizeof(*up32))) {
8441da177e4SLinus Torvalds 				err = -EFAULT;
8451da177e4SLinus Torvalds 				break;
8461da177e4SLinus Torvalds 			}
8471da177e4SLinus Torvalds 			err2 = __put_user(m.msg_perm.key, &up32->msg_perm.key);
8481da177e4SLinus Torvalds 			err2 |= __put_user(m.msg_perm.uid, &up32->msg_perm.uid);
8491da177e4SLinus Torvalds 			err2 |= __put_user(m.msg_perm.gid, &up32->msg_perm.gid);
8501da177e4SLinus Torvalds 			err2 |= __put_user(m.msg_perm.cuid, &up32->msg_perm.cuid);
8511da177e4SLinus Torvalds 			err2 |= __put_user(m.msg_perm.cgid, &up32->msg_perm.cgid);
8521da177e4SLinus Torvalds 			err2 |= __put_user(m.msg_perm.mode, &up32->msg_perm.mode);
8531da177e4SLinus Torvalds 			err2 |= __put_user(m.msg_perm.seq, &up32->msg_perm.seq);
8541da177e4SLinus Torvalds 			err2 |= __put_user(m.msg_stime, &up32->msg_stime);
8551da177e4SLinus Torvalds 			err2 |= __put_user(m.msg_rtime, &up32->msg_rtime);
8561da177e4SLinus Torvalds 			err2 |= __put_user(m.msg_ctime, &up32->msg_ctime);
8571da177e4SLinus Torvalds 			err2 |= __put_user(m.msg_cbytes, &up32->msg_cbytes);
8581da177e4SLinus Torvalds 			err2 |= __put_user(m.msg_qnum, &up32->msg_qnum);
8591da177e4SLinus Torvalds 			err2 |= __put_user(m.msg_qbytes, &up32->msg_qbytes);
8601da177e4SLinus Torvalds 			err2 |= __put_user(m.msg_lspid, &up32->msg_lspid);
8611da177e4SLinus Torvalds 			err2 |= __put_user(m.msg_lrpid, &up32->msg_lrpid);
8621da177e4SLinus Torvalds 			if (err2)
8631da177e4SLinus Torvalds 				err = -EFAULT;
8641da177e4SLinus Torvalds 		}
8651da177e4SLinus Torvalds 		break;
8661da177e4SLinus Torvalds 	}
8671da177e4SLinus Torvalds 
8681da177e4SLinus Torvalds 	return err;
8691da177e4SLinus Torvalds }
8701da177e4SLinus Torvalds 
8711da177e4SLinus Torvalds static int
8721da177e4SLinus Torvalds do_sys32_shmat (int first, int second, int third, int version, void *uptr)
8731da177e4SLinus Torvalds {
8741da177e4SLinus Torvalds 	unsigned long raddr;
8751da177e4SLinus Torvalds 	u32 *uaddr = (u32 *)A((u32)third);
8761da177e4SLinus Torvalds 	int err = -EINVAL;
8771da177e4SLinus Torvalds 
8781da177e4SLinus Torvalds 	if (version == 1)
8791da177e4SLinus Torvalds 		return err;
8801da177e4SLinus Torvalds 	err = do_shmat (first, uptr, second, &raddr);
8811da177e4SLinus Torvalds 	if (err)
8821da177e4SLinus Torvalds 		return err;
8831da177e4SLinus Torvalds 	err = put_user (raddr, uaddr);
8841da177e4SLinus Torvalds 	return err;
8851da177e4SLinus Torvalds }
8861da177e4SLinus Torvalds 
8871da177e4SLinus Torvalds struct shm_info32 {
8881da177e4SLinus Torvalds 	int used_ids;
8891da177e4SLinus Torvalds 	u32 shm_tot, shm_rss, shm_swp;
8901da177e4SLinus Torvalds 	u32 swap_attempts, swap_successes;
8911da177e4SLinus Torvalds };
8921da177e4SLinus Torvalds 
8931da177e4SLinus Torvalds static int
8941da177e4SLinus Torvalds do_sys32_shmctl (int first, int second, void *uptr)
8951da177e4SLinus Torvalds {
8961da177e4SLinus Torvalds 	struct shmid64_ds32 *up64 = (struct shmid64_ds32 *)uptr;
8971da177e4SLinus Torvalds 	struct shmid_ds32 *up32 = (struct shmid_ds32 *)uptr;
8981da177e4SLinus Torvalds 	struct shm_info32 *uip = (struct shm_info32 *)uptr;
8991da177e4SLinus Torvalds 	int err = -EFAULT, err2;
9001da177e4SLinus Torvalds 	struct shmid64_ds s64;
9011da177e4SLinus Torvalds 	mm_segment_t old_fs;
9021da177e4SLinus Torvalds 	struct shm_info si;
9031da177e4SLinus Torvalds 	struct shmid_ds s;
9041da177e4SLinus Torvalds 
9051da177e4SLinus Torvalds 	switch (second & ~IPC_64) {
9061da177e4SLinus Torvalds 	case IPC_INFO:
9071da177e4SLinus Torvalds 		second = IPC_INFO; /* So that we don't have to translate it */
9081da177e4SLinus Torvalds 	case IPC_RMID:
9091da177e4SLinus Torvalds 	case SHM_LOCK:
9101da177e4SLinus Torvalds 	case SHM_UNLOCK:
9111da177e4SLinus Torvalds 		err = sys_shmctl(first, second, (struct shmid_ds *)uptr);
9121da177e4SLinus Torvalds 		break;
9131da177e4SLinus Torvalds 	case IPC_SET:
9141da177e4SLinus Torvalds 		if (second & IPC_64) {
9151da177e4SLinus Torvalds 			err = get_user(s.shm_perm.uid, &up64->shm_perm.uid);
9161da177e4SLinus Torvalds 			err |= get_user(s.shm_perm.gid, &up64->shm_perm.gid);
9171da177e4SLinus Torvalds 			err |= get_user(s.shm_perm.mode, &up64->shm_perm.mode);
9181da177e4SLinus Torvalds 		} else {
9191da177e4SLinus Torvalds 			err = get_user(s.shm_perm.uid, &up32->shm_perm.uid);
9201da177e4SLinus Torvalds 			err |= get_user(s.shm_perm.gid, &up32->shm_perm.gid);
9211da177e4SLinus Torvalds 			err |= get_user(s.shm_perm.mode, &up32->shm_perm.mode);
9221da177e4SLinus Torvalds 		}
9231da177e4SLinus Torvalds 		if (err)
9241da177e4SLinus Torvalds 			break;
9251da177e4SLinus Torvalds 		old_fs = get_fs();
9261da177e4SLinus Torvalds 		set_fs(KERNEL_DS);
9271da177e4SLinus Torvalds 		err = sys_shmctl(first, second & ~IPC_64, &s);
9281da177e4SLinus Torvalds 		set_fs(old_fs);
9291da177e4SLinus Torvalds 		break;
9301da177e4SLinus Torvalds 
9311da177e4SLinus Torvalds 	case IPC_STAT:
9321da177e4SLinus Torvalds 	case SHM_STAT:
9331da177e4SLinus Torvalds 		old_fs = get_fs();
9341da177e4SLinus Torvalds 		set_fs(KERNEL_DS);
9351da177e4SLinus Torvalds 		err = sys_shmctl(first, second | IPC_64, (void *) &s64);
9361da177e4SLinus Torvalds 		set_fs(old_fs);
9371da177e4SLinus Torvalds 		if (err < 0)
9381da177e4SLinus Torvalds 			break;
9391da177e4SLinus Torvalds 		if (second & IPC_64) {
9401da177e4SLinus Torvalds 			if (!access_ok(VERIFY_WRITE, up64, sizeof(*up64))) {
9411da177e4SLinus Torvalds 				err = -EFAULT;
9421da177e4SLinus Torvalds 				break;
9431da177e4SLinus Torvalds 			}
9441da177e4SLinus Torvalds 			err2 = __put_user(s64.shm_perm.key, &up64->shm_perm.key);
9451da177e4SLinus Torvalds 			err2 |= __put_user(s64.shm_perm.uid, &up64->shm_perm.uid);
9461da177e4SLinus Torvalds 			err2 |= __put_user(s64.shm_perm.gid, &up64->shm_perm.gid);
9471da177e4SLinus Torvalds 			err2 |= __put_user(s64.shm_perm.cuid, &up64->shm_perm.cuid);
9481da177e4SLinus Torvalds 			err2 |= __put_user(s64.shm_perm.cgid, &up64->shm_perm.cgid);
9491da177e4SLinus Torvalds 			err2 |= __put_user(s64.shm_perm.mode, &up64->shm_perm.mode);
9501da177e4SLinus Torvalds 			err2 |= __put_user(s64.shm_perm.seq, &up64->shm_perm.seq);
9511da177e4SLinus Torvalds 			err2 |= __put_user(s64.shm_atime, &up64->shm_atime);
9521da177e4SLinus Torvalds 			err2 |= __put_user(s64.shm_dtime, &up64->shm_dtime);
9531da177e4SLinus Torvalds 			err2 |= __put_user(s64.shm_ctime, &up64->shm_ctime);
9541da177e4SLinus Torvalds 			err2 |= __put_user(s64.shm_segsz, &up64->shm_segsz);
9551da177e4SLinus Torvalds 			err2 |= __put_user(s64.shm_nattch, &up64->shm_nattch);
9561da177e4SLinus Torvalds 			err2 |= __put_user(s64.shm_cpid, &up64->shm_cpid);
9571da177e4SLinus Torvalds 			err2 |= __put_user(s64.shm_lpid, &up64->shm_lpid);
9581da177e4SLinus Torvalds 		} else {
9591da177e4SLinus Torvalds 			if (!access_ok(VERIFY_WRITE, up32, sizeof(*up32))) {
9601da177e4SLinus Torvalds 				err = -EFAULT;
9611da177e4SLinus Torvalds 				break;
9621da177e4SLinus Torvalds 			}
9631da177e4SLinus Torvalds 			err2 = __put_user(s64.shm_perm.key, &up32->shm_perm.key);
9641da177e4SLinus Torvalds 			err2 |= __put_user(s64.shm_perm.uid, &up32->shm_perm.uid);
9651da177e4SLinus Torvalds 			err2 |= __put_user(s64.shm_perm.gid, &up32->shm_perm.gid);
9661da177e4SLinus Torvalds 			err2 |= __put_user(s64.shm_perm.cuid, &up32->shm_perm.cuid);
9671da177e4SLinus Torvalds 			err2 |= __put_user(s64.shm_perm.cgid, &up32->shm_perm.cgid);
9681da177e4SLinus Torvalds 			err2 |= __put_user(s64.shm_perm.mode, &up32->shm_perm.mode);
9691da177e4SLinus Torvalds 			err2 |= __put_user(s64.shm_perm.seq, &up32->shm_perm.seq);
9701da177e4SLinus Torvalds 			err2 |= __put_user(s64.shm_atime, &up32->shm_atime);
9711da177e4SLinus Torvalds 			err2 |= __put_user(s64.shm_dtime, &up32->shm_dtime);
9721da177e4SLinus Torvalds 			err2 |= __put_user(s64.shm_ctime, &up32->shm_ctime);
9731da177e4SLinus Torvalds 			err2 |= __put_user(s64.shm_segsz, &up32->shm_segsz);
9741da177e4SLinus Torvalds 			err2 |= __put_user(s64.shm_nattch, &up32->shm_nattch);
9751da177e4SLinus Torvalds 			err2 |= __put_user(s64.shm_cpid, &up32->shm_cpid);
9761da177e4SLinus Torvalds 			err2 |= __put_user(s64.shm_lpid, &up32->shm_lpid);
9771da177e4SLinus Torvalds 		}
9781da177e4SLinus Torvalds 		if (err2)
9791da177e4SLinus Torvalds 			err = -EFAULT;
9801da177e4SLinus Torvalds 		break;
9811da177e4SLinus Torvalds 
9821da177e4SLinus Torvalds 	case SHM_INFO:
9831da177e4SLinus Torvalds 		old_fs = get_fs();
9841da177e4SLinus Torvalds 		set_fs(KERNEL_DS);
9851da177e4SLinus Torvalds 		err = sys_shmctl(first, second, (void *)&si);
9861da177e4SLinus Torvalds 		set_fs(old_fs);
9871da177e4SLinus Torvalds 		if (err < 0)
9881da177e4SLinus Torvalds 			break;
9891da177e4SLinus Torvalds 		err2 = put_user(si.used_ids, &uip->used_ids);
9901da177e4SLinus Torvalds 		err2 |= __put_user(si.shm_tot, &uip->shm_tot);
9911da177e4SLinus Torvalds 		err2 |= __put_user(si.shm_rss, &uip->shm_rss);
9921da177e4SLinus Torvalds 		err2 |= __put_user(si.shm_swp, &uip->shm_swp);
9931da177e4SLinus Torvalds 		err2 |= __put_user(si.swap_attempts, &uip->swap_attempts);
9941da177e4SLinus Torvalds 		err2 |= __put_user (si.swap_successes, &uip->swap_successes);
9951da177e4SLinus Torvalds 		if (err2)
9961da177e4SLinus Torvalds 			err = -EFAULT;
9971da177e4SLinus Torvalds 		break;
9981da177e4SLinus Torvalds 
9991da177e4SLinus Torvalds 	default:
10001da177e4SLinus Torvalds 		err = -EINVAL;
10011da177e4SLinus Torvalds 		break;
10021da177e4SLinus Torvalds 	}
10031da177e4SLinus Torvalds 
10041da177e4SLinus Torvalds 	return err;
10051da177e4SLinus Torvalds }
10061da177e4SLinus Torvalds 
10071da177e4SLinus Torvalds static int sys32_semtimedop(int semid, struct sembuf *tsems, int nsems,
10081da177e4SLinus Torvalds                             const struct compat_timespec *timeout32)
10091da177e4SLinus Torvalds {
10101da177e4SLinus Torvalds 	struct compat_timespec t32;
10111da177e4SLinus Torvalds 	struct timespec *t64 = compat_alloc_user_space(sizeof(*t64));
10121da177e4SLinus Torvalds 
10131da177e4SLinus Torvalds 	if (copy_from_user(&t32, timeout32, sizeof(t32)))
10141da177e4SLinus Torvalds 		return -EFAULT;
10151da177e4SLinus Torvalds 
10161da177e4SLinus Torvalds 	if (put_user(t32.tv_sec, &t64->tv_sec) ||
10171da177e4SLinus Torvalds 	    put_user(t32.tv_nsec, &t64->tv_nsec))
10181da177e4SLinus Torvalds 		return -EFAULT;
10191da177e4SLinus Torvalds 
10201da177e4SLinus Torvalds 	return sys_semtimedop(semid, tsems, nsems, t64);
10211da177e4SLinus Torvalds }
10221da177e4SLinus Torvalds 
10231da177e4SLinus Torvalds asmlinkage long
10241da177e4SLinus Torvalds sys32_ipc (u32 call, int first, int second, int third, u32 ptr, u32 fifth)
10251da177e4SLinus Torvalds {
10261da177e4SLinus Torvalds 	int version, err;
10271da177e4SLinus Torvalds 
10281da177e4SLinus Torvalds 	version = call >> 16; /* hack for backward compatibility */
10291da177e4SLinus Torvalds 	call &= 0xffff;
10301da177e4SLinus Torvalds 
10311da177e4SLinus Torvalds 	switch (call) {
10321da177e4SLinus Torvalds 	case SEMOP:
10331da177e4SLinus Torvalds 		/* struct sembuf is the same on 32 and 64bit :)) */
10341da177e4SLinus Torvalds 		err = sys_semtimedop (first, (struct sembuf *)AA(ptr), second,
10351da177e4SLinus Torvalds 		                      NULL);
10361da177e4SLinus Torvalds 		break;
10371da177e4SLinus Torvalds 	case SEMTIMEDOP:
10381da177e4SLinus Torvalds 		err = sys32_semtimedop (first, (struct sembuf *)AA(ptr), second,
10391da177e4SLinus Torvalds 		                      (const struct compat_timespec __user *)AA(fifth));
10401da177e4SLinus Torvalds 		break;
10411da177e4SLinus Torvalds 	case SEMGET:
10421da177e4SLinus Torvalds 		err = sys_semget (first, second, third);
10431da177e4SLinus Torvalds 		break;
10441da177e4SLinus Torvalds 	case SEMCTL:
10451da177e4SLinus Torvalds 		err = do_sys32_semctl (first, second, third,
10461da177e4SLinus Torvalds 				       (void *)AA(ptr));
10471da177e4SLinus Torvalds 		break;
10481da177e4SLinus Torvalds 
10491da177e4SLinus Torvalds 	case MSGSND:
10501da177e4SLinus Torvalds 		err = do_sys32_msgsnd (first, second, third,
10511da177e4SLinus Torvalds 				       (void *)AA(ptr));
10521da177e4SLinus Torvalds 		break;
10531da177e4SLinus Torvalds 	case MSGRCV:
10541da177e4SLinus Torvalds 		err = do_sys32_msgrcv (first, second, fifth, third,
10551da177e4SLinus Torvalds 				       version, (void *)AA(ptr));
10561da177e4SLinus Torvalds 		break;
10571da177e4SLinus Torvalds 	case MSGGET:
10581da177e4SLinus Torvalds 		err = sys_msgget ((key_t) first, second);
10591da177e4SLinus Torvalds 		break;
10601da177e4SLinus Torvalds 	case MSGCTL:
10611da177e4SLinus Torvalds 		err = do_sys32_msgctl (first, second, (void *)AA(ptr));
10621da177e4SLinus Torvalds 		break;
10631da177e4SLinus Torvalds 
10641da177e4SLinus Torvalds 	case SHMAT:
10651da177e4SLinus Torvalds 		err = do_sys32_shmat (first, second, third,
10661da177e4SLinus Torvalds 				      version, (void *)AA(ptr));
10671da177e4SLinus Torvalds 		break;
10681da177e4SLinus Torvalds 	case SHMDT:
10691da177e4SLinus Torvalds 		err = sys_shmdt ((char *)A(ptr));
10701da177e4SLinus Torvalds 		break;
10711da177e4SLinus Torvalds 	case SHMGET:
10721da177e4SLinus Torvalds 		err = sys_shmget (first, (unsigned)second, third);
10731da177e4SLinus Torvalds 		break;
10741da177e4SLinus Torvalds 	case SHMCTL:
10751da177e4SLinus Torvalds 		err = do_sys32_shmctl (first, second, (void *)AA(ptr));
10761da177e4SLinus Torvalds 		break;
10771da177e4SLinus Torvalds 	default:
10781da177e4SLinus Torvalds 		err = -EINVAL;
10791da177e4SLinus Torvalds 		break;
10801da177e4SLinus Torvalds 	}
10811da177e4SLinus Torvalds 
10821da177e4SLinus Torvalds 	return err;
10831da177e4SLinus Torvalds }
10841da177e4SLinus Torvalds 
10851da177e4SLinus Torvalds asmlinkage long sys32_shmat(int shmid, char __user *shmaddr,
10861da177e4SLinus Torvalds 			  int shmflg, int32_t *addr)
10871da177e4SLinus Torvalds {
10881da177e4SLinus Torvalds 	unsigned long raddr;
10891da177e4SLinus Torvalds 	int err;
10901da177e4SLinus Torvalds 
10911da177e4SLinus Torvalds 	err = do_shmat(shmid, shmaddr, shmflg, &raddr);
10921da177e4SLinus Torvalds 	if (err)
10931da177e4SLinus Torvalds 		return err;
10941da177e4SLinus Torvalds 
10951da177e4SLinus Torvalds 	return put_user(raddr, addr);
10961da177e4SLinus Torvalds }
10971da177e4SLinus Torvalds 
10981da177e4SLinus Torvalds struct sysctl_args32
10991da177e4SLinus Torvalds {
11001da177e4SLinus Torvalds 	compat_caddr_t name;
11011da177e4SLinus Torvalds 	int nlen;
11021da177e4SLinus Torvalds 	compat_caddr_t oldval;
11031da177e4SLinus Torvalds 	compat_caddr_t oldlenp;
11041da177e4SLinus Torvalds 	compat_caddr_t newval;
11051da177e4SLinus Torvalds 	compat_size_t newlen;
11061da177e4SLinus Torvalds 	unsigned int __unused[4];
11071da177e4SLinus Torvalds };
11081da177e4SLinus Torvalds 
11091da177e4SLinus Torvalds #ifdef CONFIG_SYSCTL
11101da177e4SLinus Torvalds 
11111da177e4SLinus Torvalds asmlinkage long sys32_sysctl(struct sysctl_args32 *args)
11121da177e4SLinus Torvalds {
11131da177e4SLinus Torvalds 	struct sysctl_args32 tmp;
11141da177e4SLinus Torvalds 	int error;
11151da177e4SLinus Torvalds 	size_t oldlen, *oldlenp = NULL;
11161da177e4SLinus Torvalds 	unsigned long addr = (((long)&args->__unused[0]) + 7) & ~7;
11171da177e4SLinus Torvalds 
11181da177e4SLinus Torvalds 	if (copy_from_user(&tmp, args, sizeof(tmp)))
11191da177e4SLinus Torvalds 		return -EFAULT;
11201da177e4SLinus Torvalds 
11211da177e4SLinus Torvalds 	if (tmp.oldval && tmp.oldlenp) {
11221da177e4SLinus Torvalds 		/* Duh, this is ugly and might not work if sysctl_args
11231da177e4SLinus Torvalds 		   is in read-only memory, but do_sysctl does indirectly
11241da177e4SLinus Torvalds 		   a lot of uaccess in both directions and we'd have to
11251da177e4SLinus Torvalds 		   basically copy the whole sysctl.c here, and
11261da177e4SLinus Torvalds 		   glibc's __sysctl uses rw memory for the structure
11271da177e4SLinus Torvalds 		   anyway.  */
11281da177e4SLinus Torvalds 		if (get_user(oldlen, (u32 *)A(tmp.oldlenp)) ||
11291da177e4SLinus Torvalds 		    put_user(oldlen, (size_t *)addr))
11301da177e4SLinus Torvalds 			return -EFAULT;
11311da177e4SLinus Torvalds 		oldlenp = (size_t *)addr;
11321da177e4SLinus Torvalds 	}
11331da177e4SLinus Torvalds 
11341da177e4SLinus Torvalds 	lock_kernel();
11351da177e4SLinus Torvalds 	error = do_sysctl((int *)A(tmp.name), tmp.nlen, (void *)A(tmp.oldval),
11361da177e4SLinus Torvalds 			  oldlenp, (void *)A(tmp.newval), tmp.newlen);
11371da177e4SLinus Torvalds 	unlock_kernel();
11381da177e4SLinus Torvalds 	if (oldlenp) {
11391da177e4SLinus Torvalds 		if (!error) {
11401da177e4SLinus Torvalds 			if (get_user(oldlen, (size_t *)addr) ||
11411da177e4SLinus Torvalds 			    put_user(oldlen, (u32 *)A(tmp.oldlenp)))
11421da177e4SLinus Torvalds 				error = -EFAULT;
11431da177e4SLinus Torvalds 		}
11441da177e4SLinus Torvalds 		copy_to_user(args->__unused, tmp.__unused, sizeof(tmp.__unused));
11451da177e4SLinus Torvalds 	}
11461da177e4SLinus Torvalds 	return error;
11471da177e4SLinus Torvalds }
11481da177e4SLinus Torvalds 
11491da177e4SLinus Torvalds #endif /* CONFIG_SYSCTL */
11501da177e4SLinus Torvalds 
11511da177e4SLinus Torvalds asmlinkage long sys32_newuname(struct new_utsname * name)
11521da177e4SLinus Torvalds {
11531da177e4SLinus Torvalds 	int ret = 0;
11541da177e4SLinus Torvalds 
11551da177e4SLinus Torvalds 	down_read(&uts_sem);
11561da177e4SLinus Torvalds 	if (copy_to_user(name,&system_utsname,sizeof *name))
11571da177e4SLinus Torvalds 		ret = -EFAULT;
11581da177e4SLinus Torvalds 	up_read(&uts_sem);
11591da177e4SLinus Torvalds 
11601da177e4SLinus Torvalds 	if (current->personality == PER_LINUX32 && !ret)
11611da177e4SLinus Torvalds 		if (copy_to_user(name->machine, "mips\0\0\0", 8))
11621da177e4SLinus Torvalds 			ret = -EFAULT;
11631da177e4SLinus Torvalds 
11641da177e4SLinus Torvalds 	return ret;
11651da177e4SLinus Torvalds }
11661da177e4SLinus Torvalds 
11671da177e4SLinus Torvalds asmlinkage int sys32_personality(unsigned long personality)
11681da177e4SLinus Torvalds {
11691da177e4SLinus Torvalds 	int ret;
11701da177e4SLinus Torvalds 	if (current->personality == PER_LINUX32 && personality == PER_LINUX)
11711da177e4SLinus Torvalds 		personality = PER_LINUX32;
11721da177e4SLinus Torvalds 	ret = sys_personality(personality);
11731da177e4SLinus Torvalds 	if (ret == PER_LINUX32)
11741da177e4SLinus Torvalds 		ret = PER_LINUX;
11751da177e4SLinus Torvalds 	return ret;
11761da177e4SLinus Torvalds }
11771da177e4SLinus Torvalds 
11781da177e4SLinus Torvalds /* ustat compatibility */
11791da177e4SLinus Torvalds struct ustat32 {
11801da177e4SLinus Torvalds 	compat_daddr_t	f_tfree;
11811da177e4SLinus Torvalds 	compat_ino_t	f_tinode;
11821da177e4SLinus Torvalds 	char		f_fname[6];
11831da177e4SLinus Torvalds 	char		f_fpack[6];
11841da177e4SLinus Torvalds };
11851da177e4SLinus Torvalds 
11861da177e4SLinus Torvalds extern asmlinkage long sys_ustat(dev_t dev, struct ustat * ubuf);
11871da177e4SLinus Torvalds 
11881da177e4SLinus Torvalds asmlinkage int sys32_ustat(dev_t dev, struct ustat32 * ubuf32)
11891da177e4SLinus Torvalds {
11901da177e4SLinus Torvalds 	int err;
11911da177e4SLinus Torvalds         struct ustat tmp;
11921da177e4SLinus Torvalds 	struct ustat32 tmp32;
11931da177e4SLinus Torvalds 	mm_segment_t old_fs = get_fs();
11941da177e4SLinus Torvalds 
11951da177e4SLinus Torvalds 	set_fs(KERNEL_DS);
11961da177e4SLinus Torvalds 	err = sys_ustat(dev, &tmp);
11971da177e4SLinus Torvalds 	set_fs (old_fs);
11981da177e4SLinus Torvalds 
11991da177e4SLinus Torvalds 	if (err)
12001da177e4SLinus Torvalds 		goto out;
12011da177e4SLinus Torvalds 
12021da177e4SLinus Torvalds         memset(&tmp32,0,sizeof(struct ustat32));
12031da177e4SLinus Torvalds         tmp32.f_tfree = tmp.f_tfree;
12041da177e4SLinus Torvalds         tmp32.f_tinode = tmp.f_tinode;
12051da177e4SLinus Torvalds 
12061da177e4SLinus Torvalds         err = copy_to_user(ubuf32,&tmp32,sizeof(struct ustat32)) ? -EFAULT : 0;
12071da177e4SLinus Torvalds 
12081da177e4SLinus Torvalds out:
12091da177e4SLinus Torvalds 	return err;
12101da177e4SLinus Torvalds }
12111da177e4SLinus Torvalds 
12121da177e4SLinus Torvalds /* Handle adjtimex compatibility. */
12131da177e4SLinus Torvalds 
12141da177e4SLinus Torvalds struct timex32 {
12151da177e4SLinus Torvalds 	u32 modes;
12161da177e4SLinus Torvalds 	s32 offset, freq, maxerror, esterror;
12171da177e4SLinus Torvalds 	s32 status, constant, precision, tolerance;
12181da177e4SLinus Torvalds 	struct compat_timeval time;
12191da177e4SLinus Torvalds 	s32 tick;
12201da177e4SLinus Torvalds 	s32 ppsfreq, jitter, shift, stabil;
12211da177e4SLinus Torvalds 	s32 jitcnt, calcnt, errcnt, stbcnt;
12221da177e4SLinus Torvalds 	s32  :32; s32  :32; s32  :32; s32  :32;
12231da177e4SLinus Torvalds 	s32  :32; s32  :32; s32  :32; s32  :32;
12241da177e4SLinus Torvalds 	s32  :32; s32  :32; s32  :32; s32  :32;
12251da177e4SLinus Torvalds };
12261da177e4SLinus Torvalds 
12271da177e4SLinus Torvalds extern int do_adjtimex(struct timex *);
12281da177e4SLinus Torvalds 
12291da177e4SLinus Torvalds asmlinkage int sys32_adjtimex(struct timex32 *utp)
12301da177e4SLinus Torvalds {
12311da177e4SLinus Torvalds 	struct timex txc;
12321da177e4SLinus Torvalds 	int ret;
12331da177e4SLinus Torvalds 
12341da177e4SLinus Torvalds 	memset(&txc, 0, sizeof(struct timex));
12351da177e4SLinus Torvalds 
12361da177e4SLinus Torvalds 	if (get_user(txc.modes, &utp->modes) ||
12371da177e4SLinus Torvalds 	   __get_user(txc.offset, &utp->offset) ||
12381da177e4SLinus Torvalds 	   __get_user(txc.freq, &utp->freq) ||
12391da177e4SLinus Torvalds 	   __get_user(txc.maxerror, &utp->maxerror) ||
12401da177e4SLinus Torvalds 	   __get_user(txc.esterror, &utp->esterror) ||
12411da177e4SLinus Torvalds 	   __get_user(txc.status, &utp->status) ||
12421da177e4SLinus Torvalds 	   __get_user(txc.constant, &utp->constant) ||
12431da177e4SLinus Torvalds 	   __get_user(txc.precision, &utp->precision) ||
12441da177e4SLinus Torvalds 	   __get_user(txc.tolerance, &utp->tolerance) ||
12451da177e4SLinus Torvalds 	   __get_user(txc.time.tv_sec, &utp->time.tv_sec) ||
12461da177e4SLinus Torvalds 	   __get_user(txc.time.tv_usec, &utp->time.tv_usec) ||
12471da177e4SLinus Torvalds 	   __get_user(txc.tick, &utp->tick) ||
12481da177e4SLinus Torvalds 	   __get_user(txc.ppsfreq, &utp->ppsfreq) ||
12491da177e4SLinus Torvalds 	   __get_user(txc.jitter, &utp->jitter) ||
12501da177e4SLinus Torvalds 	   __get_user(txc.shift, &utp->shift) ||
12511da177e4SLinus Torvalds 	   __get_user(txc.stabil, &utp->stabil) ||
12521da177e4SLinus Torvalds 	   __get_user(txc.jitcnt, &utp->jitcnt) ||
12531da177e4SLinus Torvalds 	   __get_user(txc.calcnt, &utp->calcnt) ||
12541da177e4SLinus Torvalds 	   __get_user(txc.errcnt, &utp->errcnt) ||
12551da177e4SLinus Torvalds 	   __get_user(txc.stbcnt, &utp->stbcnt))
12561da177e4SLinus Torvalds 		return -EFAULT;
12571da177e4SLinus Torvalds 
12581da177e4SLinus Torvalds 	ret = do_adjtimex(&txc);
12591da177e4SLinus Torvalds 
12601da177e4SLinus Torvalds 	if (put_user(txc.modes, &utp->modes) ||
12611da177e4SLinus Torvalds 	   __put_user(txc.offset, &utp->offset) ||
12621da177e4SLinus Torvalds 	   __put_user(txc.freq, &utp->freq) ||
12631da177e4SLinus Torvalds 	   __put_user(txc.maxerror, &utp->maxerror) ||
12641da177e4SLinus Torvalds 	   __put_user(txc.esterror, &utp->esterror) ||
12651da177e4SLinus Torvalds 	   __put_user(txc.status, &utp->status) ||
12661da177e4SLinus Torvalds 	   __put_user(txc.constant, &utp->constant) ||
12671da177e4SLinus Torvalds 	   __put_user(txc.precision, &utp->precision) ||
12681da177e4SLinus Torvalds 	   __put_user(txc.tolerance, &utp->tolerance) ||
12691da177e4SLinus Torvalds 	   __put_user(txc.time.tv_sec, &utp->time.tv_sec) ||
12701da177e4SLinus Torvalds 	   __put_user(txc.time.tv_usec, &utp->time.tv_usec) ||
12711da177e4SLinus Torvalds 	   __put_user(txc.tick, &utp->tick) ||
12721da177e4SLinus Torvalds 	   __put_user(txc.ppsfreq, &utp->ppsfreq) ||
12731da177e4SLinus Torvalds 	   __put_user(txc.jitter, &utp->jitter) ||
12741da177e4SLinus Torvalds 	   __put_user(txc.shift, &utp->shift) ||
12751da177e4SLinus Torvalds 	   __put_user(txc.stabil, &utp->stabil) ||
12761da177e4SLinus Torvalds 	   __put_user(txc.jitcnt, &utp->jitcnt) ||
12771da177e4SLinus Torvalds 	   __put_user(txc.calcnt, &utp->calcnt) ||
12781da177e4SLinus Torvalds 	   __put_user(txc.errcnt, &utp->errcnt) ||
12791da177e4SLinus Torvalds 	   __put_user(txc.stbcnt, &utp->stbcnt))
12801da177e4SLinus Torvalds 		ret = -EFAULT;
12811da177e4SLinus Torvalds 
12821da177e4SLinus Torvalds 	return ret;
12831da177e4SLinus Torvalds }
12841da177e4SLinus Torvalds 
12851da177e4SLinus Torvalds asmlinkage int sys32_sendfile(int out_fd, int in_fd, compat_off_t *offset,
12861da177e4SLinus Torvalds 	s32 count)
12871da177e4SLinus Torvalds {
12881da177e4SLinus Torvalds 	mm_segment_t old_fs = get_fs();
12891da177e4SLinus Torvalds 	int ret;
12901da177e4SLinus Torvalds 	off_t of;
12911da177e4SLinus Torvalds 
12921da177e4SLinus Torvalds 	if (offset && get_user(of, offset))
12931da177e4SLinus Torvalds 		return -EFAULT;
12941da177e4SLinus Torvalds 
12951da177e4SLinus Torvalds 	set_fs(KERNEL_DS);
12961da177e4SLinus Torvalds 	ret = sys_sendfile(out_fd, in_fd, offset ? &of : NULL, count);
12971da177e4SLinus Torvalds 	set_fs(old_fs);
12981da177e4SLinus Torvalds 
12991da177e4SLinus Torvalds 	if (offset && put_user(of, offset))
13001da177e4SLinus Torvalds 		return -EFAULT;
13011da177e4SLinus Torvalds 
13021da177e4SLinus Torvalds 	return ret;
13031da177e4SLinus Torvalds }
13041da177e4SLinus Torvalds 
13051da177e4SLinus Torvalds asmlinkage ssize_t sys32_readahead(int fd, u32 pad0, u64 a2, u64 a3,
13061da177e4SLinus Torvalds                                    size_t count)
13071da177e4SLinus Torvalds {
13081da177e4SLinus Torvalds 	return sys_readahead(fd, merge_64(a2, a3), count);
13091da177e4SLinus Torvalds }
13101da177e4SLinus Torvalds 
13111da177e4SLinus Torvalds /* Argument list sizes for sys_socketcall */
13121da177e4SLinus Torvalds #define AL(x) ((x) * sizeof(unsigned int))
13131da177e4SLinus Torvalds static unsigned char socketcall_nargs[18]={AL(0),AL(3),AL(3),AL(3),AL(2),AL(3),
13141da177e4SLinus Torvalds 				AL(3),AL(3),AL(4),AL(4),AL(4),AL(6),
13151da177e4SLinus Torvalds 				AL(6),AL(2),AL(5),AL(5),AL(3),AL(3)};
13161da177e4SLinus Torvalds #undef AL
13171da177e4SLinus Torvalds 
13181da177e4SLinus Torvalds /*
13191da177e4SLinus Torvalds  *	System call vectors.
13201da177e4SLinus Torvalds  *
13211da177e4SLinus Torvalds  *	Argument checking cleaned up. Saved 20% in size.
13221da177e4SLinus Torvalds  *  This function doesn't need to set the kernel lock because
13231da177e4SLinus Torvalds  *  it is set by the callees.
13241da177e4SLinus Torvalds  */
13251da177e4SLinus Torvalds 
13261da177e4SLinus Torvalds asmlinkage long sys32_socketcall(int call, unsigned int *args32)
13271da177e4SLinus Torvalds {
13281da177e4SLinus Torvalds 	unsigned int a[6];
13291da177e4SLinus Torvalds 	unsigned int a0,a1;
13301da177e4SLinus Torvalds 	int err;
13311da177e4SLinus Torvalds 
13321da177e4SLinus Torvalds 	extern asmlinkage long sys_socket(int family, int type, int protocol);
13331da177e4SLinus Torvalds 	extern asmlinkage long sys_bind(int fd, struct sockaddr __user *umyaddr, int addrlen);
13341da177e4SLinus Torvalds 	extern asmlinkage long sys_connect(int fd, struct sockaddr __user *uservaddr, int addrlen);
13351da177e4SLinus Torvalds 	extern asmlinkage long sys_listen(int fd, int backlog);
13361da177e4SLinus Torvalds 	extern asmlinkage long sys_accept(int fd, struct sockaddr __user *upeer_sockaddr, int __user *upeer_addrlen);
13371da177e4SLinus Torvalds 	extern asmlinkage long sys_getsockname(int fd, struct sockaddr __user *usockaddr, int __user *usockaddr_len);
13381da177e4SLinus Torvalds 	extern asmlinkage long sys_getpeername(int fd, struct sockaddr __user *usockaddr, int __user *usockaddr_len);
13391da177e4SLinus Torvalds 	extern asmlinkage long sys_socketpair(int family, int type, int protocol, int __user *usockvec);
13401da177e4SLinus Torvalds 	extern asmlinkage long sys_send(int fd, void __user * buff, size_t len, unsigned flags);
13411da177e4SLinus Torvalds 	extern asmlinkage long sys_sendto(int fd, void __user * buff, size_t len, unsigned flags,
13421da177e4SLinus Torvalds 					  struct sockaddr __user *addr, int addr_len);
13431da177e4SLinus Torvalds 	extern asmlinkage long sys_recv(int fd, void __user * ubuf, size_t size, unsigned flags);
13441da177e4SLinus Torvalds 	extern asmlinkage long sys_recvfrom(int fd, void __user * ubuf, size_t size, unsigned flags,
13451da177e4SLinus Torvalds 					    struct sockaddr __user *addr, int __user *addr_len);
13461da177e4SLinus Torvalds 	extern asmlinkage long sys_shutdown(int fd, int how);
13471da177e4SLinus Torvalds 	extern asmlinkage long sys_setsockopt(int fd, int level, int optname, char __user *optval, int optlen);
13481da177e4SLinus Torvalds 	extern asmlinkage long sys_getsockopt(int fd, int level, int optname, char __user *optval, int *optlen);
13491da177e4SLinus Torvalds 	extern asmlinkage long sys_sendmsg(int fd, struct msghdr __user *msg, unsigned flags);
13501da177e4SLinus Torvalds 	extern asmlinkage long sys_recvmsg(int fd, struct msghdr __user *msg, unsigned int flags);
13511da177e4SLinus Torvalds 
13521da177e4SLinus Torvalds 
13531da177e4SLinus Torvalds 	if(call<1||call>SYS_RECVMSG)
13541da177e4SLinus Torvalds 		return -EINVAL;
13551da177e4SLinus Torvalds 
13561da177e4SLinus Torvalds 	/* copy_from_user should be SMP safe. */
13571da177e4SLinus Torvalds 	if (copy_from_user(a, args32, socketcall_nargs[call]))
13581da177e4SLinus Torvalds 		return -EFAULT;
13591da177e4SLinus Torvalds 
13601da177e4SLinus Torvalds 	a0=a[0];
13611da177e4SLinus Torvalds 	a1=a[1];
13621da177e4SLinus Torvalds 
13631da177e4SLinus Torvalds 	switch(call)
13641da177e4SLinus Torvalds 	{
13651da177e4SLinus Torvalds 		case SYS_SOCKET:
13661da177e4SLinus Torvalds 			err = sys_socket(a0,a1,a[2]);
13671da177e4SLinus Torvalds 			break;
13681da177e4SLinus Torvalds 		case SYS_BIND:
13691da177e4SLinus Torvalds 			err = sys_bind(a0,(struct sockaddr __user *)A(a1), a[2]);
13701da177e4SLinus Torvalds 			break;
13711da177e4SLinus Torvalds 		case SYS_CONNECT:
13721da177e4SLinus Torvalds 			err = sys_connect(a0, (struct sockaddr __user *)A(a1), a[2]);
13731da177e4SLinus Torvalds 			break;
13741da177e4SLinus Torvalds 		case SYS_LISTEN:
13751da177e4SLinus Torvalds 			err = sys_listen(a0,a1);
13761da177e4SLinus Torvalds 			break;
13771da177e4SLinus Torvalds 		case SYS_ACCEPT:
13781da177e4SLinus Torvalds 			err = sys_accept(a0,(struct sockaddr __user *)A(a1), (int __user *)A(a[2]));
13791da177e4SLinus Torvalds 			break;
13801da177e4SLinus Torvalds 		case SYS_GETSOCKNAME:
13811da177e4SLinus Torvalds 			err = sys_getsockname(a0,(struct sockaddr __user *)A(a1), (int __user *)A(a[2]));
13821da177e4SLinus Torvalds 			break;
13831da177e4SLinus Torvalds 		case SYS_GETPEERNAME:
13841da177e4SLinus Torvalds 			err = sys_getpeername(a0, (struct sockaddr __user *)A(a1), (int __user *)A(a[2]));
13851da177e4SLinus Torvalds 			break;
13861da177e4SLinus Torvalds 		case SYS_SOCKETPAIR:
13871da177e4SLinus Torvalds 			err = sys_socketpair(a0,a1, a[2], (int __user *)A(a[3]));
13881da177e4SLinus Torvalds 			break;
13891da177e4SLinus Torvalds 		case SYS_SEND:
13901da177e4SLinus Torvalds 			err = sys_send(a0, (void __user *)A(a1), a[2], a[3]);
13911da177e4SLinus Torvalds 			break;
13921da177e4SLinus Torvalds 		case SYS_SENDTO:
13931da177e4SLinus Torvalds 			err = sys_sendto(a0,(void __user *)A(a1), a[2], a[3],
13941da177e4SLinus Torvalds 					 (struct sockaddr __user *)A(a[4]), a[5]);
13951da177e4SLinus Torvalds 			break;
13961da177e4SLinus Torvalds 		case SYS_RECV:
13971da177e4SLinus Torvalds 			err = sys_recv(a0, (void __user *)A(a1), a[2], a[3]);
13981da177e4SLinus Torvalds 			break;
13991da177e4SLinus Torvalds 		case SYS_RECVFROM:
14001da177e4SLinus Torvalds 			err = sys_recvfrom(a0, (void __user *)A(a1), a[2], a[3],
14011da177e4SLinus Torvalds 					   (struct sockaddr __user *)A(a[4]), (int __user *)A(a[5]));
14021da177e4SLinus Torvalds 			break;
14031da177e4SLinus Torvalds 		case SYS_SHUTDOWN:
14041da177e4SLinus Torvalds 			err = sys_shutdown(a0,a1);
14051da177e4SLinus Torvalds 			break;
14061da177e4SLinus Torvalds 		case SYS_SETSOCKOPT:
14071da177e4SLinus Torvalds 			err = sys_setsockopt(a0, a1, a[2], (char __user *)A(a[3]), a[4]);
14081da177e4SLinus Torvalds 			break;
14091da177e4SLinus Torvalds 		case SYS_GETSOCKOPT:
14101da177e4SLinus Torvalds 			err = sys_getsockopt(a0, a1, a[2], (char __user *)A(a[3]), (int __user *)A(a[4]));
14111da177e4SLinus Torvalds 			break;
14121da177e4SLinus Torvalds 		case SYS_SENDMSG:
14131da177e4SLinus Torvalds 			err = sys_sendmsg(a0, (struct msghdr __user *) A(a1), a[2]);
14141da177e4SLinus Torvalds 			break;
14151da177e4SLinus Torvalds 		case SYS_RECVMSG:
14161da177e4SLinus Torvalds 			err = sys_recvmsg(a0, (struct msghdr __user *) A(a1), a[2]);
14171da177e4SLinus Torvalds 			break;
14181da177e4SLinus Torvalds 		default:
14191da177e4SLinus Torvalds 			err = -EINVAL;
14201da177e4SLinus Torvalds 			break;
14211da177e4SLinus Torvalds 	}
14221da177e4SLinus Torvalds 	return err;
14231da177e4SLinus Torvalds }
1424d1abb6a2SRalf Baechle 
1425d1abb6a2SRalf Baechle struct sigevent32 {
1426d1abb6a2SRalf Baechle 	u32 sigev_value;
1427d1abb6a2SRalf Baechle 	u32 sigev_signo;
1428d1abb6a2SRalf Baechle 	u32 sigev_notify;
1429d1abb6a2SRalf Baechle 	u32 payload[(64 / 4) - 3];
1430d1abb6a2SRalf Baechle };
1431d1abb6a2SRalf Baechle 
1432d1abb6a2SRalf Baechle extern asmlinkage long
1433d1abb6a2SRalf Baechle sys_timer_create(clockid_t which_clock,
1434d1abb6a2SRalf Baechle 		 struct sigevent __user *timer_event_spec,
1435d1abb6a2SRalf Baechle 		 timer_t __user * created_timer_id);
1436d1abb6a2SRalf Baechle 
1437d1abb6a2SRalf Baechle long
1438d1abb6a2SRalf Baechle sys32_timer_create(u32 clock, struct sigevent32 __user *se32, timer_t __user *timer_id)
1439d1abb6a2SRalf Baechle {
1440d1abb6a2SRalf Baechle 	struct sigevent __user *p = NULL;
1441d1abb6a2SRalf Baechle 	if (se32) {
1442d1abb6a2SRalf Baechle 		struct sigevent se;
1443d1abb6a2SRalf Baechle 		p = compat_alloc_user_space(sizeof(struct sigevent));
1444d1abb6a2SRalf Baechle 		memset(&se, 0, sizeof(struct sigevent));
1445d1abb6a2SRalf Baechle 		if (get_user(se.sigev_value.sival_int,  &se32->sigev_value) ||
1446d1abb6a2SRalf Baechle 		    __get_user(se.sigev_signo, &se32->sigev_signo) ||
1447d1abb6a2SRalf Baechle 		    __get_user(se.sigev_notify, &se32->sigev_notify) ||
1448d1abb6a2SRalf Baechle 		    __copy_from_user(&se._sigev_un._pad, &se32->payload,
1449d1abb6a2SRalf Baechle 				     sizeof(se32->payload)) ||
1450d1abb6a2SRalf Baechle 		    copy_to_user(p, &se, sizeof(se)))
1451d1abb6a2SRalf Baechle 			return -EFAULT;
1452d1abb6a2SRalf Baechle 	}
1453d1abb6a2SRalf Baechle 	return sys_timer_create(clock, p, timer_id);
1454d1abb6a2SRalf Baechle }
1455d1abb6a2SRalf Baechle 
14563c37026dSRalf Baechle save_static_function(sys32_clone);
14573c37026dSRalf Baechle __attribute_used__ noinline static int
14583c37026dSRalf Baechle _sys32_clone(nabi_no_regargs struct pt_regs regs)
14593c37026dSRalf Baechle {
14603c37026dSRalf Baechle 	unsigned long clone_flags;
14613c37026dSRalf Baechle 	unsigned long newsp;
14623c37026dSRalf Baechle 	int __user *parent_tidptr, *child_tidptr;
14633c37026dSRalf Baechle 
14643c37026dSRalf Baechle 	clone_flags = regs.regs[4];
14653c37026dSRalf Baechle 	newsp = regs.regs[5];
14663c37026dSRalf Baechle 	if (!newsp)
14673c37026dSRalf Baechle 		newsp = regs.regs[29];
14683c37026dSRalf Baechle 	parent_tidptr = (int *) regs.regs[6];
14693c37026dSRalf Baechle 
14703c37026dSRalf Baechle 	/* Use __dummy4 instead of getting it off the stack, so that
14713c37026dSRalf Baechle 	   syscall() works.  */
14723c37026dSRalf Baechle 	child_tidptr = (int __user *) __dummy4;
14733c37026dSRalf Baechle 	return do_fork(clone_flags, newsp, &regs, 0,
14743c37026dSRalf Baechle 	               parent_tidptr, child_tidptr);
14753c37026dSRalf Baechle }
14763c37026dSRalf Baechle 
14773c37026dSRalf Baechle extern asmlinkage void sys_set_thread_area(u32 addr);
14783c37026dSRalf Baechle asmlinkage void sys32_set_thread_area(u32 addr)
14793c37026dSRalf Baechle {
14803c37026dSRalf Baechle 	sys_set_thread_area(AA(addr));
14813c37026dSRalf Baechle }
1482