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

Author: Philippe Gerum <r...@xenomai.org>
Date:   Mon Jul  8 16:41:24 2013 +0200

cobalt/posix/thread: sanitize mapping from core TCB to cobalt/posix thread

Testing the personality to determine whether a thread originates from
cobalt/posix is wrong, since that information may change dynamically
as extra personalities stack over the base posix one.

In addition, we may assume that any userland thread with a valid
Xenomai shadow extension which switches to kernel mode, is originally
a cobalt/posix thread, spawned from lib/cobalt.

As a consequence of this, thread2pthread() is dropped in favor of the
explicit container_of() expression, and cobalt_current_thread() shall
be used to determine the current TCB, which has to originates from the
cobalt/posix base personality.

---

 kernel/cobalt/posix/thread.c |   18 +++++++++---------
 kernel/cobalt/posix/thread.h |   16 +++++-----------
 kernel/cobalt/posix/timer.c  |    2 +-
 3 files changed, 15 insertions(+), 21 deletions(-)

diff --git a/kernel/cobalt/posix/thread.c b/kernel/cobalt/posix/thread.c
index 27641c1..3f9c60f 100644
--- a/kernel/cobalt/posix/thread.c
+++ b/kernel/cobalt/posix/thread.c
@@ -182,14 +182,13 @@ static void thread_destroy(pthread_t thread)
 
 struct xnpersonality *cobalt_thread_unmap(struct xnthread *thread)
 {
-       pthread_t tid = thread2pthread(thread);
+       pthread_t tid;
 
-       if (tid) {
-               cobalt_mark_deleted(tid);
-               cobalt_timer_cleanup_thread(tid);
-               thread_destroy(tid);
-               cobalt_thread_unhash(&tid->hkey);
-       }
+       tid = container_of(thread, struct cobalt_thread, threadbase);
+       cobalt_mark_deleted(tid);
+       cobalt_timer_cleanup_thread(tid);
+       thread_destroy(tid);
+       cobalt_thread_unhash(&tid->hkey);
 
        /* We don't stack over any personality, no chaining. */
        return NULL;
@@ -1187,11 +1186,12 @@ int cobalt_sched_max_prio(int policy)
 
 int cobalt_sched_yield(void)
 {
-       pthread_t thread = thread2pthread(xnshadow_current());
        struct sched_param_ex param;
        int policy = SCHED_NORMAL;
+       pthread_t cur;
 
-       pthread_getschedparam_ex(thread, &policy, &param);
+       cur = cobalt_current_thread();
+       pthread_getschedparam_ex(cur, &policy, &param);
        xnpod_yield();
 
        return policy == SCHED_NORMAL;
diff --git a/kernel/cobalt/posix/thread.h b/kernel/cobalt/posix/thread.h
index 791f694..5f3eb91 100644
--- a/kernel/cobalt/posix/thread.h
+++ b/kernel/cobalt/posix/thread.h
@@ -101,16 +101,6 @@ struct cobalt_thread {
        unsigned int magic;
        struct xnthread threadbase;
 
-#define thread2pthread(taddr) \
-       ({                                                              \
-               struct xnthread *__t = (taddr);                         \
-               (__t                                                    \
-                ? ((__t->personality == &cobalt_personality)           \
-                   ? (container_of(__t, struct cobalt_thread, threadbase)) \
-                   : NULL)                                             \
-                : NULL);                                               \
-       })
-
        /** cobalt_threadq */
        struct list_head link;
        struct list_head *container;
@@ -131,7 +121,11 @@ struct cobalt_thread {
        struct cobalt_hkey hkey;
 };
 
-#define cobalt_current_thread() thread2pthread(xnpod_current_thread())
+static inline struct cobalt_thread *cobalt_current_thread(void)
+{
+       struct xnthread *curr = xnshadow_current();
+       return curr ? container_of(curr, struct cobalt_thread, threadbase) : 
NULL;
+}
 
 #define thread_name(thread) ((thread)->attr.name)
 
diff --git a/kernel/cobalt/posix/timer.c b/kernel/cobalt/posix/timer.c
index 29c4c4d..3e6c3b8 100644
--- a/kernel/cobalt/posix/timer.c
+++ b/kernel/cobalt/posix/timer.c
@@ -300,7 +300,7 @@ timer_settime(timer_t timerid, int flags,
        spl_t s;
        int err;
 
-       if (!cur) {
+       if (cur == NULL) {
                err = -EPERM;
                goto error;
        }


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

Reply via email to