Module: xenomai-3 Branch: next Commit: f1213999507416b1307882c9463059b284c13e29 URL: http://git.xenomai.org/?p=xenomai-3.git;a=commit;h=f1213999507416b1307882c9463059b284c13e29
Author: Philippe Gerum <r...@xenomai.org> Date: Sat Jul 18 15:08:03 2015 +0200 copperplate: deobfuscate private/shared references --- include/copperplate/cluster.h | 8 ++------ include/copperplate/heapobj.h | 26 +++++++++++--------------- include/copperplate/threadobj.h | 12 ++++-------- lib/copperplate/cluster.c | 10 +++++----- lib/copperplate/heapobj-malloc.c | 12 ++++++------ lib/copperplate/heapobj-pshared.c | 36 ++++++++++++++++++------------------ lib/copperplate/heapobj-tlsf.c | 2 +- lib/copperplate/threadobj.c | 4 ++-- 8 files changed, 49 insertions(+), 61 deletions(-) diff --git a/include/copperplate/cluster.h b/include/copperplate/cluster.h index 923e1bf..2ca07c6 100644 --- a/include/copperplate/cluster.h +++ b/include/copperplate/cluster.h @@ -156,12 +156,8 @@ pid_t pvclusterobj_cnode(const struct pvclusterobj *cobj) struct syncluster_wait_struct { union { - struct { - dref_type(char *) name; - } shrd; - struct { - const char *name; - } priv; + dref_type(char *) name_ref; + const char *name; }; }; diff --git a/include/copperplate/heapobj.h b/include/copperplate/heapobj.h index 42fe0d1..c61cf3e 100644 --- a/include/copperplate/heapobj.h +++ b/include/copperplate/heapobj.h @@ -34,18 +34,14 @@ struct heapobj { union { -#ifdef CONFIG_XENO_PSHARED - struct { - dref_type(void *) pool; - char fsname[256]; - } shrd; -#endif - struct { - void *pool; - } priv; + dref_type(void *) pool_ref; + void *pool; }; size_t size; char name[32]; +#ifdef CONFIG_XENO_PSHARED + char fsname[256]; +#endif }; struct sysgroup { @@ -85,13 +81,13 @@ size_t malloc_usable_size_ex(void *ptr, void *pool); static inline void pvheapobj_destroy(struct heapobj *hobj) { - destroy_memory_pool(hobj->priv.pool); + destroy_memory_pool(hobj->pool); } static inline int pvheapobj_extend(struct heapobj *hobj, size_t size, void *mem) { - hobj->size = add_new_area(hobj->priv.pool, size, mem); + hobj->size = add_new_area(hobj->pool, size, mem); if (hobj->size == (size_t)-1) return __bt(-EINVAL); @@ -101,25 +97,25 @@ int pvheapobj_extend(struct heapobj *hobj, size_t size, void *mem) static inline void *pvheapobj_alloc(struct heapobj *hobj, size_t size) { - return malloc_ex(size, hobj->priv.pool); + return malloc_ex(size, hobj->pool); } static inline void pvheapobj_free(struct heapobj *hobj, void *ptr) { - free_ex(ptr, hobj->priv.pool); + free_ex(ptr, hobj->pool); } static inline size_t pvheapobj_validate(struct heapobj *hobj, void *ptr) { - return malloc_usable_size_ex(ptr, hobj->priv.pool); + return malloc_usable_size_ex(ptr, hobj->pool); } static inline size_t pvheapobj_inquire(struct heapobj *hobj) { - return get_used_size(hobj->priv.pool); + return get_used_size(hobj->pool); } static inline void *pvmalloc(size_t size) diff --git a/include/copperplate/threadobj.h b/include/copperplate/threadobj.h index 38835f4..997334b 100644 --- a/include/copperplate/threadobj.h +++ b/include/copperplate/threadobj.h @@ -40,12 +40,8 @@ struct xnthread_user_window; struct threadobj_corespec { xnhandle_t handle; union { - struct { - __u32 u_winoff; - } shrd; - struct { - struct xnthread_user_window *u_window; - } priv; + __u32 u_winoff; + struct xnthread_user_window *u_window; }; }; @@ -88,7 +84,7 @@ static inline struct xnthread_user_window * threadobj_get_window(struct threadobj_corespec *corespec) { extern void *cobalt_umm_shared; - return cobalt_umm_shared + corespec->shrd.u_winoff; + return cobalt_umm_shared + corespec->u_winoff; } #else /* !CONFIG_XENO_PSHARED */ @@ -96,7 +92,7 @@ threadobj_get_window(struct threadobj_corespec *corespec) static inline struct xnthread_user_window * threadobj_get_window(struct threadobj_corespec *corespec) { - return corespec->priv.u_window; + return corespec->u_window; } #endif /* !CONFIG_XENO_PSHARED */ diff --git a/lib/copperplate/cluster.c b/lib/copperplate/cluster.c index 880ad58..eac0afe 100644 --- a/lib/copperplate/cluster.c +++ b/lib/copperplate/cluster.c @@ -309,7 +309,7 @@ int syncluster_addobj(struct syncluster *sc, const char *name, */ syncobj_for_each_grant_waiter_safe(&sc->d->sobj, thobj, tmp) { wait = threadobj_get_wait(thobj); - if (strcmp(__mptr(wait->shrd.name), name) == 0) + if (strcmp(__mptr(wait->name_ref), name) == 0) syncobj_grant_to(&sc->d->sobj, thobj); } out: @@ -365,7 +365,7 @@ int syncluster_findobj(struct syncluster *sc, } if (wait == NULL) { wait = threadobj_prepare_wait(struct syncluster_wait_struct); - wait->shrd.name = __moff(xnstrdup(name)); + wait->name_ref = __moff(xnstrdup(name)); } ret = syncobj_wait_grant(&sc->d->sobj, timeout, &syns); if (ret) { @@ -378,7 +378,7 @@ int syncluster_findobj(struct syncluster *sc, syncobj_unlock(&sc->d->sobj, &syns); out: if (wait) { - xnfree(__mptr(wait->shrd.name)); + xnfree(__mptr(wait->name_ref)); threadobj_finish_wait(); } @@ -518,7 +518,7 @@ int pvsyncluster_addobj(struct pvsyncluster *sc, const char *name, */ syncobj_for_each_grant_waiter_safe(&sc->sobj, thobj, tmp) { wait = threadobj_get_wait(thobj); - if (strcmp(wait->priv.name, name) == 0) + if (strcmp(wait->name, name) == 0) syncobj_grant_to(&sc->sobj, thobj); } out: @@ -573,7 +573,7 @@ int pvsyncluster_findobj(struct pvsyncluster *sc, } if (wait == NULL) { wait = threadobj_prepare_wait(struct syncluster_wait_struct); - wait->priv.name = name; + wait->name = name; } ret = syncobj_wait_grant(&sc->sobj, timeout, &syns); if (ret) { diff --git a/lib/copperplate/heapobj-malloc.c b/lib/copperplate/heapobj-malloc.c index 88a720b..ec82d78 100644 --- a/lib/copperplate/heapobj-malloc.c +++ b/lib/copperplate/heapobj-malloc.c @@ -71,7 +71,7 @@ int __heapobj_init_private(struct heapobj *hobj, const char *name, ph->used = 0; - hobj->priv.pool = ph; + hobj->pool = ph; hobj->size = size; if (name) snprintf(hobj->name, sizeof(hobj->name), "%s", name); @@ -89,7 +89,7 @@ int heapobj_init_array_private(struct heapobj *hobj, const char *name, void pvheapobj_destroy(struct heapobj *hobj) { - struct pool_header *ph = hobj->priv.pool; + struct pool_header *ph = hobj->pool; __RT(pthread_mutex_destroy(&ph->lock)); __STD(free(ph)); @@ -97,7 +97,7 @@ void pvheapobj_destroy(struct heapobj *hobj) int pvheapobj_extend(struct heapobj *hobj, size_t size, void *mem) { - struct pool_header *ph = hobj->priv.pool; + struct pool_header *ph = hobj->pool; write_lock_nocancel(&ph->lock); hobj->size += size; @@ -108,7 +108,7 @@ int pvheapobj_extend(struct heapobj *hobj, size_t size, void *mem) void *pvheapobj_alloc(struct heapobj *hobj, size_t size) { - struct pool_header *ph = hobj->priv.pool; + struct pool_header *ph = hobj->pool; struct block_header *bh; void *ptr; @@ -143,7 +143,7 @@ fail: void pvheapobj_free(struct heapobj *hobj, void *ptr) { struct block_header *bh = ptr - sizeof(*bh); - struct pool_header *ph = hobj->priv.pool; + struct pool_header *ph = hobj->pool; assert(hobj->size >= bh->size); write_lock(&ph->lock); @@ -154,7 +154,7 @@ void pvheapobj_free(struct heapobj *hobj, void *ptr) size_t pvheapobj_inquire(struct heapobj *hobj) { - struct pool_header *ph = hobj->priv.pool; + struct pool_header *ph = hobj->pool; return ph->used; } diff --git a/lib/copperplate/heapobj-pshared.c b/lib/copperplate/heapobj-pshared.c index 909e05c..61769c9 100644 --- a/lib/copperplate/heapobj-pshared.c +++ b/lib/copperplate/heapobj-pshared.c @@ -625,10 +625,10 @@ static int create_main_heap(pid_t *cnode_r) * bind to it. */ snprintf(hobj->name, sizeof(hobj->name), "%s.heap", session); - snprintf(hobj->shrd.fsname, sizeof(hobj->shrd.fsname), + snprintf(hobj->fsname, sizeof(hobj->fsname), "/xeno:%s", hobj->name); - fd = shm_open(hobj->shrd.fsname, O_RDWR|O_CREAT, 0600); + fd = shm_open(hobj->fsname, O_RDWR|O_CREAT, 0600); if (fd < 0) return __bt(-errno); @@ -652,7 +652,7 @@ static int create_main_heap(pid_t *cnode_r) /* CAUTION: __moff() depends on __main_heap. */ __main_heap = m_heap; __main_sysgroup = &m_heap->sysgroup; - hobj->shrd.pool = __moff(&m_heap->base); + hobj->pool_ref = __moff(&m_heap->base); goto done; } *cnode_r = m_heap->cpid; @@ -676,8 +676,8 @@ init: goto unlink_fail; m_heap->maplen = len; - /* CAUTION: init_main_heap() depends on hobj->shrd.pool. */ - hobj->shrd.pool = __moff(&m_heap->base); + /* CAUTION: init_main_heap() depends on hobj->pool_ref. */ + hobj->pool_ref = __moff(&m_heap->base); ret = init_main_heap(m_heap, (caddr_t)m_heap + sizeof(*m_heap), size); if (ret) { errno = -ret; @@ -699,7 +699,7 @@ unmap_fail: munmap(m_heap, len); unlink_fail: ret = __bt(-errno); - shm_unlink(hobj->shrd.fsname); + shm_unlink(hobj->fsname); goto close_fail; errno_fail: ret = __bt(-errno); @@ -720,10 +720,10 @@ static int bind_main_heap(const char *session) /* No error tracking, this is for internal users. */ snprintf(hobj->name, sizeof(hobj->name), "%s.heap", session); - snprintf(hobj->shrd.fsname, sizeof(hobj->shrd.fsname), + snprintf(hobj->fsname, sizeof(hobj->fsname), "/xeno:%s", hobj->name); - fd = shm_open(hobj->shrd.fsname, O_RDWR, 0400); + fd = shm_open(hobj->fsname, O_RDWR, 0400); if (fd < 0) return -errno; @@ -753,7 +753,7 @@ static int bind_main_heap(const char *session) return -ENOENT; } - hobj->shrd.pool = __moff(&m_heap->base); + hobj->pool_ref = __moff(&m_heap->base); hobj->size = m_heap->base.total; __main_heap = m_heap; __main_catalog = &m_heap->catalog; @@ -780,7 +780,7 @@ int pshared_check(void *__heap, void *__addr) * this one, so the address shall fall into the file-backed * memory range. */ - if (__moff(heap) == main_pool.shrd.pool) { + if (__moff(heap) == main_pool.pool_ref) { m_heap = container_of(heap, struct session_heap, base); return __addr >= (void *)m_heap && __addr < (void *)m_heap + m_heap->maplen; @@ -842,7 +842,7 @@ int heapobj_init(struct heapobj *hobj, const char *name, size_t size) snprintf(hobj->name, sizeof(hobj->name), "%s.%p", session, hobj); init_heap(heap, hobj->name, (caddr_t)heap + sizeof(*heap), size); - hobj->shrd.pool = __moff(heap); + hobj->pool_ref = __moff(heap); hobj->size = heap->total; sysgroup_add(heap, &heap->memspec); @@ -858,7 +858,7 @@ int heapobj_init_array(struct heapobj *hobj, const char *name, void heapobj_destroy(struct heapobj *hobj) { - struct shared_heap *heap = __mptr(hobj->shrd.pool); + struct shared_heap *heap = __mptr(hobj->pool_ref); int cpid; if (hobj != &main_pool) { @@ -877,12 +877,12 @@ void heapobj_destroy(struct heapobj *hobj) __RT(pthread_mutex_destroy(&heap->lock)); __RT(pthread_mutex_destroy(&main_heap.sysgroup.lock)); munmap(&main_heap, main_heap.maplen); - shm_unlink(hobj->shrd.fsname); + shm_unlink(hobj->fsname); } int heapobj_extend(struct heapobj *hobj, size_t size, void *unused) { - struct shared_heap *heap = __mptr(hobj->shrd.pool); + struct shared_heap *heap = __mptr(hobj->pool_ref); struct shared_extent *extent; int state; @@ -908,22 +908,22 @@ int heapobj_extend(struct heapobj *hobj, size_t size, void *unused) void *heapobj_alloc(struct heapobj *hobj, size_t size) { - return alloc_block(__mptr(hobj->shrd.pool), size); + return alloc_block(__mptr(hobj->pool_ref), size); } void heapobj_free(struct heapobj *hobj, void *ptr) { - free_block(__mptr(hobj->shrd.pool), ptr); + free_block(__mptr(hobj->pool_ref), ptr); } size_t heapobj_validate(struct heapobj *hobj, void *ptr) { - return __bt(check_block(__mptr(hobj->shrd.pool), ptr)); + return __bt(check_block(__mptr(hobj->pool_ref), ptr)); } size_t heapobj_inquire(struct heapobj *hobj) { - struct shared_heap *heap = __mptr(hobj->shrd.pool); + struct shared_heap *heap = __mptr(hobj->pool_ref); return heap->ubytes; } diff --git a/lib/copperplate/heapobj-tlsf.c b/lib/copperplate/heapobj-tlsf.c index a074633..e573380 100644 --- a/lib/copperplate/heapobj-tlsf.c +++ b/lib/copperplate/heapobj-tlsf.c @@ -53,7 +53,7 @@ int __heapobj_init_private(struct heapobj *hobj, const char *name, else snprintf(hobj->name, sizeof(hobj->name), "%p", hobj); - hobj->priv.pool = mem; + hobj->pool = mem; /* Make sure to wipe out tlsf's signature. */ memset(mem, 0, size < 32 ? size : 32); hobj->size = init_memory_pool(size, mem); diff --git a/lib/copperplate/threadobj.c b/lib/copperplate/threadobj.c index 47b3762..e5aefe9 100644 --- a/lib/copperplate/threadobj.c +++ b/lib/copperplate/threadobj.c @@ -253,7 +253,7 @@ static inline void threadobj_uninit_corespec(struct threadobj *thobj) static inline int threadobj_setup_corespec(struct threadobj *thobj) { thobj->core.handle = cobalt_get_current(); - thobj->core.shrd.u_winoff = (void *)cobalt_get_current_window() - + thobj->core.u_winoff = (void *)cobalt_get_current_window() - cobalt_umm_shared; return 0; @@ -264,7 +264,7 @@ static inline int threadobj_setup_corespec(struct threadobj *thobj) static inline int threadobj_setup_corespec(struct threadobj *thobj) { thobj->core.handle = cobalt_get_current(); - thobj->core.priv.u_window = cobalt_get_current_window(); + thobj->core.u_window = cobalt_get_current_window(); return 0; } _______________________________________________ Xenomai-git mailing list Xenomai-git@xenomai.org http://xenomai.org/mailman/listinfo/xenomai-git