Module: xenomai-3
Branch: master
Commit: 4572997e878f24625c8ddbfa5256b8f423679bf8
URL:    
http://git.xenomai.org/?p=xenomai-3.git;a=commit;h=4572997e878f24625c8ddbfa5256b8f423679bf8

Author: Philippe Gerum <r...@xenomai.org>
Date:   Tue Oct 28 19:14:09 2014 +0100

cobalt: factor out compat helpers for common types

---

 .../posix => include/cobalt/kernel}/compat.h       |   34 ++++++-------
 include/cobalt/kernel/rtdm/cobalt.h                |    1 -
 include/cobalt/kernel/rtdm/compat.h                |    3 +-
 kernel/cobalt/posix/compat.c                       |   44 +++++++++++++++-
 kernel/cobalt/posix/syscall32.c                    |   13 +++++
 kernel/cobalt/posix/syscall32.h                    |    8 ++-
 kernel/drivers/ipc/rtipc.c                         |   53 +++++---------------
 7 files changed, 93 insertions(+), 63 deletions(-)

diff --git a/kernel/cobalt/posix/compat.h b/include/cobalt/kernel/compat.h
similarity index 86%
rename from kernel/cobalt/posix/compat.h
rename to include/cobalt/kernel/compat.h
index 466ea43..6a2e838 100644
--- a/kernel/cobalt/posix/compat.h
+++ b/include/cobalt/kernel/compat.h
@@ -15,26 +15,16 @@
  * along with this program; if not, write to the Free Software
  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
  */
-#ifndef _COBALT_POSIX_COMPAT_H
-#define _COBALT_POSIX_COMPAT_H
+#ifndef _COBALT_KERNEL_COMPAT_H
+#define _COBALT_KERNEL_COMPAT_H
 
 #ifdef CONFIG_COMPAT
 
-#include <rtdm/compat.h>
-/* CAUTION: rtdm/cobalt.h reads this header. */
-#include <xenomai/posix/thread.h>
-#include <xenomai/posix/mutex.h>
-#include <xenomai/posix/cond.h>
-#include <xenomai/posix/sem.h>
-#include <xenomai/posix/sched.h>
-#include <xenomai/posix/mqueue.h>
-#include <xenomai/posix/clock.h>
-#include <xenomai/posix/timer.h>
-#include <xenomai/posix/timerfd.h>
-#include <xenomai/posix/signal.h>
-#include <xenomai/posix/monitor.h>
-#include <xenomai/posix/event.h>
-#include <xenomai/posix/io.h>
+#include <linux/compat.h>
+#include <net/compat.h>
+#include <cobalt/uapi/sched.h>
+
+struct mq_attr;
 
 struct __compat_sched_ss_param {
        int __sched_low_priority;
@@ -150,6 +140,14 @@ int sys32_get_msghdr(struct msghdr *msg,
 int sys32_put_msghdr(struct compat_msghdr __user *u_cmsg,
                     const struct msghdr *msg);
 
+int sys32_get_iovec(struct iovec *iov,
+                   const struct compat_iovec __user *ciov,
+                   int ciovlen);
+
+int sys32_put_iovec(struct compat_iovec __user *u_ciov,
+                   const struct iovec *iov,
+                   int iovlen);
+
 #endif /* CONFIG_COMPAT */
 
-#endif /* !_COBALT_POSIX_COMPAT_H */
+#endif /* !_COBALT_KERNEL_COMPAT_H */
diff --git a/include/cobalt/kernel/rtdm/cobalt.h 
b/include/cobalt/kernel/rtdm/cobalt.h
index fc75430..2c38053 100644
--- a/include/cobalt/kernel/rtdm/cobalt.h
+++ b/include/cobalt/kernel/rtdm/cobalt.h
@@ -29,6 +29,5 @@
 #include <xenomai/posix/clock.h>
 #include <xenomai/posix/event.h>
 #include <xenomai/posix/monitor.h>
-#include <xenomai/posix/compat.h>
 
 #endif /* !_COBALT_RTDM_COBALT_H */
diff --git a/include/cobalt/kernel/rtdm/compat.h 
b/include/cobalt/kernel/rtdm/compat.h
index 44b6884..974f9bd 100644
--- a/include/cobalt/kernel/rtdm/compat.h
+++ b/include/cobalt/kernel/rtdm/compat.h
@@ -20,8 +20,7 @@
 
 #ifdef CONFIG_COMPAT
 
-#include <linux/compat.h>
-#include <net/compat.h>
+#include <cobalt/kernel/compat.h>
 #include <rtdm/rtdm.h>
 
 struct compat_rtdm_getsockopt_args {
diff --git a/kernel/cobalt/posix/compat.c b/kernel/cobalt/posix/compat.c
index 948616c..5808371 100644
--- a/kernel/cobalt/posix/compat.c
+++ b/kernel/cobalt/posix/compat.c
@@ -17,7 +17,9 @@
  */
 #include <linux/err.h>
 #include <linux/module.h>
-#include "compat.h"
+#include <cobalt/kernel/compat.h>
+#include <asm/xenomai/syscall.h>
+#include <xenomai/posix/mqueue.h>
 
 int sys32_get_timespec(struct timespec *ts,
                       const struct compat_timespec __user *cts)
@@ -379,3 +381,43 @@ int sys32_put_msghdr(struct compat_msghdr __user *u_cmsg,
        return 0;
 }
 EXPORT_SYMBOL_GPL(sys32_put_msghdr);
+
+int sys32_get_iovec(struct iovec *iov,
+                   const struct compat_iovec __user *u_ciov,
+                   int ciovlen)
+{
+       const struct compat_iovec __user *p;
+       struct compat_iovec ciov;
+       int ret, n;
+       
+       for (n = 0, p = u_ciov; n < ciovlen; n++, p++) {
+               ret = __xn_safe_copy_from_user(&ciov, p, sizeof(ciov));
+               if (ret)
+                       return ret;
+               iov[n].iov_base = compat_ptr(ciov.iov_base);
+               iov[n].iov_len = ciov.iov_len;
+       }
+
+       return 0;
+}
+EXPORT_SYMBOL_GPL(sys32_get_iovec);
+
+int sys32_put_iovec(struct compat_iovec __user *u_ciov,
+                   const struct iovec *iov,
+                   int iovlen)
+{
+       struct compat_iovec __user *p;
+       struct compat_iovec ciov;
+       int ret, n;
+       
+       for (n = 0, p = u_ciov; n < iovlen; n++, p++) {
+               ciov.iov_base = ptr_to_compat(iov[n].iov_base);
+               ciov.iov_len = iov[n].iov_len;
+               ret = __xn_safe_copy_to_user(p, &ciov, sizeof(*p));
+               if (ret)
+                       return ret;
+       }
+
+       return 0;
+}
+EXPORT_SYMBOL_GPL(sys32_put_iovec);
diff --git a/kernel/cobalt/posix/syscall32.c b/kernel/cobalt/posix/syscall32.c
index e813d21..87ea0b7 100644
--- a/kernel/cobalt/posix/syscall32.c
+++ b/kernel/cobalt/posix/syscall32.c
@@ -21,6 +21,19 @@
 #include <xenomai/rtdm/internal.h>
 #include "internal.h"
 #include "syscall32.h"
+#include "thread.h"
+#include "mutex.h"
+#include "cond.h"
+#include "sem.h"
+#include "sched.h"
+#include "clock.h"
+#include "timer.h"
+#include "timerfd.h"
+#include "signal.h"
+#include "monitor.h"
+#include "event.h"
+#include "mqueue.h"
+#include "io.h"
 #include "../debug.h"
 
 COBALT_SYSCALL32emu(thread_create, init,
diff --git a/kernel/cobalt/posix/syscall32.h b/kernel/cobalt/posix/syscall32.h
index c759820..99fe140 100644
--- a/kernel/cobalt/posix/syscall32.h
+++ b/kernel/cobalt/posix/syscall32.h
@@ -18,7 +18,13 @@
 #ifndef _COBALT_POSIX_SYSCALL32_H
 #define _COBALT_POSIX_SYSCALL32_H
 
-#include "compat.h"
+#include <cobalt/kernel/compat.h>
+
+struct cobalt_mutex_shadow;
+struct cobalt_event_shadow;
+struct cobalt_cond_shadow;
+struct cobalt_sem_shadow;
+struct cobalt_monitor_shadow;
 
 COBALT_SYSCALL32emu_DECL(thread_create,
                         int, (compat_ulong_t pth,
diff --git a/kernel/drivers/ipc/rtipc.c b/kernel/drivers/ipc/rtipc.c
index 4c569c7..1c705c4 100644
--- a/kernel/drivers/ipc/rtipc.c
+++ b/kernel/drivers/ipc/rtipc.c
@@ -22,6 +22,7 @@
 #include <linux/slab.h>
 #include <linux/poll.h>
 #include <rtdm/ipc.h>
+#include <rtdm/compat.h>
 #include "internal.h"
 
 MODULE_DESCRIPTION("Real-time IPC interface");
@@ -66,25 +67,17 @@ int rtipc_get_iovec(struct rtdm_fd *fd, struct iovec *iov,
                    const struct msghdr *msg)
 {
        size_t len = sizeof(iov[0]) * msg->msg_iovlen;
+
        if (!rtdm_fd_is_user(fd)) {
                memcpy(iov, msg->msg_iov, len);
                return 0;
        }
 
 #ifdef CONFIG_COMPAT
-       if (rtdm_fd_is_compat(fd)) {
-               struct compat_iovec ciov, __user *p;
-               int ret, n;
-               for (n = 0, p = (struct compat_iovec *)msg->msg_iov;
-                    n < msg->msg_iovlen; n++, p++) {
-                       ret = rtdm_copy_from_user(fd, &ciov, p, sizeof(ciov));
-                       if (ret)
-                               return ret;
-                       iov[n].iov_base = compat_ptr(ciov.iov_base);
-                       iov[n].iov_len = ciov.iov_len;
-               }
-               return 0;
-       }
+       if (rtdm_fd_is_compat(fd))
+               return sys32_get_iovec(iov,
+                              (struct compat_iovec __user *)msg->msg_iov,
+                              msg->msg_iovlen);
 #endif
 
        return rtdm_copy_from_user(fd, iov, msg->msg_iov, len);
@@ -101,19 +94,9 @@ int rtipc_put_iovec(struct rtdm_fd *fd, const struct iovec 
*iov,
        }
 
 #ifdef CONFIG_COMPAT
-       if (rtdm_fd_is_compat(fd)) {
-               struct compat_iovec ciov, __user *p;
-               int ret, n;
-               for (n = 0, p = (struct compat_iovec *)msg->msg_iov;
-                    n < msg->msg_iovlen; n++, p++) {
-                       ciov.iov_base = ptr_to_compat(iov[n].iov_base);
-                       ciov.iov_len = iov[n].iov_len;
-                       ret = rtdm_copy_to_user(fd, p, &ciov, sizeof(*p));
-                       if (ret)
-                               return ret;
-               }
-               return 0;
-       }
+       if (rtdm_fd_is_compat(fd))
+               return sys32_put_iovec((struct compat_iovec __user 
*)msg->msg_iov,
+                                      iov, msg->msg_iovlen);
 #endif
 
        return rtdm_copy_to_user(fd, msg->msg_iov, iov, len);
@@ -326,14 +309,9 @@ int rtipc_get_timeval(struct rtdm_fd *fd, struct timeval 
*tv,
 {
 #ifdef CONFIG_COMPAT
        if (rtdm_fd_is_compat(fd)) {
-               const struct compat_timeval *ctv;
-               if (arglen != sizeof(*ctv))
+               if (arglen != sizeof(struct compat_timeval))
                        return -EINVAL;
-               ctv = arg;
-               return (ctv == NULL ||
-                       !access_rok(ctv, sizeof(*ctv)) ||
-                       __xn_get_user(tv->tv_sec, &ctv->tv_sec) ||
-                       __xn_get_user(tv->tv_usec, &ctv->tv_usec)) ? -EFAULT : 
0;
+               return sys32_get_timeval(tv, arg);
        }
 #endif
 
@@ -353,14 +331,9 @@ int rtipc_put_timeval(struct rtdm_fd *fd, void *arg,
 {
 #ifdef CONFIG_COMPAT
        if (rtdm_fd_is_compat(fd)) {
-               struct compat_timeval *ctv;
-               if (arglen != sizeof(*ctv))
+               if (arglen != sizeof(struct compat_timeval))
                        return -EINVAL;
-               ctv = arg;
-               return (ctv == NULL ||
-                       !access_wok(ctv, sizeof(*ctv)) ||
-                       __xn_put_user(tv->tv_sec, &ctv->tv_sec) ||
-                       __xn_put_user(tv->tv_usec, &ctv->tv_usec)) ? -EFAULT : 
0;
+               return sys32_put_timeval(arg, tv);
        }
 #endif
 


_______________________________________________
Xenomai-git mailing list
Xenomai-git@xenomai.org
http://www.xenomai.org/mailman/listinfo/xenomai-git

Reply via email to