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

Author: Philippe Gerum <r...@xenomai.org>
Date:   Thu Nov 17 09:50:19 2011 +0100

copperplate/debug: use malloc() for logging memory

Only malloc() is safe to use at any time, even in case of memory
allocation error in the non-malloc heapobj implementations. If there
is a malloc() error, well, we'll lose the backtracing data, but won't
deadlock into the allocator code.

---

 include/copperplate/debug.h |    3 ---
 lib/copperplate/debug.c     |   35 +++--------------------------------
 lib/copperplate/init.c      |    1 -
 3 files changed, 3 insertions(+), 36 deletions(-)

diff --git a/include/copperplate/debug.h b/include/copperplate/debug.h
index 375b2c0..2811e2b 100644
--- a/include/copperplate/debug.h
+++ b/include/copperplate/debug.h
@@ -75,8 +75,6 @@ char *__get_error_buf(size_t *sizep);
 
 int debug_pkg_init(void);
 
-void debug_pkg_activate(void);
-
 #ifdef __cplusplus
 }
 #endif
@@ -124,7 +122,6 @@ struct backtrace_data {
        })
 
 #define debug_pkg_init()       ({ 0; })
-#define debug_pkg_activate()   ({ 0; })
 
 #endif /* !__XENO_DEBUG__ */
 
diff --git a/lib/copperplate/debug.c b/lib/copperplate/debug.c
index 6bcd1a7..8ce9b8a 100644
--- a/lib/copperplate/debug.c
+++ b/lib/copperplate/debug.c
@@ -22,6 +22,7 @@
 #include <unistd.h>
 #include <assert.h>
 #include <pthread.h>
+#include <malloc.h>
 #include <errno.h>
 #include "copperplate/lock.h"
 #include "copperplate/debug.h"
@@ -35,30 +36,6 @@ static struct backtrace_data main_btd = {
        .name = "main",
 };
 
-static void *safe_malloc(size_t size)
-{
-       return malloc(size);
-}
-
-static void safe_free(void *p)
-{
-       free(p);
-}
-
-static void *fast_malloc(size_t size)
-{
-       return xnmalloc(size);
-}
-
-static void fast_free(void *p)
-{
-       xnfree(p);
-}
-
-static void *(*do_malloc)(size_t size) = safe_malloc;
-
-static void (*do_free)(void *p) = safe_free;
-
 void __debug(struct threadobj *thobj, const char *fmt, ...)
 {
        va_list ap;
@@ -81,7 +58,7 @@ void backtrace_log(int retval, const char *fn,
 
        pthread_setcanceltype(PTHREAD_CANCEL_DEFERRED, &state);
 
-       ef = do_malloc(sizeof(*ef));
+       ef = malloc(sizeof(*ef));
        if (ef == NULL)
                goto out;
 
@@ -117,7 +94,7 @@ static void flush_backtrace(struct backtrace_data *btd)
 
        for (ef = btd->inner; ef; ef = nef) {
                nef = ef->next;
-               do_free(ef);
+               free(ef);
        }
 
        btd->inner = NULL;
@@ -205,9 +182,3 @@ int debug_pkg_init(void)
        __RT(pthread_mutex_init(&main_btd.lock, NULL));
        return -pthread_key_create(&btkey, NULL);
 }
-
-void debug_pkg_activate(void)
-{
-       do_malloc = fast_malloc;
-       do_free = fast_free;
-}
diff --git a/lib/copperplate/init.c b/lib/copperplate/init.c
index e477d38..1b35674 100644
--- a/lib/copperplate/init.c
+++ b/lib/copperplate/init.c
@@ -284,7 +284,6 @@ void copperplate_init(int argc, char *const argv[])
        }
 
        optind = 0;
-       debug_pkg_activate();
 
        return;
 fail:


_______________________________________________
Xenomai-git mailing list
Xenomai-git@gna.org
https://mail.gna.org/listinfo/xenomai-git

Reply via email to