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

Author: Philippe Gerum <r...@xenomai.org>
Date:   Wed Sep  3 18:57:42 2014 +0200

lib/cobalt: sanitize base pointers to process heaps

---

 lib/cobalt/current.c  |    4 ++--
 lib/cobalt/internal.c |    8 ++++----
 lib/cobalt/internal.h |    5 +++--
 lib/cobalt/sem_heap.c |   18 +++++++++---------
 4 files changed, 18 insertions(+), 17 deletions(-)

diff --git a/lib/cobalt/current.c b/lib/cobalt/current.c
index f567335..9d10e22 100644
--- a/lib/cobalt/current.c
+++ b/lib/cobalt/current.c
@@ -41,7 +41,7 @@ static inline void __cobalt_set_tsd(xnhandle_t current, __u32 
u_winoff)
        struct xnthread_user_window *window;
 
        cobalt_current = current;
-       window = (void *)(cobalt_sem_heap[0] + u_winoff);
+       window = cobalt_sem_heap[0] + u_winoff;
        cobalt_current_window = window;
        cobalt_commit_memory(cobalt_current_window);
 }
@@ -69,7 +69,7 @@ static inline void __cobalt_set_tsd(xnhandle_t current,
        current = (current != XN_NO_HANDLE ? current : (xnhandle_t)0);
        pthread_setspecific(cobalt_current_key, (void *)(uintptr_t)current);
 
-       window = (void *)(cobalt_sem_heap[0] + u_winoff);
+       window = cobalt_sem_heap[0] + u_winoff;
        pthread_setspecific(cobalt_current_window_key, window);
        cobalt_commit_memory(window);
 }
diff --git a/lib/cobalt/internal.c b/lib/cobalt/internal.c
index fbcf9ee..2edf46b 100644
--- a/lib/cobalt/internal.c
+++ b/lib/cobalt/internal.c
@@ -156,7 +156,7 @@ static inline
 struct cobalt_monitor_data *get_monitor_data(cobalt_monitor_t *mon)
 {
        return mon->flags & COBALT_MONITOR_SHARED ?
-               (void *)cobalt_sem_heap[1] + mon->u.data_offset :
+               cobalt_sem_heap[1] + mon->u.data_offset :
                mon->u.data;
 }
 
@@ -171,7 +171,7 @@ int cobalt_monitor_init(cobalt_monitor_t *mon, clockid_t 
clk_id, int flags)
                return ret;
 
        if ((flags & COBALT_MONITOR_SHARED) == 0) {
-               datp = (void *)cobalt_sem_heap[0] + mon->u.data_offset;
+               datp = cobalt_sem_heap[0] + mon->u.data_offset;
                mon->u.data = datp;
        } else
                datp = get_monitor_data(mon);
@@ -433,7 +433,7 @@ static inline
 struct cobalt_event_data *get_event_data(cobalt_event_t *event)
 {
        return event->flags & COBALT_EVENT_SHARED ?
-               (void *)cobalt_sem_heap[1] + event->u.data_offset :
+               cobalt_sem_heap[1] + event->u.data_offset :
                event->u.data;
 }
 
@@ -448,7 +448,7 @@ int cobalt_event_init(cobalt_event_t *event, unsigned int 
value,
                return ret;
 
        if ((flags & COBALT_EVENT_SHARED) == 0) {
-               datp = (void *)cobalt_sem_heap[0] + event->u.data_offset;
+               datp = cobalt_sem_heap[0] + event->u.data_offset;
                event->u.data = datp;
        } else
                datp = get_event_data(event);
diff --git a/lib/cobalt/internal.h b/lib/cobalt/internal.h
index 567e583..1dad7d7 100644
--- a/lib/cobalt/internal.h
+++ b/lib/cobalt/internal.h
@@ -21,14 +21,15 @@
 #include <cobalt/sys/cobalt.h>
 #include "current.h"
 
-extern unsigned long cobalt_sem_heap[2];
+extern void *cobalt_sem_heap[2];
 
 void cobalt_sigshadow_install_once(void);
 
 static inline struct mutex_dat *mutex_get_datp(struct cobalt_mutex_shadow 
*shadow)
 {
        if (shadow->attr.pshared)
-               return (struct mutex_dat *)(cobalt_sem_heap[1] + 
shadow->dat_offset);
+               return (struct mutex_dat *)
+                       (cobalt_sem_heap[1] + shadow->dat_offset);
 
        return shadow->dat;
 }
diff --git a/lib/cobalt/sem_heap.c b/lib/cobalt/sem_heap.c
index bb0c8a5..dcfea8d 100644
--- a/lib/cobalt/sem_heap.c
+++ b/lib/cobalt/sem_heap.c
@@ -37,7 +37,7 @@
 
 struct xnvdso *vdso;
 
-unsigned long cobalt_sem_heap[2] = { 0, 0 };
+void *cobalt_sem_heap[2] = { NULL, NULL };
 
 static pthread_once_t init_private_heap = PTHREAD_ONCE_INIT;
 static struct cobalt_heapstat private_hdesc;
@@ -101,14 +101,14 @@ static void unmap_on_fork(void)
         * We replace former mappings with an invalid one, to detect
         * any spuriously late access from the fastsync code.
         */
-       addr = __STD(mmap((void *)cobalt_sem_heap[PRIVATE],
+       addr = __STD(mmap(cobalt_sem_heap[PRIVATE],
                          private_hdesc.size, PROT_NONE,
                          MAP_PRIVATE | MAP_ANONYMOUS | MAP_FIXED, -1, 0));
 
-       if (addr != (void *)cobalt_sem_heap[PRIVATE])
-               munmap((void *)cobalt_sem_heap[PRIVATE], private_hdesc.size);
+       if (addr != cobalt_sem_heap[PRIVATE])
+               munmap(cobalt_sem_heap[PRIVATE], private_hdesc.size);
 
-       cobalt_sem_heap[PRIVATE] = 0UL;
+       cobalt_sem_heap[PRIVATE] = NULL;
        init_private_heap = PTHREAD_ONCE_INIT;
 }
 
@@ -130,8 +130,8 @@ static void cobalt_init_vdso(void)
    after a fork */
 static void cobalt_init_private_heap(void)
 {
-       cobalt_sem_heap[PRIVATE] = (unsigned long)map_sem_heap(PRIVATE);
-       if (cobalt_sem_heap[PRIVATE] == (unsigned long)MAP_FAILED) {
+       cobalt_sem_heap[PRIVATE] = map_sem_heap(PRIVATE);
+       if (cobalt_sem_heap[PRIVATE] == MAP_FAILED) {
                report_error("cannot map private heap: %s",
                             strerror(errno));
                exit(EXIT_FAILURE);
@@ -143,8 +143,8 @@ static void cobalt_init_rest_once(void)
 {
        pthread_atfork(NULL, NULL, unmap_on_fork);
 
-       cobalt_sem_heap[SHARED] = (unsigned long)map_sem_heap(SHARED);
-       if (cobalt_sem_heap[SHARED] == (unsigned long)MAP_FAILED) {
+       cobalt_sem_heap[SHARED] = map_sem_heap(SHARED);
+       if (cobalt_sem_heap[SHARED] == MAP_FAILED) {
                report_error("cannot map shared heap: %s",
                             strerror(errno));
                exit(EXIT_FAILURE);


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

Reply via email to