Module: xenomai-2.6 Branch: master Commit: 435f87958222c885b3dd94c9c7b2ef9c01efda7b URL: http://git.xenomai.org/?p=xenomai-2.6.git;a=commit;h=435f87958222c885b3dd94c9c7b2ef9c01efda7b
Author: Philippe Gerum <r...@xenomai.org> Date: Mon Dec 9 12:11:20 2013 +0100 posix, vrtx: catch unexpected sync errors with thread trampoline If __real_sem_wait() fails synchronizing with the trampoline, we simply can't continue, as this usually reveals a general issue with regular IPCs on the platform. This also plugs a nasty bug causing the POSIX thread trampoline to execute random start code, as the argument structure living on its parent thread's stack could be trashed, once the latter has returned to the caller because of a synchronization failure. --- src/skins/posix/thread.c | 28 +++++++++++++++++++--------- src/skins/vrtx/task.c | 12 +++++++++++- 2 files changed, 30 insertions(+), 10 deletions(-) diff --git a/src/skins/posix/thread.c b/src/skins/posix/thread.c index 31055f8..b63e197 100644 --- a/src/skins/posix/thread.c +++ b/src/skins/posix/thread.c @@ -20,6 +20,7 @@ #include <stdlib.h> #include <string.h> #include <errno.h> +#include <error.h> #include <signal.h> #include <unistd.h> #include <pthread.h> @@ -264,17 +265,26 @@ int __wrap_pthread_create(pthread_t *tid, __real_sem_init(&iargs.sync, 0, 0); err = __real_pthread_create(<id, attr, - &__pthread_trampoline, &iargs); - - if (!err) - while (__real_sem_wait(&iargs.sync) && errno == EINTR) ; + __pthread_trampoline, &iargs); + if (err) + goto out; + + for (;;) { + err = __real_sem_wait(&iargs.sync); + if (err && errno == EINTR) + continue; + if (err == 0) { + err = iargs.ret; + if (err == 0) + *tid = ltid; + break; + } + /* We can't continue if we can't sync up. */ + error(1, errno, "__real_sem_wait"); + } +out: __real_sem_destroy(&iargs.sync); - err = err ?: iargs.ret; - - if (!err) - *tid = ltid; - return err; } diff --git a/src/skins/vrtx/task.c b/src/skins/vrtx/task.c index 310dedf..400a9f7 100644 --- a/src/skins/vrtx/task.c +++ b/src/skins/vrtx/task.c @@ -22,6 +22,7 @@ #include <malloc.h> #include <unistd.h> #include <stdlib.h> +#include <error.h> #include <pthread.h> #include <semaphore.h> #include <signal.h> @@ -169,7 +170,16 @@ int sc_tecreate(void (*entry) (void *), return -1; } - while (__real_sem_wait(&iargs.sync) && errno == EINTR) ; + for (;;) { + err = __real_sem_wait(&iargs.sync); + if (err && errno == EINTR) + continue; + if (err == 0) + break; + /* We can't continue if we can't sync up. */ + error(1, errno, "__real_sem_wait"); + } + __real_sem_destroy(&iargs.sync); return iargs.tid; _______________________________________________ Xenomai-git mailing list Xenomai-git@xenomai.org http://www.xenomai.org/mailman/listinfo/xenomai-git