[Xenomai-git] Gilles Chanteperdrix : posix: add a magic to internal structures.
Module: xenomai-head Branch: master Commit: afc0eac7e4989f4134b18a256b5c5e1ca1c56a39 URL: http://git.xenomai.org/?p=xenomai-head.git;a=commit;h=afc0eac7e4989f4134b18a256b5c5e1ca1c56a39 Author: Gilles Chanteperdrix Date: Sun Aug 29 16:17:35 2010 +0200 posix: add a magic to internal structures. These structures may still be referenced by a process' child if they were destroyed by the father after the fork, so, use a magic in order to be able to detect this case. --- ksrc/skins/posix/cond.c | 37 + ksrc/skins/posix/mutex.c | 30 ++- ksrc/skins/posix/mutex.h |4 ++- ksrc/skins/posix/sem.c | 57 ++--- src/skins/posix/mutex.c |6 ++-- 5 files changed, 79 insertions(+), 55 deletions(-) diff --git a/ksrc/skins/posix/cond.c b/ksrc/skins/posix/cond.c index f86e85e..769eb4b 100644 --- a/ksrc/skins/posix/cond.c +++ b/ksrc/skins/posix/cond.c @@ -51,6 +51,7 @@ #include typedef struct pse51_cond { + unsigned magic; xnsynch_t synchbase; xnholder_t link;/* Link in pse51_condq */ @@ -101,7 +102,7 @@ static void cond_destroy_internal(pse51_cond_t * cond, pse51_kqueues_t *q) * @see * http://www.opengroup.org/onlinepubs/95399/functions/pthread_cond_init.html";> * Specification. - * + * */ int pthread_cond_init(pthread_cond_t * cnd, const pthread_condattr_t * attr) { @@ -142,6 +143,7 @@ int pthread_cond_init(pthread_cond_t * cnd, const pthread_condattr_t * attr) shadow->magic = PSE51_COND_MAGIC; shadow->cond = cond; + cond->magic = PSE51_COND_MAGIC; xnsynch_init(&cond->synchbase, synch_flags, NULL); inith(&cond->link); cond->attr = *attr; @@ -179,7 +181,7 @@ int pthread_cond_init(pthread_cond_t * cnd, const pthread_condattr_t * attr) * @see * http://www.opengroup.org/onlinepubs/95399/functions/pthread_cond_destroy.html";> * Specification. - * + * */ int pthread_cond_destroy(pthread_cond_t * cnd) { @@ -189,12 +191,13 @@ int pthread_cond_destroy(pthread_cond_t * cnd) xnlock_get_irqsave(&nklock, s); - if (!pse51_obj_active(shadow, PSE51_COND_MAGIC, struct __shadow_cond)) { + cond = shadow->cond; + if (!pse51_obj_active(shadow, PSE51_COND_MAGIC, struct __shadow_cond) + || !pse51_obj_active(cond, PSE51_COND_MAGIC, struct pse51_cond)) { xnlock_put_irqrestore(&nklock, s); return EINVAL; } - cond = shadow->cond; if (cond->owningq != pse51_kqueues(cond->attr.pshared)) { xnlock_put_irqrestore(&nklock, s); return EPERM; @@ -206,6 +209,7 @@ int pthread_cond_destroy(pthread_cond_t * cnd) } pse51_mark_deleted(shadow); + pse51_mark_deleted(cond); xnlock_put_irqrestore(&nklock, s); @@ -224,10 +228,10 @@ static inline int mutex_save_count(xnthread_t *cur, { pse51_mutex_t *mutex; - if (!pse51_obj_active(shadow, PSE51_MUTEX_MAGIC, struct __shadow_mutex)) -return EINVAL; - mutex = shadow->mutex; + if (!pse51_obj_active(shadow, PSE51_MUTEX_MAGIC, struct __shadow_mutex) + || !pse51_obj_active(mutex, PSE51_MUTEX_MAGIC, struct pse51_mutex)) +return EINVAL; if (xnsynch_owner_check(&mutex->synchbase, cur) != 0) return EPERM; @@ -267,6 +271,7 @@ int pse51_cond_timedwait_prologue(xnthread_t *cur, /* If another thread waiting for cond does not use the same mutex */ if (!pse51_obj_active(shadow, PSE51_COND_MAGIC, struct __shadow_cond) + || !pse51_obj_active(cond, PSE51_COND_MAGIC, struct pse51_cond) || (cond->mutex && cond->mutex != mutex->mutex)) { err = EINVAL; goto unlock_and_return; @@ -403,7 +408,7 @@ int pse51_cond_timedwait_epilogue(xnthread_t *cur, * @see * http://www.opengroup.org/onlinepubs/95399/functions/pthread_cond_wait.html";> * Specification. - * + * */ int pthread_cond_wait(pthread_cond_t * cnd, pthread_mutex_t * mx) { @@ -470,7 +475,7 @@ int pthread_cond_wait(pthread_cond_t * cnd, pthread_mutex_t * mx) * @see * http://www.opengroup.org/onlinepubs/95399/functions/pthread_cond_timedwait.html";> * Specification. - * + * */ int pthread_cond_timedwait(pthread_cond_t * cnd, pthread_mutex_t * mx, const struct timespec *abstime) @@ -521,7 +526,7 @@ int pthread_cond_timedwait(pthread_cond_t * cnd, * @see * http://www.opengroup.org/onlinepubs/95399/functions/pthread_cond_signal.html.";> * Specification. - * + * */ int pthread_cond_signal(pthread_cond_t * cnd) { @@ -531,12 +536,13 @@ int pthread_cond_signal(pthread_cond_t * cnd) xnlock_get_irqsave(&nklock, s); - if (!pse51_obj_active(shadow, PSE51_COND_MAGIC, struct __shadow_cond)) { + cond = shadow->cond; + if (!pse51_obj_active(shadow,
[Xenomai-git] Gilles Chanteperdrix : posix: add a magic to internal structures.
Module: xenomai-head Branch: master Commit: e768b24bd0173acefce3505d3c408766ce6cfa68 URL: http://git.xenomai.org/?p=xenomai-head.git;a=commit;h=e768b24bd0173acefce3505d3c408766ce6cfa68 Author: Gilles Chanteperdrix Date: Sun Aug 29 16:17:35 2010 +0200 posix: add a magic to internal structures. These structures may still be referenced by a process' child if they were destroyed by the father after the fork, so, use a magic in order to be able to detect this case. --- ksrc/skins/posix/cond.c | 37 + ksrc/skins/posix/mutex.c | 30 ++- ksrc/skins/posix/mutex.h |4 ++- ksrc/skins/posix/sem.c | 57 ++--- src/skins/posix/mutex.c |6 ++-- 5 files changed, 79 insertions(+), 55 deletions(-) diff --git a/ksrc/skins/posix/cond.c b/ksrc/skins/posix/cond.c index f86e85e..769eb4b 100644 --- a/ksrc/skins/posix/cond.c +++ b/ksrc/skins/posix/cond.c @@ -51,6 +51,7 @@ #include typedef struct pse51_cond { + unsigned magic; xnsynch_t synchbase; xnholder_t link;/* Link in pse51_condq */ @@ -101,7 +102,7 @@ static void cond_destroy_internal(pse51_cond_t * cond, pse51_kqueues_t *q) * @see * http://www.opengroup.org/onlinepubs/95399/functions/pthread_cond_init.html";> * Specification. - * + * */ int pthread_cond_init(pthread_cond_t * cnd, const pthread_condattr_t * attr) { @@ -142,6 +143,7 @@ int pthread_cond_init(pthread_cond_t * cnd, const pthread_condattr_t * attr) shadow->magic = PSE51_COND_MAGIC; shadow->cond = cond; + cond->magic = PSE51_COND_MAGIC; xnsynch_init(&cond->synchbase, synch_flags, NULL); inith(&cond->link); cond->attr = *attr; @@ -179,7 +181,7 @@ int pthread_cond_init(pthread_cond_t * cnd, const pthread_condattr_t * attr) * @see * http://www.opengroup.org/onlinepubs/95399/functions/pthread_cond_destroy.html";> * Specification. - * + * */ int pthread_cond_destroy(pthread_cond_t * cnd) { @@ -189,12 +191,13 @@ int pthread_cond_destroy(pthread_cond_t * cnd) xnlock_get_irqsave(&nklock, s); - if (!pse51_obj_active(shadow, PSE51_COND_MAGIC, struct __shadow_cond)) { + cond = shadow->cond; + if (!pse51_obj_active(shadow, PSE51_COND_MAGIC, struct __shadow_cond) + || !pse51_obj_active(cond, PSE51_COND_MAGIC, struct pse51_cond)) { xnlock_put_irqrestore(&nklock, s); return EINVAL; } - cond = shadow->cond; if (cond->owningq != pse51_kqueues(cond->attr.pshared)) { xnlock_put_irqrestore(&nklock, s); return EPERM; @@ -206,6 +209,7 @@ int pthread_cond_destroy(pthread_cond_t * cnd) } pse51_mark_deleted(shadow); + pse51_mark_deleted(cond); xnlock_put_irqrestore(&nklock, s); @@ -224,10 +228,10 @@ static inline int mutex_save_count(xnthread_t *cur, { pse51_mutex_t *mutex; - if (!pse51_obj_active(shadow, PSE51_MUTEX_MAGIC, struct __shadow_mutex)) -return EINVAL; - mutex = shadow->mutex; + if (!pse51_obj_active(shadow, PSE51_MUTEX_MAGIC, struct __shadow_mutex) + || !pse51_obj_active(mutex, PSE51_MUTEX_MAGIC, struct pse51_mutex)) +return EINVAL; if (xnsynch_owner_check(&mutex->synchbase, cur) != 0) return EPERM; @@ -267,6 +271,7 @@ int pse51_cond_timedwait_prologue(xnthread_t *cur, /* If another thread waiting for cond does not use the same mutex */ if (!pse51_obj_active(shadow, PSE51_COND_MAGIC, struct __shadow_cond) + || !pse51_obj_active(cond, PSE51_COND_MAGIC, struct pse51_cond) || (cond->mutex && cond->mutex != mutex->mutex)) { err = EINVAL; goto unlock_and_return; @@ -403,7 +408,7 @@ int pse51_cond_timedwait_epilogue(xnthread_t *cur, * @see * http://www.opengroup.org/onlinepubs/95399/functions/pthread_cond_wait.html";> * Specification. - * + * */ int pthread_cond_wait(pthread_cond_t * cnd, pthread_mutex_t * mx) { @@ -470,7 +475,7 @@ int pthread_cond_wait(pthread_cond_t * cnd, pthread_mutex_t * mx) * @see * http://www.opengroup.org/onlinepubs/95399/functions/pthread_cond_timedwait.html";> * Specification. - * + * */ int pthread_cond_timedwait(pthread_cond_t * cnd, pthread_mutex_t * mx, const struct timespec *abstime) @@ -521,7 +526,7 @@ int pthread_cond_timedwait(pthread_cond_t * cnd, * @see * http://www.opengroup.org/onlinepubs/95399/functions/pthread_cond_signal.html.";> * Specification. - * + * */ int pthread_cond_signal(pthread_cond_t * cnd) { @@ -531,12 +536,13 @@ int pthread_cond_signal(pthread_cond_t * cnd) xnlock_get_irqsave(&nklock, s); - if (!pse51_obj_active(shadow, PSE51_COND_MAGIC, struct __shadow_cond)) { + cond = shadow->cond; + if (!pse51_obj_active(shadow,
[Xenomai-git] Gilles Chanteperdrix : posix: add a magic to internal structures.
Module: xenomai-2.5 Branch: master Commit: afc0eac7e4989f4134b18a256b5c5e1ca1c56a39 URL: http://git.xenomai.org/?p=xenomai-2.5.git;a=commit;h=afc0eac7e4989f4134b18a256b5c5e1ca1c56a39 Author: Gilles Chanteperdrix Date: Sun Aug 29 16:17:35 2010 +0200 posix: add a magic to internal structures. These structures may still be referenced by a process' child if they were destroyed by the father after the fork, so, use a magic in order to be able to detect this case. --- ksrc/skins/posix/cond.c | 37 + ksrc/skins/posix/mutex.c | 30 ++- ksrc/skins/posix/mutex.h |4 ++- ksrc/skins/posix/sem.c | 57 ++--- src/skins/posix/mutex.c |6 ++-- 5 files changed, 79 insertions(+), 55 deletions(-) diff --git a/ksrc/skins/posix/cond.c b/ksrc/skins/posix/cond.c index f86e85e..769eb4b 100644 --- a/ksrc/skins/posix/cond.c +++ b/ksrc/skins/posix/cond.c @@ -51,6 +51,7 @@ #include typedef struct pse51_cond { + unsigned magic; xnsynch_t synchbase; xnholder_t link;/* Link in pse51_condq */ @@ -101,7 +102,7 @@ static void cond_destroy_internal(pse51_cond_t * cond, pse51_kqueues_t *q) * @see * http://www.opengroup.org/onlinepubs/95399/functions/pthread_cond_init.html";> * Specification. - * + * */ int pthread_cond_init(pthread_cond_t * cnd, const pthread_condattr_t * attr) { @@ -142,6 +143,7 @@ int pthread_cond_init(pthread_cond_t * cnd, const pthread_condattr_t * attr) shadow->magic = PSE51_COND_MAGIC; shadow->cond = cond; + cond->magic = PSE51_COND_MAGIC; xnsynch_init(&cond->synchbase, synch_flags, NULL); inith(&cond->link); cond->attr = *attr; @@ -179,7 +181,7 @@ int pthread_cond_init(pthread_cond_t * cnd, const pthread_condattr_t * attr) * @see * http://www.opengroup.org/onlinepubs/95399/functions/pthread_cond_destroy.html";> * Specification. - * + * */ int pthread_cond_destroy(pthread_cond_t * cnd) { @@ -189,12 +191,13 @@ int pthread_cond_destroy(pthread_cond_t * cnd) xnlock_get_irqsave(&nklock, s); - if (!pse51_obj_active(shadow, PSE51_COND_MAGIC, struct __shadow_cond)) { + cond = shadow->cond; + if (!pse51_obj_active(shadow, PSE51_COND_MAGIC, struct __shadow_cond) + || !pse51_obj_active(cond, PSE51_COND_MAGIC, struct pse51_cond)) { xnlock_put_irqrestore(&nklock, s); return EINVAL; } - cond = shadow->cond; if (cond->owningq != pse51_kqueues(cond->attr.pshared)) { xnlock_put_irqrestore(&nklock, s); return EPERM; @@ -206,6 +209,7 @@ int pthread_cond_destroy(pthread_cond_t * cnd) } pse51_mark_deleted(shadow); + pse51_mark_deleted(cond); xnlock_put_irqrestore(&nklock, s); @@ -224,10 +228,10 @@ static inline int mutex_save_count(xnthread_t *cur, { pse51_mutex_t *mutex; - if (!pse51_obj_active(shadow, PSE51_MUTEX_MAGIC, struct __shadow_mutex)) -return EINVAL; - mutex = shadow->mutex; + if (!pse51_obj_active(shadow, PSE51_MUTEX_MAGIC, struct __shadow_mutex) + || !pse51_obj_active(mutex, PSE51_MUTEX_MAGIC, struct pse51_mutex)) +return EINVAL; if (xnsynch_owner_check(&mutex->synchbase, cur) != 0) return EPERM; @@ -267,6 +271,7 @@ int pse51_cond_timedwait_prologue(xnthread_t *cur, /* If another thread waiting for cond does not use the same mutex */ if (!pse51_obj_active(shadow, PSE51_COND_MAGIC, struct __shadow_cond) + || !pse51_obj_active(cond, PSE51_COND_MAGIC, struct pse51_cond) || (cond->mutex && cond->mutex != mutex->mutex)) { err = EINVAL; goto unlock_and_return; @@ -403,7 +408,7 @@ int pse51_cond_timedwait_epilogue(xnthread_t *cur, * @see * http://www.opengroup.org/onlinepubs/95399/functions/pthread_cond_wait.html";> * Specification. - * + * */ int pthread_cond_wait(pthread_cond_t * cnd, pthread_mutex_t * mx) { @@ -470,7 +475,7 @@ int pthread_cond_wait(pthread_cond_t * cnd, pthread_mutex_t * mx) * @see * http://www.opengroup.org/onlinepubs/95399/functions/pthread_cond_timedwait.html";> * Specification. - * + * */ int pthread_cond_timedwait(pthread_cond_t * cnd, pthread_mutex_t * mx, const struct timespec *abstime) @@ -521,7 +526,7 @@ int pthread_cond_timedwait(pthread_cond_t * cnd, * @see * http://www.opengroup.org/onlinepubs/95399/functions/pthread_cond_signal.html.";> * Specification. - * + * */ int pthread_cond_signal(pthread_cond_t * cnd) { @@ -531,12 +536,13 @@ int pthread_cond_signal(pthread_cond_t * cnd) xnlock_get_irqsave(&nklock, s); - if (!pse51_obj_active(shadow, PSE51_COND_MAGIC, struct __shadow_cond)) { + cond = shadow->cond; + if (!pse51_obj_active(shadow, PS