*/
 
 struct atmif_sioc {
-    int number;
-    int length;
-    void __user *arg;
+       int number;
+       int length;
+       void __user *arg;
 };
 
+#ifdef __KERNEL__
+#ifdef CONFIG_COMPAT
+#include <linux/compat.h>
+struct compat_atmif_sioc {
+       int number;
+       int length;
+       compat_uptr_t arg;
+};
+#endif
+#endif
+
 typedef unsigned short atm_backend_t;
 #endif
 
                                        /* use backend to make new if */
 #define ATM_ADDPARTY   _IOW('a', ATMIOC_SPECIAL+4,struct atm_iobuf)
                                        /* add party to p2mp call */
+#ifdef CONFIG_COMPAT
+/* It actually takes struct sockaddr_atmsvc, not struct atm_iobuf */
+#define COMPAT_ATM_ADDPARTY    _IOW('a', ATMIOC_SPECIAL+4,struct compat_atm_iobuf)
+#endif
 #define ATM_DROPPARTY  _IOW('a', ATMIOC_SPECIAL+5,int)
                                        /* drop party from p2mp call */
 
 extern struct proc_dir_entry *atm_proc_root;
 #endif
 
+#ifdef CONFIG_COMPAT
+#include <linux/compat.h>
+struct compat_atm_iobuf {
+       int length;
+       compat_uptr_t buffer;
+};
+#endif
 
 struct k_atm_aal_stats {
 #define __HANDLE_ITEM(i) atomic_t i
        int (*open)(struct atm_vcc *vcc);
        void (*close)(struct atm_vcc *vcc);
        int (*ioctl)(struct atm_dev *dev,unsigned int cmd,void __user *arg);
+#ifdef CONFIG_COMPAT
+       int (*compat_ioctl)(struct atm_dev *dev,unsigned int cmd,
+                           void __user *arg);
+#endif
        int (*getsockopt)(struct atm_vcc *vcc,int level,int optname,
            void __user *optval,int optlen);
        int (*setsockopt)(struct atm_vcc *vcc,int level,int optname,
 
                size_t total_len);
 unsigned int vcc_poll(struct file *file, struct socket *sock, poll_table *wait);
 int vcc_ioctl(struct socket *sock, unsigned int cmd, unsigned long arg);
+int vcc_compat_ioctl(struct socket *sock, unsigned int cmd, unsigned long arg);
 int vcc_setsockopt(struct socket *sock, int level, int optname,
                   char __user *optval, int optlen);
 int vcc_getsockopt(struct socket *sock, int level, int optname,
 
 #include <linux/atmlec.h>
 #include <linux/mutex.h>
 #include <asm/ioctls.h>
+#include <net/compat.h>
 
 #include "resources.h"
 #include "signaling.h"         /* for WAITING and sigd_attach */
 EXPORT_SYMBOL(register_atm_ioctl);
 EXPORT_SYMBOL(deregister_atm_ioctl);
 
-int vcc_ioctl(struct socket *sock, unsigned int cmd, unsigned long arg)
+static int do_vcc_ioctl(struct socket *sock, unsigned int cmd, unsigned long arg, int compat)
 {
        struct sock *sk = sock->sk;
        struct atm_vcc *vcc;
                                goto done;
                        }
                case SIOCGSTAMP: /* borrowed from IP */
-                       error = sock_get_timestamp(sk, argp);
+#ifdef CONFIG_COMPAT
+                       if (compat)
+                               error = compat_sock_get_timestamp(sk, argp);
+                       else
+#endif
+                               error = sock_get_timestamp(sk, argp);
                        goto done;
                case SIOCGSTAMPNS: /* borrowed from IP */
-                       error = sock_get_timestampns(sk, argp);
+#ifdef CONFIG_COMPAT
+                       if (compat)
+                               error = compat_sock_get_timestampns(sk, argp);
+                       else
+#endif
+                               error = sock_get_timestampns(sk, argp);
                        goto done;
                case ATM_SETSC:
-                       printk(KERN_WARNING "ATM_SETSC is obsolete\n");
+                       if (net_ratelimit())
+                               printk(KERN_WARNING "ATM_SETSC is obsolete; used by %s:%d\n",
+                                      current->comm, task_pid_nr(current));
                        error = 0;
                        goto done;
                case ATMSIGD_CTRL:
                         * info uses kernel pointers as opaque references,
                         * so the holder of the file descriptor can scribble
                         * on the kernel... so we should make sure that we
-                        * have the same privledges that /proc/kcore needs
+                        * have the same privileges that /proc/kcore needs
                         */
                        if (!capable(CAP_SYS_RAWIO)) {
                                error = -EPERM;
                                goto done;
                        }
+#ifdef CONFIG_COMPAT
+                       /* WTF? I don't even want to _think_ about making this
+                          work for 32-bit userspace. TBH I don't really want
+                          to think about it at all. dwmw2. */
+                       if (compat) {
+                               if (net_ratelimit())
+                                       printk(KERN_WARNING "32-bit task cannot be atmsigd\n");
+                               error = -EINVAL;
+                               goto done;
+                       }
+#endif
                        error = sigd_attach(vcc);
                        if (!error)
                                sock->state = SS_CONNECTED;
        if (error != -ENOIOCTLCMD)
                goto done;
 
-       error = atm_dev_ioctl(cmd, argp);
+       error = atm_dev_ioctl(cmd, argp, compat);
 
 done:
        return error;
 }
+
+
+int vcc_ioctl(struct socket *sock, unsigned int cmd, unsigned long arg)
+{
+       return do_vcc_ioctl(sock, cmd, arg, 0);
+}
+
+#ifdef CONFIG_COMPAT
+int vcc_compat_ioctl(struct socket *sock, unsigned int cmd, unsigned long arg)
+{
+       return do_vcc_ioctl(sock, cmd, arg, 1);
+}
+#endif
 
        .getname =      pvc_getname,
        .poll =         vcc_poll,
        .ioctl =        vcc_ioctl,
+#ifdef CONFIG_COMPAT
+       .compat_ioctl = vcc_compat_ioctl,
+#endif
        .listen =       sock_no_listen,
        .shutdown =     pvc_shutdown,
        .setsockopt =   pvc_setsockopt,
 
 }
 
 
-int atm_dev_ioctl(unsigned int cmd, void __user *arg)
+int atm_dev_ioctl(unsigned int cmd, void __user *arg, int compat)
 {
        void __user *buf;
        int error, len, number, size = 0;
        struct atm_dev *dev;
        struct list_head *p;
        int *tmp_buf, *tmp_p;
-       struct atm_iobuf __user *iobuf = arg;
-       struct atmif_sioc __user *sioc = arg;
+       int __user *sioc_len;
+       int __user *iobuf_len;
+
+#ifndef CONFIG_COMPAT
+       compat = 0; /* Just so the compiler _knows_ */
+#endif
+
        switch (cmd) {
                case ATM_GETNAMES:
-                       if (get_user(buf, &iobuf->buffer))
-                               return -EFAULT;
-                       if (get_user(len, &iobuf->length))
+
+                       if (compat) {
+#ifdef CONFIG_COMPAT
+                               struct compat_atm_iobuf __user *ciobuf = arg;
+                               compat_uptr_t cbuf;
+                               iobuf_len = &ciobuf->length;
+                               if (get_user(cbuf, &ciobuf->buffer))
+                                       return -EFAULT;
+                               buf = compat_ptr(cbuf);
+#endif
+                       } else {
+                               struct atm_iobuf __user *iobuf = arg;
+                               iobuf_len = &iobuf->length;
+                               if (get_user(buf, &iobuf->buffer))
+                                       return -EFAULT;
+                       }
+                       if (get_user(len, iobuf_len))
                                return -EFAULT;
                        mutex_lock(&atm_dev_mutex);
                        list_for_each(p, &atm_devs)
                        }
                        mutex_unlock(&atm_dev_mutex);
                        error = ((copy_to_user(buf, tmp_buf, size)) ||
-                                       put_user(size, &iobuf->length))
+                                       put_user(size, iobuf_len))
                                                ? -EFAULT : 0;
                        kfree(tmp_buf);
                        return error;
                        break;
        }
 
-       if (get_user(buf, &sioc->arg))
-               return -EFAULT;
-       if (get_user(len, &sioc->length))
-               return -EFAULT;
-       if (get_user(number, &sioc->number))
-               return -EFAULT;
-
+       if (compat) {
+#ifdef CONFIG_COMPAT
+               struct compat_atmif_sioc __user *csioc = arg;
+               compat_uptr_t carg;
+
+               sioc_len = &csioc->length;
+               if (get_user(carg, &csioc->arg))
+                       return -EFAULT;
+               buf = compat_ptr(carg);
+
+               if (get_user(len, &csioc->length))
+                       return -EFAULT;
+               if (get_user(number, &csioc->number))
+                       return -EFAULT;
+#endif
+       } else {
+               struct atmif_sioc __user *sioc = arg;
+
+               sioc_len = &sioc->length;
+               if (get_user(buf, &sioc->arg))
+                       return -EFAULT;
+               if (get_user(len, &sioc->length))
+                       return -EFAULT;
+               if (get_user(number, &sioc->number))
+                       return -EFAULT;
+       }
        if (!(dev = try_then_request_module(atm_dev_lookup(number),
                                            "atm-device-%d", number)))
                return -ENODEV;
                        size = error;
                        /* may return 0, but later on size == 0 means "don't
                           write the length" */
-                       error = put_user(size, &sioc->length)
+                       error = put_user(size, sioc_len)
                                ? -EFAULT : 0;
                        goto done;
                case ATM_SETLOOP:
                        }
                        /* fall through */
                default:
-                       if (!dev->ops->ioctl) {
-                               error = -EINVAL;
-                               goto done;
+                       if (compat) {
+#ifdef CONFIG_COMPAT
+                               if (!dev->ops->compat_ioctl) {
+                                       error = -EINVAL;
+                                       goto done;
+                               }
+                               size = dev->ops->compat_ioctl(dev, cmd, buf);
+#endif
+                       } else {
+                               if (!dev->ops->ioctl) {
+                                       error = -EINVAL;
+                                       goto done;
+                               }
+                               size = dev->ops->ioctl(dev, cmd, buf);
                        }
-                       size = dev->ops->ioctl(dev, cmd, buf);
                        if (size < 0) {
                                error = (size == -ENOIOCTLCMD ? -EINVAL : size);
                                goto done;
        }
 
        if (size)
-               error = put_user(size, &sioc->length)
+               error = put_user(size, sioc_len)
                        ? -EFAULT : 0;
        else
                error = 0;
 
 extern struct list_head atm_devs;
 extern struct mutex atm_dev_mutex;
 
-int atm_dev_ioctl(unsigned int cmd, void __user *arg);
+int atm_dev_ioctl(unsigned int cmd, void __user *arg, int compat);
 
 
 #ifdef CONFIG_PROC_FS
 
        return error;
 }
 
+#ifdef CONFIG_COMPAT
+static int svc_compat_ioctl(struct socket *sock, unsigned int cmd, unsigned long arg)
+{
+       /* The definition of ATM_ADDPARTY uses the size of struct atm_iobuf.
+          But actually it takes a struct sockaddr_atmsvc, which doesn't need
+          compat handling. So all we have to do is fix up cmd... */
+       if (cmd == COMPAT_ATM_ADDPARTY)
+               cmd = ATM_ADDPARTY;
+
+       if (cmd == ATM_ADDPARTY || cmd == ATM_DROPPARTY)
+               return svc_ioctl(sock, cmd, arg);
+       else
+               return vcc_compat_ioctl(sock, cmd, arg);
+}
+#endif /* CONFIG_COMPAT */
+
 static const struct proto_ops svc_proto_ops = {
        .family =       PF_ATMSVC,
        .owner =        THIS_MODULE,
        .getname =      svc_getname,
        .poll =         vcc_poll,
        .ioctl =        svc_ioctl,
+#ifdef CONFIG_COMPAT
+       .compat_ioctl = svc_compat_ioctl,
+#endif
        .listen =       svc_listen,
        .shutdown =     svc_shutdown,
        .setsockopt =   svc_setsockopt,