Module: xenomai-forge Branch: next Commit: bdfcfe58150ceee57efb4bef702a912760a65b3d URL: http://git.xenomai.org/?p=xenomai-forge.git;a=commit;h=bdfcfe58150ceee57efb4bef702a912760a65b3d
Author: Philippe Gerum <r...@xenomai.org> Date: Tue Apr 29 18:25:42 2014 +0200 alchemy: do not publish half-baked objects Object control blocks must be fully built and sane before indexed by their respective clusters. Otherwise, binding operations from remote threads may succeed too early, which open windows for referring to partly initialized objects, which would be quite unfortunate. --- lib/alchemy/alarm.c | 13 +++++++------ lib/alchemy/buffer.c | 14 ++++++++------ lib/alchemy/cond.c | 12 +++++++----- lib/alchemy/event.c | 14 ++++++++------ lib/alchemy/heap.c | 14 ++++++++------ lib/alchemy/mutex.c | 12 +++++++----- lib/alchemy/queue.c | 14 ++++++++------ lib/alchemy/sem.c | 12 +++++++----- lib/alchemy/task.c | 16 ++++++++-------- 9 files changed, 68 insertions(+), 53 deletions(-) diff --git a/lib/alchemy/alarm.c b/lib/alchemy/alarm.c index 16475d4..4e38941 100644 --- a/lib/alchemy/alarm.c +++ b/lib/alchemy/alarm.c @@ -189,22 +189,23 @@ int rt_alarm_create(RT_ALARM *alarm, const char *name, acb->arg = arg; acb->expiries = 0; memset(&acb->itmspec, 0, sizeof(acb->itmspec)); - acb->magic = alarm_magic; + registry_init_file_obstack(&acb->fsobj, ®istry_ops); + alarm->handle = (uintptr_t)acb; + acb->magic = alarm_magic; if (pvcluster_addobj(&alchemy_alarm_table, acb->name, &acb->cobj)) { + registry_destroy_file(&acb->fsobj); timerobj_destroy(&acb->tmobj); ret = -EEXIST; goto fail; } - registry_init_file_obstack(&acb->fsobj, ®istry_ops); ret = __bt(registry_add_file(&acb->fsobj, O_RDONLY, - "/alchemy/alarms/%s", - acb->name)); + "/alchemy/alarms/%s", acb->name)); if (ret) - warning("failed to export alarm %s to registry", - acb->name); + warning("failed to export alarm %s to registry, %s", + acb->name, symerror(ret)); CANCEL_RESTORE(svc); diff --git a/lib/alchemy/buffer.c b/lib/alchemy/buffer.c index f77a4c7..f648114 100644 --- a/lib/alchemy/buffer.c +++ b/lib/alchemy/buffer.c @@ -240,7 +240,6 @@ int rt_buffer_create(RT_BUFFER *bf, const char *name, } generate_name(bcb->name, name, &buffer_namegen); - bcb->magic = buffer_magic; bcb->mode = mode; bcb->bufsz = bufsz; bcb->rdoff = 0; @@ -249,9 +248,13 @@ int rt_buffer_create(RT_BUFFER *bf, const char *name, if (mode & B_PRIO) sobj_flags = SYNCOBJ_PRIO; + registry_init_file_obstack(&bcb->fsobj, ®istry_ops); + syncobj_init(&bcb->sobj, CLOCK_COPPERPLATE, sobj_flags, fnref_put(libalchemy, buffer_finalize)); + bcb->magic = buffer_magic; + if (syncluster_addobj(&alchemy_buffer_table, bcb->name, &bcb->cobj)) { ret = -EEXIST; goto fail_register; @@ -259,19 +262,18 @@ int rt_buffer_create(RT_BUFFER *bf, const char *name, bf->handle = mainheap_ref(bcb, uintptr_t); - registry_init_file_obstack(&bcb->fsobj, ®istry_ops); ret = __bt(registry_add_file(&bcb->fsobj, O_RDONLY, - "/alchemy/buffers/%s", - bcb->name)); + "/alchemy/buffers/%s", bcb->name)); if (ret) - warning("failed to export buffer %s to registry", - bcb->name); + warning("failed to export buffer %s to registry, %s", + bcb->name, symerror(ret)); CANCEL_RESTORE(svc); return 0; fail_register: + registry_destroy_file(&bcb->fsobj); syncobj_uninit(&bcb->sobj); xnfree(bcb->buf); fail_bufalloc: diff --git a/lib/alchemy/cond.c b/lib/alchemy/cond.c index 7b95636..e5db4a4 100644 --- a/lib/alchemy/cond.c +++ b/lib/alchemy/cond.c @@ -132,21 +132,23 @@ int rt_cond_create(RT_COND *cond, const char *name) __RT(pthread_condattr_setclock(&cattr, CLOCK_COPPERPLATE)); __RT(pthread_cond_init(&ccb->cond, &cattr)); __RT(pthread_condattr_destroy(&cattr)); + + registry_init_file(&ccb->fsobj, ®istry_ops, 0); + ccb->magic = cond_magic; if (syncluster_addobj(&alchemy_cond_table, ccb->name, &ccb->cobj)) { + registry_destroy_file(&ccb->fsobj); __RT(pthread_cond_destroy(&ccb->cond)); xnfree(ccb); ret = -EEXIST; } else { cond->handle = mainheap_ref(ccb, uintptr_t); - registry_init_file(&ccb->fsobj, ®istry_ops, 0); ret = __bt(registry_add_file(&ccb->fsobj, O_RDONLY, - "/alchemy/condvars/%s", - ccb->name)); + "/alchemy/condvars/%s", ccb->name)); if (ret) { - warning("failed to export condvar %s to registry", - ccb->name); + warning("failed to export condvar %s to registry, %s", + ccb->name, symerror(ret)); ret = 0; } } diff --git a/lib/alchemy/event.c b/lib/alchemy/event.c index 37c6569..6fb0dd2 100644 --- a/lib/alchemy/event.c +++ b/lib/alchemy/event.c @@ -186,7 +186,6 @@ int rt_event_create(RT_EVENT *event, const char *name, } generate_name(evcb->name, name, &event_namegen); - evcb->magic = event_magic; if (mode & EV_PRIO) evobj_flags = EVOBJ_PRIO; @@ -197,19 +196,22 @@ int rt_event_create(RT_EVENT *event, const char *name, goto out; } + registry_init_file_obstack(&evcb->fsobj, ®istry_ops); + + evcb->magic = event_magic; + if (syncluster_addobj(&alchemy_event_table, evcb->name, &evcb->cobj)) { + registry_destroy_file(&evcb->fsobj); eventobj_destroy(&evcb->evobj); xnfree(evcb); ret = -EEXIST; } else { event->handle = mainheap_ref(evcb, uintptr_t); - registry_init_file_obstack(&evcb->fsobj, ®istry_ops); ret = __bt(registry_add_file(&evcb->fsobj, O_RDONLY, - "/alchemy/events/%s", - evcb->name)); + "/alchemy/events/%s", evcb->name)); if (ret) { - warning("failed to export event %s to registry", - evcb->name); + warning("failed to export event %s to registry, %s", + evcb->name, symerror(ret)); ret = 0; } } diff --git a/lib/alchemy/heap.c b/lib/alchemy/heap.c index 560e085..734c809 100644 --- a/lib/alchemy/heap.c +++ b/lib/alchemy/heap.c @@ -245,7 +245,6 @@ int rt_heap_create(RT_HEAP *heap, } generate_name(hcb->name, name, &heap_namegen); - hcb->magic = heap_magic; hcb->mode = mode; hcb->size = heapsz; hcb->sba = NULL; @@ -253,23 +252,26 @@ int rt_heap_create(RT_HEAP *heap, if (mode & H_PRIO) sobj_flags = SYNCOBJ_PRIO; + registry_init_file_obstack(&hcb->fsobj, ®istry_ops); + syncobj_init(&hcb->sobj, CLOCK_COPPERPLATE, sobj_flags, fnref_put(libalchemy, heap_finalize)); + hcb->magic = heap_magic; + if (syncluster_addobj(&alchemy_heap_table, hcb->name, &hcb->cobj)) { + registry_destroy_file(&hcb->fsobj); syncobj_uninit(&hcb->sobj); heapobj_destroy(&hcb->hobj); xnfree(hcb); ret = -EEXIST; } else { heap->handle = mainheap_ref(hcb, uintptr_t); - registry_init_file_obstack(&hcb->fsobj, ®istry_ops); ret = __bt(registry_add_file(&hcb->fsobj, O_RDONLY, - "/alchemy/heaps/%s", - hcb->name)); + "/alchemy/heaps/%s", hcb->name)); if (ret) { - warning("failed to export heap %s to registry", - hcb->name); + warning("failed to export heap %s to registry, %s", + hcb->name, symerror(ret)); ret = 0; } } diff --git a/lib/alchemy/mutex.c b/lib/alchemy/mutex.c index a2c75d8..478b555 100644 --- a/lib/alchemy/mutex.c +++ b/lib/alchemy/mutex.c @@ -140,20 +140,22 @@ int rt_mutex_create(RT_MUTEX *mutex, const char *name) #endif __RT(pthread_mutex_init(&mcb->lock, &mattr)); __RT(pthread_mutexattr_destroy(&mattr)); + + registry_init_file(&mcb->fsobj, ®istry_ops, 0); + mcb->magic = mutex_magic; if (syncluster_addobj(&alchemy_mutex_table, mcb->name, &mcb->cobj)) { + registry_destroy_file(&mcb->fsobj); xnfree(mcb); ret = -EEXIST; } else { mutex->handle = mainheap_ref(mcb, uintptr_t); - registry_init_file(&mcb->fsobj, ®istry_ops, 0); ret = __bt(registry_add_file(&mcb->fsobj, O_RDONLY, - "/alchemy/mutexes/%s", - mcb->name)); + "/alchemy/mutexes/%s", mcb->name)); if (ret) { - warning("failed to export mutex %s to registry", - mcb->name); + warning("failed to export mutex %s to registry, %s", + mcb->name, symerror(ret)); ret = 0; } } diff --git a/lib/alchemy/queue.c b/lib/alchemy/queue.c index 4cb2a4f..4432c40 100644 --- a/lib/alchemy/queue.c +++ b/lib/alchemy/queue.c @@ -243,7 +243,6 @@ int rt_queue_create(RT_QUEUE *queue, const char *name, goto out; } - qcb->magic = queue_magic; qcb->mode = mode; qcb->limit = qlimit; list_init(&qcb->mq); @@ -255,20 +254,23 @@ int rt_queue_create(RT_QUEUE *queue, const char *name, syncobj_init(&qcb->sobj, CLOCK_COPPERPLATE, sobj_flags, fnref_put(libalchemy, queue_finalize)); + registry_init_file_obstack(&qcb->fsobj, ®istry_ops); + + qcb->magic = queue_magic; + if (syncluster_addobj(&alchemy_queue_table, qcb->name, &qcb->cobj)) { + registry_destroy_file(&qcb->fsobj); heapobj_destroy(&qcb->hobj); syncobj_uninit(&qcb->sobj); xnfree(qcb); ret = -EEXIST; } else { queue->handle = mainheap_ref(qcb, uintptr_t); - registry_init_file_obstack(&qcb->fsobj, ®istry_ops); ret = __bt(registry_add_file(&qcb->fsobj, O_RDONLY, - "/alchemy/queues/%s", - qcb->name)); + "/alchemy/queues/%s", qcb->name)); if (ret) { - warning("failed to export queue %s to registry", - qcb->name); + warning("failed to export queue %s to registry, %s", + qcb->name, symerror(ret)); ret = 0; } } diff --git a/lib/alchemy/sem.c b/lib/alchemy/sem.c index f2bb241..f7ec3f7 100644 --- a/lib/alchemy/sem.c +++ b/lib/alchemy/sem.c @@ -211,21 +211,23 @@ int rt_sem_create(RT_SEM *sem, const char *name, } generate_name(scb->name, name, &sem_namegen); + + registry_init_file_obstack(&scb->fsobj, ®istry_ops); + scb->magic = sem_magic; if (syncluster_addobj(&alchemy_sem_table, scb->name, &scb->cobj)) { + registry_destroy_file(&scb->fsobj); semobj_destroy(&scb->smobj); xnfree(scb); ret = -EEXIST; } else { sem->handle = mainheap_ref(scb, uintptr_t); - registry_init_file_obstack(&scb->fsobj, ®istry_ops); ret = __bt(registry_add_file(&scb->fsobj, O_RDONLY, - "/alchemy/semaphores/%s", - scb->name)); + "/alchemy/semaphores/%s", scb->name)); if (ret) { - warning("failed to export semaphore %s to registry", - scb->name); + warning("failed to export semaphore %s to registry, %s", + scb->name, symerror(ret)); ret = 0; } } diff --git a/lib/alchemy/task.c b/lib/alchemy/task.c index ebc8987..fc88218 100644 --- a/lib/alchemy/task.c +++ b/lib/alchemy/task.c @@ -277,22 +277,22 @@ static int create_tcb(struct alchemy_task **tcbp, RT_TASK *task, */ tcb->self.handle = mainheap_ref(tcb, uintptr_t); + registry_init_file_obstack(&tcb->fsobj, ®istry_ops); + if (syncluster_addobj(&alchemy_task_table, tcb->name, &tcb->cobj)) { + registry_destroy_file(&tcb->fsobj); delete_tcb(tcb); return -EEXIST; } - registry_init_file_obstack(&tcb->fsobj, ®istry_ops); - ret = __bt(registry_add_file(&tcb->fsobj, O_RDONLY, - "/alchemy/tasks/%s", - tcb->name)); - if (ret) - warning("failed to export task %s to registry", - tcb->name); - if (task) task->handle = tcb->self.handle; + ret = __bt(registry_add_file(&tcb->fsobj, O_RDONLY, + "/alchemy/tasks/%s", tcb->name)); + if (ret) + warning("failed to export task %s to registry, %s", + tcb->name, symerror(ret)); return 0; } _______________________________________________ Xenomai-git mailing list Xenomai-git@xenomai.org http://www.xenomai.org/mailman/listinfo/xenomai-git