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

Author: Philippe Gerum <r...@xenomai.org>
Date:   Fri Jun  7 10:31:46 2013 +0200

cobalt/nucleus: introduce dedicated ppd handlers

---

 include/asm-generic/syscall.h    |    2 -
 include/cobalt/nucleus/ppd.h     |   18 ++--
 include/cobalt/nucleus/shadow.h  |   14 ++-
 include/cobalt/nucleus/sys_ppd.h |    9 +-
 kernel/cobalt/cond.c             |    4 +-
 kernel/cobalt/cond.h             |    4 +-
 kernel/cobalt/internal.h         |   55 +++++------
 kernel/cobalt/mq.c               |   78 ++++++++--------
 kernel/cobalt/mq.h               |    2 +-
 kernel/cobalt/mutex.c            |    6 +-
 kernel/cobalt/mutex.h            |    4 +-
 kernel/cobalt/nucleus/shadow.c   |  194 +++++++++++++++++++-------------------
 kernel/cobalt/registry.c         |    2 +-
 kernel/cobalt/rtdm/core.c        |    2 +-
 kernel/cobalt/rtdm/internal.h    |    2 +-
 kernel/cobalt/rtdm/module.c      |    2 +-
 kernel/cobalt/rtdm/syscall.c     |   38 ++++----
 kernel/cobalt/sem.c              |   36 ++++----
 kernel/cobalt/sem.h              |    6 +-
 kernel/cobalt/syscall.c          |  107 ++++++++++-----------
 kernel/cobalt/timer.c            |    6 +-
 kernel/cobalt/timer.h            |    2 +-
 22 files changed, 289 insertions(+), 304 deletions(-)

diff --git a/include/asm-generic/syscall.h b/include/asm-generic/syscall.h
index ff53380..d3e23f0 100644
--- a/include/asm-generic/syscall.h
+++ b/include/asm-generic/syscall.h
@@ -82,8 +82,6 @@ struct xnsysinfo {
 struct task_struct;
 struct pt_regs;
 
-#define XENOMAI_MAX_SYSENT 255
-
 struct xnsysent {
 
        /*
diff --git a/include/cobalt/nucleus/ppd.h b/include/cobalt/nucleus/ppd.h
index 6680cb3..296dbfe 100644
--- a/include/cobalt/nucleus/ppd.h
+++ b/include/cobalt/nucleus/ppd.h
@@ -6,22 +6,20 @@
 
 struct mm_struct;
 
-typedef struct xnshadow_ppd_key {
+struct xnshadow_ppd_key {
        unsigned long muxid;
        struct mm_struct *mm;
-} xnshadow_ppd_key_t;
+};
 
-typedef struct xnshadow_ppd_t {
-       xnshadow_ppd_key_t key;
-       xnholder_t link;
-#define link2ppd(ln)   container_of(ln, xnshadow_ppd_t, link)
-} xnshadow_ppd_t;
+struct xnshadow_ppd {
+       struct xnshadow_ppd_key key;
+       struct xnholder link;
+};
 
 #define xnshadow_ppd_muxid(ppd) ((ppd)->key.muxid)
-
 #define xnshadow_ppd_mm(ppd)    ((ppd)->key.mm)
 
-/* Call with nklock locked irqs off. */
-xnshadow_ppd_t *xnshadow_ppd_get(unsigned int muxid);
+/* Called with nklock locked irqs off. */
+struct xnshadow_ppd *xnshadow_ppd_get(unsigned int muxid);
 
 #endif /* _XENO_NUCLEUS_PPD_H */
diff --git a/include/cobalt/nucleus/shadow.h b/include/cobalt/nucleus/shadow.h
index 52df983..917ba44 100644
--- a/include/cobalt/nucleus/shadow.h
+++ b/include/cobalt/nucleus/shadow.h
@@ -25,10 +25,6 @@
 
 #define XENOMAI_SKINS_NR  4
 
-/* Events sent to the interface callback */
-#define XNSHADOW_CLIENT_ATTACH  0
-#define XNSHADOW_CLIENT_DETACH  1
-
 struct xnthread;
 struct xnthread_user_window;
 struct xnmutex;
@@ -36,13 +32,19 @@ struct pt_regs;
 struct timespec;
 struct timeval;
 struct completion;
+struct xnshadow_ppd;
+
+struct xnskin_client_ops {
+       struct xnshadow_ppd *(*attach)(void);
+       void (*detach)(struct xnshadow_ppd *ppd);
+};
 
 struct xnskin_props {
        const char *name;
-       unsigned magic;
+       unsigned int magic;
        int nrcalls;
-       void *(*eventcb)(int, void *);
        struct xnsysent *systab;
+       struct xnskin_client_ops ops;
 };
 
 static inline struct xnthread *xnshadow_current(void)
diff --git a/include/cobalt/nucleus/sys_ppd.h b/include/cobalt/nucleus/sys_ppd.h
index a714169..e60fd6d 100644
--- a/include/cobalt/nucleus/sys_ppd.h
+++ b/include/cobalt/nucleus/sys_ppd.h
@@ -5,24 +5,23 @@
 #include <nucleus/heap.h>
 
 struct xnsys_ppd {
-       xnshadow_ppd_t ppd;
-       xnheap_t sem_heap;
+       struct xnshadow_ppd ppd;
+       struct xnheap sem_heap;
        unsigned long mayday_addr;
        xnarch_atomic_t refcnt;
        char *exe_path;
-#define ppd2sys(addr) container_of(addr, struct xnsys_ppd, ppd)
 };
 
 extern struct xnsys_ppd __xnsys_global_ppd;
 
 static inline struct xnsys_ppd *xnsys_ppd_get(int global)
 {
-       xnshadow_ppd_t *ppd;
+       struct xnshadow_ppd *ppd;
 
        if (global || (ppd = xnshadow_ppd_get(0)) == NULL)
                return &__xnsys_global_ppd;
 
-       return ppd2sys(ppd);
+       return container_of(ppd, struct xnsys_ppd, ppd);
 }
 
 #endif /* _XENO_NUCLEUS_SYS_PPD_H */
diff --git a/kernel/cobalt/cond.c b/kernel/cobalt/cond.c
index 538bf4f..695a726 100644
--- a/kernel/cobalt/cond.c
+++ b/kernel/cobalt/cond.c
@@ -52,7 +52,7 @@
 #include "cond.h"
 
 static inline void
-cond_destroy_internal(cobalt_cond_t *cond, cobalt_kqueues_t *q)
+cond_destroy_internal(cobalt_cond_t *cond, struct cobalt_kqueues *q)
 {
        spl_t s;
 
@@ -476,7 +476,7 @@ int cobalt_cond_wait_epilogue(struct __shadow_cond __user 
*u_cnd,
        return err;
 }
 
-void cobalt_condq_cleanup(cobalt_kqueues_t *q)
+void cobalt_condq_cleanup(struct cobalt_kqueues *q)
 {
        xnholder_t *holder;
        spl_t s;
diff --git a/kernel/cobalt/cond.h b/kernel/cobalt/cond.h
index b89f7b2..9118949 100644
--- a/kernel/cobalt/cond.h
+++ b/kernel/cobalt/cond.h
@@ -65,7 +65,7 @@ typedef struct cobalt_cond {
        unsigned long *pending_signals;
        pthread_condattr_t attr;
        struct cobalt_mutex *mutex;
-       cobalt_kqueues_t *owningq;
+       struct cobalt_kqueues *owningq;
 } cobalt_cond_t;
 
 extern const pthread_condattr_t cobalt_default_cond_attr;
@@ -126,7 +126,7 @@ int cobalt_cond_wait_prologue(struct __shadow_cond __user 
*u_cnd,
 int cobalt_cond_wait_epilogue(struct __shadow_cond __user *u_cnd,
                              struct __shadow_mutex __user *u_mx);
 
-void cobalt_condq_cleanup(cobalt_kqueues_t *q);
+void cobalt_condq_cleanup(struct cobalt_kqueues *q);
 
 void cobalt_cond_pkg_init(void);
 
diff --git a/kernel/cobalt/internal.h b/kernel/cobalt/internal.h
index bb006d4..5c7918a 100644
--- a/kernel/cobalt/internal.h
+++ b/kernel/cobalt/internal.h
@@ -68,58 +68,51 @@
 
 #define cobalt_mark_deleted(t) ((t)->magic = ~(t)->magic)
 
-typedef struct cobalt_kqueues {
-       xnqueue_t condq;
-       xnqueue_t intrq;
-       xnqueue_t mutexq;
-       xnqueue_t semq;
-       xnqueue_t threadq;
-       xnqueue_t timerq;
-       xnqueue_t monitorq;
-       xnqueue_t eventq;
-} cobalt_kqueues_t;
-
-typedef struct {
-       cobalt_kqueues_t kqueues;
+struct cobalt_kqueues {
+       struct xnqueue condq;
+       struct xnqueue intrq;
+       struct xnqueue mutexq;
+       struct xnqueue semq;
+       struct xnqueue threadq;
+       struct xnqueue timerq;
+       struct xnqueue monitorq;
+       struct xnqueue eventq;
+};
+
+struct cobalt_context {
+       struct cobalt_kqueues kqueues;
        cobalt_assocq_t uqds;
        cobalt_assocq_t usems;
-
-       xnshadow_ppd_t ppd;
-
-#define ppd2queues(addr)                                               \
-       ((cobalt_queues_t *) ((char *) (addr) - offsetof(cobalt_queues_t, ppd)))
-
-} cobalt_queues_t;
+       struct xnshadow_ppd ppd;
+};
 
 extern int cobalt_muxid;
 
-extern cobalt_kqueues_t cobalt_global_kqueues;
+extern struct cobalt_kqueues cobalt_global_kqueues;
 
-static inline cobalt_queues_t *cobalt_queues(void)
+static inline struct cobalt_context *cobalt_process_context(void)
 {
-       xnshadow_ppd_t *ppd;
+       struct xnshadow_ppd *ppd;
        spl_t s;
 
        xnlock_get_irqsave(&nklock, s);
-
        ppd = xnshadow_ppd_get(cobalt_muxid);
-
        xnlock_put_irqrestore(&nklock, s);
 
-       if (!ppd)
+       if (ppd == NULL)
                return NULL;
 
-       return ppd2queues(ppd);
+       return container_of(ppd, struct cobalt_context, ppd);
 }
 
-static inline cobalt_kqueues_t *cobalt_kqueues(int pshared)
+static inline struct cobalt_kqueues *cobalt_kqueues(int pshared)
 {
-       xnshadow_ppd_t *ppd;
+       struct xnshadow_ppd *ppd;
 
-       if (pshared || !(ppd = xnshadow_ppd_get(cobalt_muxid)))
+       if (pshared || (ppd = xnshadow_ppd_get(cobalt_muxid)) == NULL)
                return &cobalt_global_kqueues;
 
-       return &ppd2queues(ppd)->kqueues;
+       return &container_of(ppd, struct cobalt_context, ppd)->kqueues;
 }
 
 static inline void ns2ts(struct timespec *ts, xnticks_t nsecs)
diff --git a/kernel/cobalt/mq.c b/kernel/cobalt/mq.c
index 96f7fa9..d6269a3 100644
--- a/kernel/cobalt/mq.c
+++ b/kernel/cobalt/mq.c
@@ -961,16 +961,16 @@ static inline int mq_notify(mqd_t fd, const struct 
sigevent *evp)
 
 int cobalt_mq_notify(mqd_t fd, const struct sigevent *__user evp)
 {
+       struct cobalt_context *cc;
        cobalt_assoc_t *assoc;
        struct sigevent sev;
-       cobalt_queues_t *q;
        cobalt_ufd_t *ufd;
 
-       q = cobalt_queues();
-       if (q == NULL)
+       cc = cobalt_process_context();
+       if (cc == NULL)
                return -EPERM;
 
-       assoc = cobalt_assoc_lookup(&q->uqds, fd);
+       assoc = cobalt_assoc_lookup(&cc->uqds, fd);
        if (assoc == NULL)
                return -EBADF;
 
@@ -1048,9 +1048,9 @@ static void uqd_cleanup(cobalt_assoc_t *assoc)
        xnfree(ufd);
 }
 
-void cobalt_mq_uqds_cleanup(cobalt_queues_t *q)
+void cobalt_mq_uqds_cleanup(struct cobalt_context *cc)
 {
-       cobalt_assocq_destroy(&q->uqds, &uqd_cleanup);
+       cobalt_assocq_destroy(&cc->uqds, &uqd_cleanup);
 }
 
 /* mq_open(name, oflags, mode, attr, ufd) */
@@ -1059,14 +1059,14 @@ int cobalt_mq_open(const char __user *u_name, int 
oflags,
 {
        struct mq_attr locattr, *attr;
        char name[COBALT_MAXNAME];
+       struct cobalt_context *cc;
        cobalt_ufd_t *assoc;
-       cobalt_queues_t *q;
        unsigned len;
        mqd_t kqd;
        int err;
 
-       q = cobalt_queues();
-       if (q == NULL)
+       cc = cobalt_process_context();
+       if (cc == NULL)
                return -EPERM;
 
        len = __xn_safe_strncpy_from_user(name, u_name, sizeof(name));
@@ -1075,6 +1075,7 @@ int cobalt_mq_open(const char __user *u_name, int oflags,
 
        if (len >= sizeof(name))
                return -ENAMETOOLONG;
+
        if (len == 0)
                return -EINVAL;
 
@@ -1098,7 +1099,7 @@ int cobalt_mq_open(const char __user *u_name, int oflags,
 
        assoc->kfd = kqd;
 
-       err = cobalt_assoc_insert(&q->uqds, &assoc->assoc, (u_long)uqd);
+       err = cobalt_assoc_insert(&cc->uqds, &assoc->assoc, (u_long)uqd);
        if (err) {
                xnfree(assoc);
                mq_close(kqd);
@@ -1109,15 +1110,15 @@ int cobalt_mq_open(const char __user *u_name, int 
oflags,
 
 int cobalt_mq_close(mqd_t uqd)
 {
+       struct cobalt_context *cc;
        cobalt_assoc_t *assoc;
-       cobalt_queues_t *q;
        int err;
 
-       q = cobalt_queues();
-       if (q == NULL)
+       cc = cobalt_process_context();
+       if (cc == NULL)
                return -EPERM;
 
-       assoc = cobalt_assoc_remove(&q->uqds, (u_long)uqd);
+       assoc = cobalt_assoc_remove(&cc->uqds, (u_long)uqd);
        if (assoc == NULL)
                return -EBADF;
 
@@ -1143,17 +1144,17 @@ int cobalt_mq_unlink(const char __user *u_name)
 
 int cobalt_mq_getattr(mqd_t uqd, struct mq_attr __user *u_attr)
 {
+       struct cobalt_context *cc;
        cobalt_assoc_t *assoc;
        struct mq_attr attr;
-       cobalt_queues_t *q;
        cobalt_ufd_t *ufd;
        int err;
 
-       q = cobalt_queues();
-       if (q == NULL)
+       cc = cobalt_process_context();
+       if (cc == NULL)
                return -EPERM;
 
-       assoc = cobalt_assoc_lookup(&q->uqds, (u_long)uqd);
+       assoc = cobalt_assoc_lookup(&cc->uqds, (u_long)uqd);
        if (assoc == NULL)
                return -EBADF;
 
@@ -1170,16 +1171,16 @@ int cobalt_mq_setattr(mqd_t uqd, const struct mq_attr 
__user *u_attr,
                      struct mq_attr __user *u_oattr)
 {
        struct mq_attr attr, oattr;
+       struct cobalt_context *cc;
        cobalt_assoc_t *assoc;
-       cobalt_queues_t *q;
        cobalt_ufd_t *ufd;
        int err;
 
-       q = cobalt_queues();
-       if (q == NULL)
+       cc = cobalt_process_context();
+       if (cc == NULL)
                return -EPERM;
 
-       assoc = cobalt_assoc_lookup(&q->uqds, (u_long)uqd);
+       assoc = cobalt_assoc_lookup(&cc->uqds, (u_long)uqd);
        if (assoc == NULL)
                return -EBADF;
 
@@ -1201,17 +1202,17 @@ int cobalt_mq_setattr(mqd_t uqd, const struct mq_attr 
__user *u_attr,
 int cobalt_mq_send(mqd_t uqd,
                   const void __user *u_buf, size_t len, unsigned int prio)
 {
+       struct cobalt_context *cc;
        cobalt_assoc_t *assoc;
-       cobalt_queues_t *q;
        cobalt_msg_t *msg;
        cobalt_ufd_t *ufd;
        cobalt_mq_t *mq;
 
-       q = cobalt_queues();
-       if (q == NULL)
+       cc = cobalt_process_context();
+       if (cc == NULL)
                return -EPERM;
 
-       assoc = cobalt_assoc_lookup(&q->uqds, (u_long)uqd);
+       assoc = cobalt_assoc_lookup(&cc->uqds, (u_long)uqd);
        if (assoc == NULL)
                return -EBADF;
 
@@ -1238,17 +1239,17 @@ int cobalt_mq_timedsend(mqd_t uqd, const void __user 
*u_buf, size_t len,
                        unsigned int prio, const struct timespec __user *u_ts)
 {
        struct timespec timeout, *timeoutp;
+       struct cobalt_context *cc;
        cobalt_assoc_t *assoc;
-       cobalt_queues_t *q;
        cobalt_msg_t *msg;
        cobalt_ufd_t *ufd;
        cobalt_mq_t *mq;
 
-       q = cobalt_queues();
-       if (q == NULL)
+       cc = cobalt_process_context();
+       if (cc == NULL)
                return -EPERM;
 
-       assoc = cobalt_assoc_lookup(&q->uqds, (u_long)uqd);
+       assoc = cobalt_assoc_lookup(&cc->uqds, (u_long)uqd);
        if (assoc == NULL)
                return -EBADF;
 
@@ -1281,8 +1282,8 @@ int cobalt_mq_timedsend(mqd_t uqd, const void __user 
*u_buf, size_t len,
 int cobalt_mq_receive(mqd_t uqd, void __user *u_buf,
                      ssize_t __user *u_len, unsigned int __user *u_prio)
 {
+       struct cobalt_context *cc;
        cobalt_assoc_t *assoc;
-       cobalt_queues_t *q;
        cobalt_ufd_t *ufd;
        cobalt_msg_t *msg;
        cobalt_mq_t *mq;
@@ -1290,11 +1291,11 @@ int cobalt_mq_receive(mqd_t uqd, void __user *u_buf,
        ssize_t len;
        int err;
 
-       q = cobalt_queues();
-       if (q == NULL)
+       cc = cobalt_process_context();
+       if (cc == NULL)
                return -EPERM;
 
-       assoc = cobalt_assoc_lookup(&q->uqds, (u_long)uqd);
+       assoc = cobalt_assoc_lookup(&cc->uqds, (u_long)uqd);
        if (assoc == NULL)
                return -EBADF;
 
@@ -1317,6 +1318,7 @@ int cobalt_mq_receive(mqd_t uqd, void __user *u_buf,
                cobalt_mq_finish_rcv(ufd->kfd, mq, msg);
                return -EFAULT;
        }
+
        len = msg->len;
        prio = cobalt_msg_get_prio(msg);
 
@@ -1340,8 +1342,8 @@ int cobalt_mq_timedreceive(mqd_t uqd, void __user *u_buf,
                           const struct timespec __user *u_ts)
 {
        struct timespec timeout, *timeoutp;
+       struct cobalt_context *cc;
        cobalt_assoc_t *assoc;
-       cobalt_queues_t *q;
        unsigned int prio;
        cobalt_ufd_t *ufd;
        cobalt_msg_t *msg;
@@ -1349,11 +1351,11 @@ int cobalt_mq_timedreceive(mqd_t uqd, void __user 
*u_buf,
        ssize_t len;
        int err;
 
-       q = cobalt_queues();
-       if (q == NULL)
+       cc = cobalt_process_context();
+       if (cc == NULL)
                return -EPERM;
 
-       assoc = cobalt_assoc_lookup(&q->uqds, (u_long)uqd);
+       assoc = cobalt_assoc_lookup(&cc->uqds, (u_long)uqd);
        if (assoc == NULL)
                return -EBADF;
 
diff --git a/kernel/cobalt/mq.h b/kernel/cobalt/mq.h
index 269b8f0..43ed958 100644
--- a/kernel/cobalt/mq.h
+++ b/kernel/cobalt/mq.h
@@ -38,7 +38,7 @@ int cobalt_mq_timedreceive(mqd_t uqd, void __user *u_buf,
 
 int cobalt_mq_notify(mqd_t fd, const struct sigevent *__user evp);
 
-void cobalt_mq_uqds_cleanup(cobalt_queues_t *q);
+void cobalt_mq_uqds_cleanup(struct cobalt_context *cc);
 
 int cobalt_mq_pkg_init(void);
 
diff --git a/kernel/cobalt/mutex.c b/kernel/cobalt/mutex.c
index 59d67e5..7d1379d 100644
--- a/kernel/cobalt/mutex.c
+++ b/kernel/cobalt/mutex.c
@@ -58,7 +58,7 @@ static int cobalt_mutex_init_inner(struct __shadow_mutex 
*shadow,
 {
        xnflags_t synch_flags = XNSYNCH_PRIO | XNSYNCH_OWNER;
        struct xnsys_ppd *sys_ppd;
-       cobalt_kqueues_t *kq;
+       struct cobalt_kqueues *kq;
        spl_t s;
 
        if (!attr)
@@ -97,7 +97,7 @@ static int cobalt_mutex_init_inner(struct __shadow_mutex 
*shadow,
 }
 
 static void cobalt_mutex_destroy_inner(cobalt_mutex_t *mutex,
-                                      cobalt_kqueues_t *q)
+                                      struct cobalt_kqueues *q)
 {
        spl_t s;
 
@@ -387,7 +387,7 @@ int cobalt_mutex_unlock(struct __shadow_mutex __user *u_mx)
        return err;
 }
 
-void cobalt_mutexq_cleanup(cobalt_kqueues_t *q)
+void cobalt_mutexq_cleanup(struct cobalt_kqueues *q)
 {
        xnholder_t *holder;
        spl_t s;
diff --git a/kernel/cobalt/mutex.h b/kernel/cobalt/mutex.h
index d01d4c5..1982b2e 100644
--- a/kernel/cobalt/mutex.h
+++ b/kernel/cobalt/mutex.h
@@ -64,7 +64,7 @@ typedef struct cobalt_mutex {
        xnqueue_t conds;
 
        pthread_mutexattr_t attr;
-       cobalt_kqueues_t *owningq;
+       struct cobalt_kqueues *owningq;
 } cobalt_mutex_t;
 
 extern pthread_mutexattr_t cobalt_default_mutex_attr;
@@ -162,7 +162,7 @@ int cobalt_mutex_timedlock(struct __shadow_mutex __user 
*u_mx,
 
 int cobalt_mutex_unlock(struct __shadow_mutex __user *u_mx);
 
-void cobalt_mutexq_cleanup(cobalt_kqueues_t *q);
+void cobalt_mutexq_cleanup(struct cobalt_kqueues *q);
 
 void cobalt_mutex_pkg_init(void);
 
diff --git a/kernel/cobalt/nucleus/shadow.c b/kernel/cobalt/nucleus/shadow.c
index 42e3338..241291a 100644
--- a/kernel/cobalt/nucleus/shadow.c
+++ b/kernel/cobalt/nucleus/shadow.c
@@ -96,12 +96,12 @@ union xnshadow_ppd_hkey {
  * the same bucket, so that they can all be destroyed with only one
  * hash lookup by ppd_remove_mm.
  */
-static unsigned int ppd_lookup_inner(xnqueue_t **pq, xnshadow_ppd_t ** pholder,
-                                    xnshadow_ppd_key_t * pkey)
+static unsigned int ppd_lookup_inner(xnqueue_t **pq, struct xnshadow_ppd ** 
pholder,
+                                    struct xnshadow_ppd_key * pkey)
 {
        union xnshadow_ppd_hkey key = { .mm = pkey->mm };
        unsigned bucket = jhash2(&key.val, sizeof(key) / sizeof(uint32_t), 0);
-       xnshadow_ppd_t *ppd;
+       struct xnshadow_ppd *ppd;
        xnholder_t *holder;
 
        *pq = &ppd_hash[bucket % PPD_HASH_SIZE];
@@ -113,7 +113,7 @@ static unsigned int ppd_lookup_inner(xnqueue_t **pq, 
xnshadow_ppd_t ** pholder,
        }
 
        do {
-               ppd = link2ppd(holder);
+               ppd = container_of(holder, struct xnshadow_ppd, link);
                holder = nextq(*pq, holder);
        } while (holder &&
                 (ppd->key.mm < pkey->mm ||
@@ -128,16 +128,18 @@ static unsigned int ppd_lookup_inner(xnqueue_t **pq, 
xnshadow_ppd_t ** pholder,
        /* not found, return successor for insertion. */
        if (ppd->key.mm < pkey->mm ||
            (ppd->key.mm == pkey->mm && ppd->key.muxid > pkey->muxid))
-               *pholder = holder ? link2ppd(holder) : NULL;
+               *pholder = holder ?
+                       container_of(holder, struct xnshadow_ppd, link) :
+                       NULL;
        else
                *pholder = ppd;
 
        return 0;
 }
 
-static int ppd_insert(xnshadow_ppd_t *holder)
+static int ppd_insert(struct xnshadow_ppd *holder)
 {
-       xnshadow_ppd_t *next;
+       struct xnshadow_ppd *next;
        unsigned int found;
        xnqueue_t *q;
        spl_t s;
@@ -163,10 +165,10 @@ static int ppd_insert(xnshadow_ppd_t *holder)
 }
 
 /* will be called by skin code, nklock locked irqs off. */
-static xnshadow_ppd_t *ppd_lookup(unsigned muxid, struct mm_struct *mm)
+static struct xnshadow_ppd *ppd_lookup(unsigned muxid, struct mm_struct *mm)
 {
-       xnshadow_ppd_t *holder;
-       xnshadow_ppd_key_t key;
+       struct xnshadow_ppd_key key;
+       struct xnshadow_ppd *holder;
        unsigned int found;
        xnqueue_t *q;
 
@@ -180,7 +182,7 @@ static xnshadow_ppd_t *ppd_lookup(unsigned muxid, struct 
mm_struct *mm)
        return holder;
 }
 
-static void ppd_remove(xnshadow_ppd_t * holder)
+static void ppd_remove(struct xnshadow_ppd * holder)
 {
        unsigned int found;
        xnqueue_t *q;
@@ -196,10 +198,10 @@ static void ppd_remove(xnshadow_ppd_t * holder)
 }
 
 static inline void ppd_remove_mm(struct mm_struct *mm,
-                                void (*destructor) (xnshadow_ppd_t *))
+                                void (*destructor) (struct xnshadow_ppd *))
 {
-       xnshadow_ppd_key_t key;
-       xnshadow_ppd_t *ppd;
+       struct xnshadow_ppd_key key;
+       struct xnshadow_ppd *ppd;
        xnholder_t *holder;
        xnqueue_t *q;
        spl_t s;
@@ -219,17 +221,19 @@ static inline void ppd_remove_mm(struct mm_struct *mm,
                 * while we are running xnpod_remove_mm.
                 */
                destructor(ppd);
-               ppd = holder ? link2ppd(holder) : NULL;
+               ppd = holder ?
+                       container_of(holder, struct xnshadow_ppd, link) :
+                       NULL;
                xnlock_get_irqsave(&nklock, s);
        }
 
        xnlock_put_irqrestore(&nklock, s);
 }
 
-static void detach_ppd(xnshadow_ppd_t * ppd)
+static void detach_ppd(struct xnshadow_ppd *ppd)
 {
        unsigned int muxid = xnshadow_ppd_muxid(ppd);
-       skins[muxid].props->eventcb(XNSHADOW_CLIENT_DETACH, ppd);
+       skins[muxid].props->ops.detach(ppd);
 }
 
 struct xnvdso *nkvdso;
@@ -1220,7 +1224,7 @@ static inline int raise_cap(int cap)
 static int xnshadow_sys_bind(unsigned int magic,
                             struct xnsysinfo __user *u_breq)
 {
-       xnshadow_ppd_t *ppd = NULL, *sys_ppd = NULL;
+       struct xnshadow_ppd *ppd = NULL, *sys_ppd = NULL;
        unsigned long featreq, featmis;
        struct xnskin_slot *sslt;
        int muxid, abirev, ret;
@@ -1298,7 +1302,7 @@ static int xnshadow_sys_bind(unsigned int magic,
        if (sys_ppd)
                goto muxid_eventcb;
 
-       sys_ppd = skins[0].props->eventcb(XNSHADOW_CLIENT_ATTACH, current);
+       sys_ppd = skins[0].props->ops.attach();
        if (IS_ERR(sys_ppd)) {
                ret = PTR_ERR(sys_ppd);
                goto fail;
@@ -1312,15 +1316,12 @@ static int xnshadow_sys_bind(unsigned int magic,
        if (ppd_insert(sys_ppd) == -EBUSY) {
                /* In case of concurrent binding (which can not happen with
                   Xenomai libraries), detach right away the second ppd. */
-               skins[0].props->eventcb(XNSHADOW_CLIENT_DETACH, sys_ppd);
+               skins[0].props->ops.detach(sys_ppd);
                sys_ppd = NULL;
        }
 
 muxid_eventcb:
 
-       if (sslt->props->eventcb == NULL)
-               goto eventcb_done;
-
        xnlock_get_irqsave(&nklock, s);
        ppd = ppd_lookup(muxid, current->mm);
        xnlock_put_irqrestore(&nklock, s);
@@ -1329,7 +1330,7 @@ muxid_eventcb:
        if (ppd)
                goto eventcb_done;
 
-       ppd = sslt->props->eventcb(XNSHADOW_CLIENT_ATTACH, current);
+       ppd = sslt->props->ops.attach();
        if (IS_ERR(ppd)) {
                ret = PTR_ERR(ppd);
                goto fail_destroy_sys_ppd;
@@ -1347,7 +1348,7 @@ muxid_eventcb:
                 * with Xenomai libraries), detach right away the
                 * second ppd.
                 */
-               sslt->props->eventcb(XNSHADOW_CLIENT_DETACH, ppd);
+               sslt->props->ops.detach(ppd);
                ppd = NULL;
        }
 
@@ -1359,9 +1360,9 @@ eventcb_done:
                 * at some point if you want me to be of some help
                 * here...
                 */
-               if (sslt->props->eventcb && ppd) {
+               if (ppd) {
                        ppd_remove(ppd);
-                       sslt->props->eventcb(XNSHADOW_CLIENT_DETACH, ppd);
+                       sslt->props->ops.detach(ppd);
                }
 
                ret = -ENOSYS;
@@ -1369,7 +1370,7 @@ eventcb_done:
        fail_destroy_sys_ppd:
                if (sys_ppd) {
                        ppd_remove(sys_ppd);
-                       skins[0].props->eventcb(XNSHADOW_CLIENT_DETACH, 
sys_ppd);
+                       skins[0].props->ops.detach(sys_ppd);
                }
              fail:
                return ret;
@@ -1574,60 +1575,58 @@ out:
        return pathname;
 }
 
-static void *xnshadow_sys_event(int event, void *data)
+static struct xnshadow_ppd *xnshadow_sys_attach(void)
 {
        struct xnsys_ppd *p;
        char *exe_path;
        int ret;
 
-       switch (event) {
-       case XNSHADOW_CLIENT_ATTACH:
-               p = kmalloc(sizeof(*p), GFP_KERNEL);
-               if (p == NULL)
-                       return ERR_PTR(-ENOMEM);
+       p = kmalloc(sizeof(*p), GFP_KERNEL);
+       if (p == NULL)
+               return ERR_PTR(-ENOMEM);
 
-               ret = xnheap_init_mapped(&p->sem_heap,
-                                        CONFIG_XENO_OPT_SEM_HEAPSZ * 1024,
-                                        XNARCH_SHARED_HEAP_FLAGS);
-               if (ret) {
-                       kfree(p);
-                       return ERR_PTR(ret);
-               }
+       ret = xnheap_init_mapped(&p->sem_heap,
+                                CONFIG_XENO_OPT_SEM_HEAPSZ * 1024,
+                                XNARCH_SHARED_HEAP_FLAGS);
+       if (ret) {
+               kfree(p);
+               return ERR_PTR(ret);
+       }
 
-               xnheap_set_label(&p->sem_heap,
-                                "private sem heap [%d]", current->pid);
+       xnheap_set_label(&p->sem_heap,
+                        "private sem heap [%d]", current->pid);
 
-               p->mayday_addr = map_mayday_page(current);
-               if (p->mayday_addr == 0) {
-                       printk(KERN_WARNING
-                              "Xenomai: %s[%d] cannot map MAYDAY page\n",
-                              current->comm, current->pid);
-                       kfree(p);
-                       return ERR_PTR(-ENOMEM);
-               }
+       p->mayday_addr = map_mayday_page(current);
+       if (p->mayday_addr == 0) {
+               printk(KERN_WARNING
+                      "Xenomai: %s[%d] cannot map MAYDAY page\n",
+                      current->comm, current->pid);
+               kfree(p);
+               return ERR_PTR(-ENOMEM);
+       }
 
-               exe_path = get_exe_path(current);
-               if (IS_ERR(exe_path)) {
-                       printk(KERN_WARNING
-                              "Xenomai: %s[%d] can't find exe path\n",
-                              current->comm, current->pid);
-                       exe_path = NULL; /* Not lethal, but weird. */
-               }
-               p->exe_path = exe_path;
-               xnarch_atomic_set(&p->refcnt, 1);
+       exe_path = get_exe_path(current);
+       if (IS_ERR(exe_path)) {
+               printk(KERN_WARNING
+                      "Xenomai: %s[%d] can't find exe path\n",
+                      current->comm, current->pid);
+               exe_path = NULL; /* Not lethal, but weird. */
+       }
+       p->exe_path = exe_path;
+       xnarch_atomic_set(&p->refcnt, 1);
 
-               return &p->ppd;
+       return &p->ppd;
+}
 
-       case XNSHADOW_CLIENT_DETACH:
-               p = ppd2sys(data);
-               xnheap_destroy_mapped(&p->sem_heap, post_ppd_release, NULL);
-               if (p->exe_path)
-                       kfree(p->exe_path);
+static void xnshadow_sys_detach(struct xnshadow_ppd *ppd)
+{
+       struct xnsys_ppd *p;
 
-               return NULL;
-       }
+       p = container_of(ppd, struct xnsys_ppd, ppd);
+       xnheap_destroy_mapped(&p->sem_heap, post_ppd_release, NULL);
 
-       return ERR_PTR(-EINVAL);
+       if (p->exe_path)
+               kfree(p->exe_path);
 }
 
 static struct xnskin_props __props = {
@@ -1635,7 +1634,10 @@ static struct xnskin_props __props = {
        .magic = 0x434F5245,
        .nrcalls = sizeof(__systab) / sizeof(__systab[0]),
        .systab = __systab,
-       .eventcb = xnshadow_sys_event,
+       .ops = {
+               .attach = xnshadow_sys_attach,
+               .detach = xnshadow_sys_detach,
+       },
 };
 
 void xnshadow_send_sig(xnthread_t *thread, int sig, int arg)
@@ -1654,41 +1656,35 @@ void xnshadow_send_sig(xnthread_t *thread, int sig, int 
arg)
 }
 EXPORT_SYMBOL_GPL(xnshadow_send_sig);
 
-/*
- * xnshadow_register_interface() -- Register a new skin/interface.
- * NOTE: an interface can be registered without its pod being
- * necessarily active. In such a case, a lazy initialization scheme
- * can be implemented through the event callback fired upon the first
- * client binding.
+/**
+ * @fn int xnshadow_register_interface(struct xnskin_props *props)
+ * @internal
+ * @brief Register a new real-time interface.
+ *
+ * - ops->attach() is called when a user-space process binds to the
+ *   interface, on behalf of one of its threads. The attach() handler
+ *   may return:
  *
- * The event callback will be called with its first argument set to:
- * - XNSHADOW_CLIENT_ATTACH, when a user-space process binds the interface, the
- *   second argument being the task_struct pointer of the calling thread, the
- *   callback may then return:
- *   . a pointer to an xnshadow_ppd_t structure, meaning that this structure
- *   will be attached to the calling process for this interface;
- *   . a NULL pointer, meaning that no per-process structure should be attached
- *   to this process for this interface;
- *   . ERR_PTR(negative value) indicating an error, the binding process will
- *   then abort;
- * - XNSHADOW_DETACH, when a user-space process terminates, if a non-NULL
- *   per-process structure is attached to the dying process, the second 
argument
- *   being the pointer to the per-process data attached to the dying process.
+ *   . a pointer to a xnshadow_ppd structure, representing the context
+ *   of the calling process for this interface;
+ *
+ *   . a NULL pointer, meaning that no per-process structure should be
+ *   attached to this process for this interface;
+ *
+ *   . ERR_PTR(negative value) indicating an error, the binding
+ *   process will then abort.
+ *
+ * - ops->detach() is called on behalf of an exiting user-space
+ *   process which has previously attached to the interface. This
+ *   handler is passed a pointer to the per-process data received
+ *   earlier from the ops->attach() handler.
  */
-
 int xnshadow_register_interface(struct xnskin_props *props)
 {
        struct xnskin_slot *sslt;
        int muxid;
        spl_t s;
 
-       /*
-        * We can only handle up to MAX_SYSENT syscalls per skin,
-        * check for over- and underflow (MKL).
-        */
-       if (XENOMAI_MAX_SYSENT < props->nrcalls || 0 > props->nrcalls)
-               return -EINVAL;
-
        down(&registration_mutex);
 
        xnlock_get_irqsave(&nklock, s);
@@ -1760,7 +1756,7 @@ EXPORT_SYMBOL_GPL(xnshadow_unregister_interface);
  * process; @return NULL otherwise.
  *
  */
-xnshadow_ppd_t *xnshadow_ppd_get(unsigned int muxid)
+struct xnshadow_ppd *xnshadow_ppd_get(unsigned int muxid)
 {
        struct xnthread *curr = xnpod_current_thread();
 
diff --git a/kernel/cobalt/registry.c b/kernel/cobalt/registry.c
index 367e0e0..405ad8d 100644
--- a/kernel/cobalt/registry.c
+++ b/kernel/cobalt/registry.c
@@ -379,7 +379,7 @@ void cobalt_assocq_destroy(cobalt_assocq_t * q, void 
(*destroy) (cobalt_assoc_t
        xnlock_put_irqrestore(&cobalt_assoc_lock, s);
 }
 
-cobalt_kqueues_t cobalt_global_kqueues;
+struct cobalt_kqueues cobalt_global_kqueues;
 
 int cobalt_reg_pkg_init(unsigned buckets_count, unsigned maxfds)
 {
diff --git a/kernel/cobalt/rtdm/core.c b/kernel/cobalt/rtdm/core.c
index 5d04dfb..71ff5ec 100644
--- a/kernel/cobalt/rtdm/core.c
+++ b/kernel/cobalt/rtdm/core.c
@@ -103,7 +103,7 @@ static int create_instance(struct rtdm_device *device,
                           rtdm_user_info_t *user_info, int nrt_mem)
 {
        struct rtdm_dev_context *context;
-       xnshadow_ppd_t *ppd;
+       struct xnshadow_ppd *ppd;
        spl_t s;
        int fd;
 
diff --git a/kernel/cobalt/rtdm/internal.h b/kernel/cobalt/rtdm/internal.h
index 45c946c..e75beca 100644
--- a/kernel/cobalt/rtdm/internal.h
+++ b/kernel/cobalt/rtdm/internal.h
@@ -46,7 +46,7 @@ struct rtdm_process {
        pid_t pid;
 #endif /* CONFIG_XENO_OPT_VFILE */
 
-       xnshadow_ppd_t ppd;
+       struct xnshadow_ppd ppd;
 };
 
 DECLARE_EXTERN_XNLOCK(rt_fildes_lock);
diff --git a/kernel/cobalt/rtdm/module.c b/kernel/cobalt/rtdm/module.c
index 43c1210..b0c12f2 100644
--- a/kernel/cobalt/rtdm/module.c
+++ b/kernel/cobalt/rtdm/module.c
@@ -61,7 +61,7 @@ static int __init __rtdm_init(void)
 
        rtdm_initialised = 1;
 
-       printk(KERN_INFO "starting RTDM services\n");
+       printk(XENO_INFO "starting RTDM services\n");
 
        return 0;
 
diff --git a/kernel/cobalt/rtdm/syscall.c b/kernel/cobalt/rtdm/syscall.c
index 6b83a44..9324189 100644
--- a/kernel/cobalt/rtdm/syscall.c
+++ b/kernel/cobalt/rtdm/syscall.c
@@ -104,34 +104,29 @@ static int sys_rtdm_sendmsg(int fd, const struct msghdr 
__user *u_msg,
        return __rt_dev_sendmsg(p, fd, &krnl_msg, flags);
 }
 
-static void *rtdm_skin_callback(int event, void *data)
+static struct xnshadow_ppd *rtdm_process_attach(void)
 {
        struct rtdm_process *process;
 
-       switch (event) {
-       case XNSHADOW_CLIENT_ATTACH:
-               process = kmalloc(sizeof(*process), GFP_KERNEL);
-               if (process == NULL)
-                       return ERR_PTR(-ENOSPC);
+       process = kmalloc(sizeof(*process), GFP_KERNEL);
+       if (process == NULL)
+               return ERR_PTR(-ENOSPC);
 
 #ifdef CONFIG_XENO_OPT_VFILE
-               memcpy(process->name, current->comm, sizeof(process->name));
-               process->pid = current->pid;
+       memcpy(process->name, current->comm, sizeof(process->name));
+       process->pid = current->pid;
 #endif /* CONFIG_XENO_OPT_VFILE */
 
-               return &process->ppd;
-
-       case XNSHADOW_CLIENT_DETACH:
-               process = container_of((xnshadow_ppd_t *) data,
-                                      struct rtdm_process, ppd);
-
-               cleanup_owned_contexts(process);
+       return &process->ppd;
+}
 
-               kfree(process);
+static void rtdm_process_detach(struct xnshadow_ppd *ppd)
+{
+       struct rtdm_process *process;
 
-               break;
-       }
-       return NULL;
+       process = container_of(ppd, struct rtdm_process, ppd);
+       cleanup_owned_contexts(process);
+       kfree(process);
 }
 
 static struct xnsysent __systab[] = {
@@ -151,7 +146,10 @@ static struct xnskin_props __props = {
        .magic = RTDM_SKIN_MAGIC,
        .nrcalls = sizeof(__systab) / sizeof(__systab[0]),
        .systab = __systab,
-       .eventcb = &rtdm_skin_callback,
+       .ops = {
+               .attach = rtdm_process_attach,
+               .detach = rtdm_process_detach,
+       },
 };
 
 int __init rtdm_syscall_init(void)
diff --git a/kernel/cobalt/sem.c b/kernel/cobalt/sem.c
index ec4d983..01507c8 100644
--- a/kernel/cobalt/sem.c
+++ b/kernel/cobalt/sem.c
@@ -46,10 +46,10 @@ typedef struct cobalt_sem {
        xnholder_t link;        /* Link in semq */
        unsigned int value;
        int flags;
-       cobalt_kqueues_t *owningq;
+       struct cobalt_kqueues *owningq;
 } cobalt_sem_t;
 
-static inline cobalt_kqueues_t *sem_kqueue(struct cobalt_sem *sem)
+static inline struct cobalt_kqueues *sem_kqueue(struct cobalt_sem *sem)
 {
        int pshared = !!(sem->flags & SEM_PSHARED);
        return cobalt_kqueues(pshared);
@@ -75,7 +75,7 @@ typedef struct cobalt_uptr {
 
 #define link2uptr(laddr) container_of(laddr, cobalt_uptr_t, link)
 
-static int sem_destroy_inner(cobalt_sem_t *sem, cobalt_kqueues_t *q)
+static int sem_destroy_inner(cobalt_sem_t *sem, struct cobalt_kqueues *q)
 {
        int ret = 0;
        spl_t s;
@@ -652,7 +652,7 @@ static int sem_timedwait(cobalt_sem_t *sem, const struct 
timespec *abs_timeout)
        return err;
 }
 
-int sem_post_inner(cobalt_sem_t *sem, cobalt_kqueues_t *ownq, int bcast)
+int sem_post_inner(cobalt_sem_t *sem, struct cobalt_kqueues *ownq, int bcast)
 {
        if (sem->magic != COBALT_SEM_MAGIC)
                return -EINVAL;
@@ -860,18 +860,18 @@ int cobalt_sem_open(unsigned long __user *u_addr,
                    const char __user *u_name,
                    int oflags, mode_t mode, unsigned value)
 {
+       struct cobalt_context *cc;
        char name[COBALT_MAXNAME];
        struct __shadow_sem *sm;
        cobalt_assoc_t *assoc;
        unsigned long uaddr;
-       cobalt_queues_t *q;
        cobalt_usem_t *usm;
        long len;
        int err;
        spl_t s;
 
-       q = cobalt_queues();
-       if (q == NULL)
+       cc = cobalt_process_context();
+       if (cc == NULL)
                return -EPERM;
 
        if (__xn_safe_copy_from_user(&uaddr, u_addr, sizeof(uaddr)))
@@ -895,7 +895,7 @@ int cobalt_sem_open(unsigned long __user *u_addr,
 
        xnlock_get_irqsave(&cobalt_assoc_lock, s);
 
-       assoc = cobalt_assoc_lookup(&q->usems, (u_long)sm->sem);
+       assoc = cobalt_assoc_lookup(&cc->usems, (u_long)sm->sem);
        if (assoc) {
                usm = assoc2usem(assoc);
                ++usm->refcnt;
@@ -916,7 +916,7 @@ int cobalt_sem_open(unsigned long __user *u_addr,
 
        xnlock_get_irqsave(&cobalt_assoc_lock, s);
 
-       assoc = cobalt_assoc_lookup(&q->usems, (u_long)sm->sem);
+       assoc = cobalt_assoc_lookup(&cc->usems, (u_long)sm->sem);
        if (assoc) {
                assoc2usem(assoc)->refcnt++;
                xnlock_put_irqrestore(&nklock, s);
@@ -925,7 +925,7 @@ int cobalt_sem_open(unsigned long __user *u_addr,
                goto got_usm;
        }
 
-       cobalt_assoc_insert(&q->usems, &usm->assoc, (u_long)sm->sem);
+       cobalt_assoc_insert(&cc->usems, &usm->assoc, (u_long)sm->sem);
 
        xnlock_put_irqrestore(&cobalt_assoc_lock, s);
 
@@ -945,15 +945,15 @@ int cobalt_sem_open(unsigned long __user *u_addr,
 
 int cobalt_sem_close(unsigned long uaddr, int __user *u_closed)
 {
+       struct cobalt_context *cc;
        struct __shadow_sem sm;
        cobalt_assoc_t *assoc;
        int closed = 0, err;
        cobalt_usem_t *usm;
-       cobalt_queues_t *q;
        spl_t s;
 
-       q = cobalt_queues();
-       if (q == NULL)
+       cc = cobalt_process_context();
+       if (cc == NULL)
                return -EPERM;
 
        if (__xn_safe_copy_from_user(&sm, (void __user *)uaddr, sizeof(sm)))
@@ -961,7 +961,7 @@ int cobalt_sem_close(unsigned long uaddr, int __user 
*u_closed)
 
        xnlock_get_irqsave(&cobalt_assoc_lock, s);
 
-       assoc = cobalt_assoc_lookup(&q->usems, (u_long)sm.sem);
+       assoc = cobalt_assoc_lookup(&cc->usems, (u_long)sm.sem);
        if (assoc == NULL) {
                xnlock_put_irqrestore(&cobalt_assoc_lock, s);
                return -EINVAL;
@@ -972,7 +972,7 @@ int cobalt_sem_close(unsigned long uaddr, int __user 
*u_closed)
        err = sem_close(&sm);
 
        if (!err && (closed = (--usm->refcnt == 0)))
-               cobalt_assoc_remove(&q->usems, (u_long)sm.sem);
+               cobalt_assoc_remove(&cc->usems, (u_long)sm.sem);
 
        xnlock_put_irqrestore(&cobalt_assoc_lock, s);
 
@@ -1047,12 +1047,12 @@ static void usem_cleanup(cobalt_assoc_t *assoc)
        xnfree(usem);
 }
 
-void cobalt_sem_usems_cleanup(cobalt_queues_t *q)
+void cobalt_sem_usems_cleanup(struct cobalt_context *cc)
 {
-       cobalt_assocq_destroy(&q->usems, &usem_cleanup);
+       cobalt_assocq_destroy(&cc->usems, &usem_cleanup);
 }
 
-void cobalt_semq_cleanup(cobalt_kqueues_t *q)
+void cobalt_semq_cleanup(struct cobalt_kqueues *q)
 {
        xnholder_t *holder;
        spl_t s;
diff --git a/kernel/cobalt/sem.h b/kernel/cobalt/sem.h
index 7cff922..2c76800 100644
--- a/kernel/cobalt/sem.h
+++ b/kernel/cobalt/sem.h
@@ -33,14 +33,14 @@ typedef struct {
 #define assoc2usem(laddr) container_of(laddr, cobalt_usem_t, assoc)
 } cobalt_usem_t;
 
-void cobalt_sem_usems_cleanup(cobalt_queues_t *q);
+void cobalt_sem_usems_cleanup(struct cobalt_context *cc);
 
 struct cobalt_sem;
 
 int sem_getvalue(struct cobalt_sem *sem, int *value);
 
 int sem_post_inner(struct cobalt_sem *sem,
-                  cobalt_kqueues_t *ownq, int bcast);
+                  struct cobalt_kqueues *ownq, int bcast);
 
 int cobalt_sem_init(struct __shadow_sem __user *u_sem,
                    int pshared, unsigned value);
@@ -71,7 +71,7 @@ int cobalt_sem_init_np(struct __shadow_sem __user *u_sem,
 
 int cobalt_sem_broadcast_np(struct __shadow_sem __user *u_sem);
 
-void cobalt_semq_cleanup(cobalt_kqueues_t *q);
+void cobalt_semq_cleanup(struct cobalt_kqueues *q);
 
 void cobalt_sem_pkg_init(void);
 
diff --git a/kernel/cobalt/syscall.c b/kernel/cobalt/syscall.c
index 55c03a3..de9e3fc 100644
--- a/kernel/cobalt/syscall.c
+++ b/kernel/cobalt/syscall.c
@@ -41,24 +41,23 @@ int cobalt_muxid;
 
 static int fd_valid_p(int fd)
 {
-       cobalt_queues_t *q;
        const int rtdm_fd_start = __FD_SETSIZE - RTDM_FD_MAX;
+       struct rtdm_dev_context *ctx;
+       struct cobalt_context *cc;
 
        if (fd >= rtdm_fd_start) {
-               struct rtdm_dev_context *ctx;
                ctx = rtdm_context_get(fd - rtdm_fd_start);
-               if (ctx) {
-                       rtdm_context_unlock(ctx);
-                       return 1;
-               }
-               return 0;
+               if (ctx == NULL)
+                       return 0;
+               rtdm_context_unlock(ctx);
+               return 1;
        }
 
-       q = cobalt_queues();
-       if (q == NULL)
+       cc = cobalt_process_context();
+       if (cc == NULL)
                return 0;
 
-       return cobalt_assoc_lookup(&q->uqds, fd) != NULL;
+       return cobalt_assoc_lookup(&cc->uqds, fd) != NULL;
 }
 
 static int first_fd_valid_p(fd_set *fds[XNSELECT_MAX_TYPES], int nfds)
@@ -77,19 +76,19 @@ static int first_fd_valid_p(fd_set 
*fds[XNSELECT_MAX_TYPES], int nfds)
 
 static int select_bind_one(struct xnselector *selector, unsigned type, int fd)
 {
-       cobalt_assoc_t *assoc;
-       cobalt_queues_t *q;
        const int rtdm_fd_start = __FD_SETSIZE - RTDM_FD_MAX;
+       struct cobalt_context *cc;
+       cobalt_assoc_t *assoc;
 
        if (fd >= rtdm_fd_start)
                return rtdm_select_bind(fd - rtdm_fd_start,
                                        selector, type, fd);
 
-       q = cobalt_queues();
-       if (q == NULL)
+       cc = cobalt_process_context();
+       if (cc == NULL)
                return -EPERM;
 
-       assoc = cobalt_assoc_lookup(&q->uqds, fd);
+       assoc = cobalt_assoc_lookup(&cc->uqds, fd);
        if (assoc == NULL)
                return -EBADF;
 
@@ -310,46 +309,43 @@ static struct xnsysent __systab[] = {
        SKINCALL_DEF(sc_cobalt_sched_setconfig_np, cobalt_sched_setconfig_np, 
any),
 };
 
-static void *cobalt_eventcb(int event, void *data)
+static struct xnshadow_ppd *cobalt_process_attach(void)
 {
-       cobalt_queues_t *q;
-
-       switch (event) {
-       case XNSHADOW_CLIENT_ATTACH:
-               q = kmalloc(sizeof(*q), GFP_KERNEL);
-               if (q == NULL)
-                       return ERR_PTR(-ENOSPC);
-
-               initq(&q->kqueues.condq);
-               initq(&q->kqueues.mutexq);
-               initq(&q->kqueues.semq);
-               initq(&q->kqueues.threadq);
-               initq(&q->kqueues.timerq);
-               initq(&q->kqueues.monitorq);
-               initq(&q->kqueues.eventq);
-               cobalt_assocq_init(&q->uqds);
-               cobalt_assocq_init(&q->usems);
-
-               return &q->ppd;
-
-       case XNSHADOW_CLIENT_DETACH:
-               q = ppd2queues((xnshadow_ppd_t *) data);
-
-               cobalt_sem_usems_cleanup(q);
-               cobalt_mq_uqds_cleanup(q);
-               cobalt_monitorq_cleanup(&q->kqueues);
-               cobalt_timerq_cleanup(&q->kqueues);
-               cobalt_semq_cleanup(&q->kqueues);
-               cobalt_mutexq_cleanup(&q->kqueues);
-               cobalt_condq_cleanup(&q->kqueues);
-               cobalt_eventq_cleanup(&q->kqueues);
-
-               kfree(q);
-
-               return NULL;
-       }
+       struct cobalt_context *cc;
+
+       cc = kmalloc(sizeof(*cc), GFP_KERNEL);
+       if (cc == NULL)
+               return ERR_PTR(-ENOSPC);
+
+       initq(&cc->kqueues.condq);
+       initq(&cc->kqueues.mutexq);
+       initq(&cc->kqueues.semq);
+       initq(&cc->kqueues.threadq);
+       initq(&cc->kqueues.timerq);
+       initq(&cc->kqueues.monitorq);
+       initq(&cc->kqueues.eventq);
+       cobalt_assocq_init(&cc->uqds);
+       cobalt_assocq_init(&cc->usems);
+
+       return &cc->ppd;
+}
+
+static void cobalt_process_detach(struct xnshadow_ppd *ppd)
+{
+       struct cobalt_context *cc;
+
+       cc = container_of(ppd, struct cobalt_context, ppd);
+
+       cobalt_sem_usems_cleanup(cc);
+       cobalt_mq_uqds_cleanup(cc);
+       cobalt_monitorq_cleanup(&cc->kqueues);
+       cobalt_timerq_cleanup(&cc->kqueues);
+       cobalt_semq_cleanup(&cc->kqueues);
+       cobalt_mutexq_cleanup(&cc->kqueues);
+       cobalt_condq_cleanup(&cc->kqueues);
+       cobalt_eventq_cleanup(&cc->kqueues);
 
-       return ERR_PTR(-EINVAL);
+       kfree(cc);
 }
 
 static struct xnskin_props __props = {
@@ -357,7 +353,10 @@ static struct xnskin_props __props = {
        .magic = COBALT_SKIN_MAGIC,
        .nrcalls = sizeof(__systab) / sizeof(__systab[0]),
        .systab = __systab,
-       .eventcb = &cobalt_eventcb,
+       .ops = {
+               .attach = cobalt_process_attach,
+               .detach = cobalt_process_detach,
+       },
 };
 
 int cobalt_syscall_init(void)
diff --git a/kernel/cobalt/timer.c b/kernel/cobalt/timer.c
index 3631631..4453b36 100644
--- a/kernel/cobalt/timer.c
+++ b/kernel/cobalt/timer.c
@@ -46,7 +46,7 @@ struct cobalt_timer {
 
        clockid_t clockid;
        pthread_t owner;
-       cobalt_kqueues_t *owningq;
+       struct cobalt_kqueues *owningq;
 };
 
 static xnqueue_t timer_freeq;
@@ -191,7 +191,7 @@ static inline int timer_create(clockid_t clockid,
 }
 
 static inline int
-cobalt_timer_delete_inner(timer_t timerid, cobalt_kqueues_t *q, int force)
+cobalt_timer_delete_inner(timer_t timerid, struct cobalt_kqueues *q, int force)
 {
        struct cobalt_timer *timer;
        spl_t s;
@@ -585,7 +585,7 @@ void cobalt_timer_cleanup_thread(pthread_t zombie)
        }
 }
 
-void cobalt_timerq_cleanup(cobalt_kqueues_t *q)
+void cobalt_timerq_cleanup(struct cobalt_kqueues *q)
 {
        xnholder_t *holder;
        spl_t s;
diff --git a/kernel/cobalt/timer.h b/kernel/cobalt/timer.h
index 6aa5186..7bfc0fe 100644
--- a/kernel/cobalt/timer.h
+++ b/kernel/cobalt/timer.h
@@ -48,7 +48,7 @@ void cobalt_timer_init_thread(pthread_t new);
 
 void cobalt_timer_cleanup_thread(pthread_t zombie);
 
-void cobalt_timerq_cleanup(cobalt_kqueues_t *q);
+void cobalt_timerq_cleanup(struct cobalt_kqueues *q);
 
 int cobalt_timer_pkg_init(void);
 


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

Reply via email to