Merge branch 'fixes' of git://git.linaro.org/people/rmk/linux-arm
[linux-flexiantxendom0-3.2.10.git] / ipc / compat.c
index ab76fb0..a6df704 100644 (file)
@@ -26,8 +26,8 @@
 #include <linux/init.h>
 #include <linux/msg.h>
 #include <linux/shm.h>
-#include <linux/slab.h>
 #include <linux/syscalls.h>
+#include <linux/ptrace.h>
 
 #include <linux/mutex.h>
 #include <asm/uaccess.h>
@@ -118,6 +118,7 @@ extern int sem_ctls[];
 
 static inline int compat_ipc_parse_version(int *cmd)
 {
+#ifdef CONFIG_ARCH_WANT_OLD_COMPAT_IPC
        int version = *cmd & IPC_64;
 
        /* this is tricky: architectures that have support for the old
@@ -129,6 +130,10 @@ static inline int compat_ipc_parse_version(int *cmd)
        *cmd &= ~IPC_64;
 #endif
        return version;
+#else
+       /* With the asm-generic APIs, we always use the 64-bit versions. */
+       return IPC_64;
+#endif
 }
 
 static inline int __get_compat_ipc64_perm(struct ipc64_perm *p64,
@@ -233,19 +238,16 @@ static inline int put_compat_semid_ds(struct semid64_ds *s,
        return err;
 }
 
-long compat_sys_semctl(int first, int second, int third, void __user *uptr)
+static long do_compat_semctl(int first, int second, int third, u32 pad)
 {
        union semun fourth;
-       u32 pad;
        int err, err2;
        struct semid64_ds s64;
        struct semid64_ds __user *up64;
        int version = compat_ipc_parse_version(&third);
 
-       if (!uptr)
-               return -EINVAL;
-       if (get_user(pad, (u32 __user *) uptr))
-               return -EFAULT;
+       memset(&s64, 0, sizeof(s64));
+
        if ((third & (~IPC_64)) == SETVAL)
                fourth.val = (int) pad;
        else
@@ -304,6 +306,18 @@ long compat_sys_semctl(int first, int second, int third, void __user *uptr)
        return err;
 }
 
+#ifdef CONFIG_ARCH_WANT_OLD_COMPAT_IPC
+long compat_sys_semctl(int first, int second, int third, void __user *uptr)
+{
+       u32 pad;
+
+       if (!uptr)
+               return -EINVAL;
+       if (get_user(pad, (u32 __user *) uptr))
+               return -EFAULT;
+       return do_compat_semctl(first, second, third, pad);
+}
+
 long compat_sys_msgsnd(int first, int second, int third, void __user *uptr)
 {
        struct compat_msgbuf __user *up = uptr;
@@ -352,6 +366,37 @@ long compat_sys_msgrcv(int first, int second, int msgtyp, int third,
 out:
        return err;
 }
+#else
+long compat_sys_semctl(int semid, int semnum, int cmd, int arg)
+{
+       return do_compat_semctl(semid, semnum, cmd, arg);
+}
+
+long compat_sys_msgsnd(int msqid, struct compat_msgbuf __user *msgp,
+                      size_t msgsz, int msgflg)
+{
+       compat_long_t mtype;
+
+       if (get_user(mtype, &msgp->mtype))
+               return -EFAULT;
+       return do_msgsnd(msqid, mtype, msgp->mtext, msgsz, msgflg);
+}
+
+long compat_sys_msgrcv(int msqid, struct compat_msgbuf __user *msgp,
+                      size_t msgsz, long msgtyp, int msgflg)
+{
+       long err, mtype;
+
+       err =  do_msgrcv(msqid, &mtype, msgp->mtext, msgsz, msgtyp, msgflg);
+       if (err < 0)
+               goto out;
+
+       if (put_user(mtype, &msgp->mtype))
+               err = -EFAULT;
+ out:
+       return err;
+}
+#endif
 
 static inline int get_compat_msqid64(struct msqid64_ds *m64,
                                     struct compat_msqid64_ds __user *up64)
@@ -422,6 +467,8 @@ long compat_sys_msgctl(int first, int second, void __user *uptr)
        int version = compat_ipc_parse_version(&second);
        void __user *p;
 
+       memset(&m64, 0, sizeof(m64));
+
        switch (second & (~IPC_64)) {
        case IPC_INFO:
        case IPC_RMID:
@@ -467,6 +514,7 @@ long compat_sys_msgctl(int first, int second, void __user *uptr)
        return err;
 }
 
+#ifdef CONFIG_ARCH_WANT_OLD_COMPAT_IPC
 long compat_sys_shmat(int first, int second, compat_uptr_t third, int version,
                        void __user *uptr)
 {
@@ -482,6 +530,19 @@ long compat_sys_shmat(int first, int second, compat_uptr_t third, int version,
        uaddr = compat_ptr(third);
        return put_user(raddr, uaddr);
 }
+#else
+long compat_sys_shmat(int shmid, compat_uptr_t shmaddr, int shmflg)
+{
+       unsigned long ret;
+       long err;
+
+       err = do_shmat(shmid, compat_ptr(shmaddr), shmflg, &ret);
+       if (err)
+               return err;
+       force_successful_syscall_return();
+       return (long)ret;
+}
+#endif
 
 static inline int get_compat_shmid64_ds(struct shmid64_ds *s64,
                                        struct compat_shmid64_ds __user *up64)
@@ -595,6 +656,8 @@ long compat_sys_shmctl(int first, int second, void __user *uptr)
        int err, err2;
        int version = compat_ipc_parse_version(&second);
 
+       memset(&s64, 0, sizeof(s64));
+
        switch (second & (~IPC_64)) {
        case IPC_RMID:
        case SHM_LOCK: