[Xenomai-git] Philippe Gerum : copperplate/heapobj: enable heapmem for private memory

2018-05-20 Thread git repository hosting
Module: xenomai-3
Branch: next
Commit: 3354a6255a69d2de950eae5691ac71c701ba3a99
URL:
http://git.xenomai.org/?p=xenomai-3.git;a=commit;h=3354a6255a69d2de950eae5691ac71c701ba3a99

Author: Philippe Gerum 
Date:   Sun Apr 22 19:50:57 2018 +0200

copperplate/heapobj: enable heapmem for private memory

Make HEAPMEM the default private memory allocator for real-time
configurations (cobalt || (mercury && non-debug)).

This setting can be reverted by passing --with-localmem=tlsf.

---

 configure.ac  |   51 ++---
 include/copperplate/heapobj.h |   68 ++-
 lib/boilerplate/Makefile.am   |7 ++-
 lib/copperplate/Makefile.am   |4 ++
 lib/copperplate/heapobj-heapmem.c |   91 +
 5 files changed, 209 insertions(+), 12 deletions(-)

diff --git a/configure.ac b/configure.ac
index c0ef1df..b670206 100644
--- a/configure.ac
+++ b/configure.ac
@@ -327,6 +327,26 @@ if test x$use_pshared = xy; then
 fi
 AM_CONDITIONAL(XENO_PSHARED,[test x$use_pshared = xy])
 
+dnl Allocator selection
+
+localmem_allocator=heapmem
+AC_MSG_CHECKING([for process-local memory allocator])
+AC_ARG_WITH(localmem,
+AS_HELP_STRING([--with-localmem=],[Select process-local 
memory allocator]),
+[
+   case "$withval" in
+   "" | y | ye | yes | n | no)
+   AC_MSG_ERROR([You must supply an argument to --with-localmem])
+ ;;
+   heapmem|tlsf)
+  localmem_allocator=$withval
+  ;;
+   *)
+   AC_MSG_ERROR([--localmem-allocator=])
+   esac
+])
+AC_MSG_RESULT($localmem_allocator)
+
 dnl Registry support in user-space (FUSE-based, default: off)
 
 use_registry=
@@ -610,12 +630,31 @@ AM_CONDITIONAL(CONFIG_XENO_SHARED,[test "$enable_shared" 
= 'yes'])
 # Default sampling period (ns) used in various tests
 
AC_DEFINE_UNQUOTED(CONFIG_XENO_DEFAULT_PERIOD,$CONFIG_XENO_DEFAULT_PERIOD,[config])
 
-dnl Allocator for Copperplate
-dnl Note: in dual kernel mode, we don't want malloc, no matter what.
-dnl We switch to malloc only over the Mercury core in debug mode, to ease
-dnl debugging with valgrind, instrumented glibc etc.
-AM_CONDITIONAL(XENO_TLSF,[test $rtcore_type = cobalt -o x$debug_mode = x])
-test $rtcore_type = cobalt -o x$debug_mode = x && 
AC_DEFINE(CONFIG_XENO_TLSF,1,[config])
+dnl Allocator for Copperplate. Note: in dual kernel mode, we don't
+dnl want malloc, no matter what: pick either heapmem or tlsf, defaults
+dnl to heapmem. Force switch to malloc over the Mercury core in debug
+dnl mode, to ease debugging with valgrind, instrumented glibc etc.
+
+if test $rtcore_type = cobalt -o x$debug_mode = x; then
+   case $localmem_allocator in
+   heapmem)
+   AC_DEFINE(CONFIG_XENO_HEAPMEM,1,[config])
+   use_heapmem=y
+   use_tlsf=
+   ;;
+   tlsf)
+   AC_DEFINE(CONFIG_XENO_TLSF,1,[config])
+   use_tlsf=y
+   use_heapmem=
+   ;;
+   esac
+else
+   use_heapmem=
+   use_tlsf=
+AC_MSG_WARN([using malloc() for private memory in debug mode])
+fi
+AM_CONDITIONAL(XENO_TLSF,[test x$use_tlsf = xy])
+AM_CONDITIONAL(XENO_HEAPMEM,[test x$use_heapmem = xy])
 
 dnl Check for atomic builtins. For now we only check for the legacy
 dnl interface, i.e. __sync_*.
diff --git a/include/copperplate/heapobj.h b/include/copperplate/heapobj.h
index dc2a45d..c8a7773 100644
--- a/include/copperplate/heapobj.h
+++ b/include/copperplate/heapobj.h
@@ -139,7 +139,71 @@ static inline char *pvstrdup(const char *ptr)
return strcpy(str, ptr);
 }
 
-#else /* !CONFIG_XENO_TLSF, i.e. malloc */
+#elif defined(CONFIG_XENO_HEAPMEM)
+
+#include 
+
+extern struct heap_memory heapmem_main;
+
+static inline
+void pvheapobj_destroy(struct heapobj *hobj)
+{
+   heapmem_destroy(hobj->pool);
+}
+
+static inline
+int pvheapobj_extend(struct heapobj *hobj, size_t size, void *mem)
+{
+   return heapmem_extend(hobj->pool, mem, size);
+}
+
+static inline
+void *pvheapobj_alloc(struct heapobj *hobj, size_t size)
+{
+   return heapmem_alloc(hobj->pool, size);
+}
+
+static inline
+void pvheapobj_free(struct heapobj *hobj, void *ptr)
+{
+   heapmem_free(hobj->pool, ptr);
+}
+
+static inline
+size_t pvheapobj_validate(struct heapobj *hobj, void *ptr)
+{
+   ssize_t size = heapmem_check(hobj->pool, ptr);
+   return size < 0 ? 0 : size;
+}
+
+static inline
+size_t pvheapobj_inquire(struct heapobj *hobj)
+{
+   return heapmem_used_size(hobj->pool);
+}
+
+static inline void *pvmalloc(size_t size)
+{
+   return heapmem_alloc(_main, size);
+}
+
+static inline void pvfree(void *ptr)
+{
+   heapmem_free(_main, ptr);
+}
+
+static inline char *pvstrdup(const char *ptr)
+{
+   char *str;
+
+   str = (char *)pvmalloc(strlen(ptr) + 1);
+   if (str == NULL)
+   return NULL;
+
+   return strcpy(str, ptr);
+}
+
+#else /* !CONFIG_XENO_HEAPMEM, i.e. malloc */
 
 #include 
 
@@ -176,7 

[Xenomai-git] Philippe Gerum : copperplate/heapobj: enable heapmem for private memory

2018-05-16 Thread git repository hosting
Module: xenomai-3
Branch: wip/heapmem
Commit: 9cf7116e796d6d29d42c67a8231dbddc889ccf41
URL:
http://git.xenomai.org/?p=xenomai-3.git;a=commit;h=9cf7116e796d6d29d42c67a8231dbddc889ccf41

Author: Philippe Gerum 
Date:   Sun Apr 22 19:50:57 2018 +0200

copperplate/heapobj: enable heapmem for private memory

Make HEAPMEM the default private memory allocator for real-time
configurations (cobalt || (mercury && non-debug)).

This setting can be reverted by passing --with-localmem=tlsf.

---

 configure.ac  |   51 ++---
 include/copperplate/heapobj.h |   68 ++-
 lib/boilerplate/Makefile.am   |7 ++-
 lib/copperplate/Makefile.am   |4 ++
 lib/copperplate/heapobj-heapmem.c |   91 +
 5 files changed, 209 insertions(+), 12 deletions(-)

diff --git a/configure.ac b/configure.ac
index c0ef1df..b670206 100644
--- a/configure.ac
+++ b/configure.ac
@@ -327,6 +327,26 @@ if test x$use_pshared = xy; then
 fi
 AM_CONDITIONAL(XENO_PSHARED,[test x$use_pshared = xy])
 
+dnl Allocator selection
+
+localmem_allocator=heapmem
+AC_MSG_CHECKING([for process-local memory allocator])
+AC_ARG_WITH(localmem,
+AS_HELP_STRING([--with-localmem=],[Select process-local 
memory allocator]),
+[
+   case "$withval" in
+   "" | y | ye | yes | n | no)
+   AC_MSG_ERROR([You must supply an argument to --with-localmem])
+ ;;
+   heapmem|tlsf)
+  localmem_allocator=$withval
+  ;;
+   *)
+   AC_MSG_ERROR([--localmem-allocator=])
+   esac
+])
+AC_MSG_RESULT($localmem_allocator)
+
 dnl Registry support in user-space (FUSE-based, default: off)
 
 use_registry=
@@ -610,12 +630,31 @@ AM_CONDITIONAL(CONFIG_XENO_SHARED,[test "$enable_shared" 
= 'yes'])
 # Default sampling period (ns) used in various tests
 
AC_DEFINE_UNQUOTED(CONFIG_XENO_DEFAULT_PERIOD,$CONFIG_XENO_DEFAULT_PERIOD,[config])
 
-dnl Allocator for Copperplate
-dnl Note: in dual kernel mode, we don't want malloc, no matter what.
-dnl We switch to malloc only over the Mercury core in debug mode, to ease
-dnl debugging with valgrind, instrumented glibc etc.
-AM_CONDITIONAL(XENO_TLSF,[test $rtcore_type = cobalt -o x$debug_mode = x])
-test $rtcore_type = cobalt -o x$debug_mode = x && 
AC_DEFINE(CONFIG_XENO_TLSF,1,[config])
+dnl Allocator for Copperplate. Note: in dual kernel mode, we don't
+dnl want malloc, no matter what: pick either heapmem or tlsf, defaults
+dnl to heapmem. Force switch to malloc over the Mercury core in debug
+dnl mode, to ease debugging with valgrind, instrumented glibc etc.
+
+if test $rtcore_type = cobalt -o x$debug_mode = x; then
+   case $localmem_allocator in
+   heapmem)
+   AC_DEFINE(CONFIG_XENO_HEAPMEM,1,[config])
+   use_heapmem=y
+   use_tlsf=
+   ;;
+   tlsf)
+   AC_DEFINE(CONFIG_XENO_TLSF,1,[config])
+   use_tlsf=y
+   use_heapmem=
+   ;;
+   esac
+else
+   use_heapmem=
+   use_tlsf=
+AC_MSG_WARN([using malloc() for private memory in debug mode])
+fi
+AM_CONDITIONAL(XENO_TLSF,[test x$use_tlsf = xy])
+AM_CONDITIONAL(XENO_HEAPMEM,[test x$use_heapmem = xy])
 
 dnl Check for atomic builtins. For now we only check for the legacy
 dnl interface, i.e. __sync_*.
diff --git a/include/copperplate/heapobj.h b/include/copperplate/heapobj.h
index dc2a45d..c8a7773 100644
--- a/include/copperplate/heapobj.h
+++ b/include/copperplate/heapobj.h
@@ -139,7 +139,71 @@ static inline char *pvstrdup(const char *ptr)
return strcpy(str, ptr);
 }
 
-#else /* !CONFIG_XENO_TLSF, i.e. malloc */
+#elif defined(CONFIG_XENO_HEAPMEM)
+
+#include 
+
+extern struct heap_memory heapmem_main;
+
+static inline
+void pvheapobj_destroy(struct heapobj *hobj)
+{
+   heapmem_destroy(hobj->pool);
+}
+
+static inline
+int pvheapobj_extend(struct heapobj *hobj, size_t size, void *mem)
+{
+   return heapmem_extend(hobj->pool, mem, size);
+}
+
+static inline
+void *pvheapobj_alloc(struct heapobj *hobj, size_t size)
+{
+   return heapmem_alloc(hobj->pool, size);
+}
+
+static inline
+void pvheapobj_free(struct heapobj *hobj, void *ptr)
+{
+   heapmem_free(hobj->pool, ptr);
+}
+
+static inline
+size_t pvheapobj_validate(struct heapobj *hobj, void *ptr)
+{
+   ssize_t size = heapmem_check(hobj->pool, ptr);
+   return size < 0 ? 0 : size;
+}
+
+static inline
+size_t pvheapobj_inquire(struct heapobj *hobj)
+{
+   return heapmem_used_size(hobj->pool);
+}
+
+static inline void *pvmalloc(size_t size)
+{
+   return heapmem_alloc(_main, size);
+}
+
+static inline void pvfree(void *ptr)
+{
+   heapmem_free(_main, ptr);
+}
+
+static inline char *pvstrdup(const char *ptr)
+{
+   char *str;
+
+   str = (char *)pvmalloc(strlen(ptr) + 1);
+   if (str == NULL)
+   return NULL;
+
+   return strcpy(str, ptr);
+}
+
+#else /* !CONFIG_XENO_HEAPMEM, i.e. malloc */
 
 #include 
 
@@ 

[Xenomai-git] Philippe Gerum : copperplate/heapobj: enable heapmem for private memory

2018-04-27 Thread git repository hosting
Module: xenomai-3
Branch: wip/heapmem
Commit: df72ae08afc7711a600ad5c1b4fd5f72639f565e
URL:
http://git.xenomai.org/?p=xenomai-3.git;a=commit;h=df72ae08afc7711a600ad5c1b4fd5f72639f565e

Author: Philippe Gerum 
Date:   Sun Apr 22 19:50:57 2018 +0200

copperplate/heapobj: enable heapmem for private memory

Make HEAPMEM the default private memory allocator for real-time
configurations (cobalt || (mercury && non-debug)).

This setting can be reverted by passing --with-localmem=tlsf.

---

 configure.ac  |   51 ++---
 include/copperplate/heapobj.h |   68 ++-
 lib/boilerplate/Makefile.am   |7 ++-
 lib/copperplate/Makefile.am   |4 ++
 lib/copperplate/heapobj-heapmem.c |   91 +
 5 files changed, 209 insertions(+), 12 deletions(-)

diff --git a/configure.ac b/configure.ac
index c0ef1df..b670206 100644
--- a/configure.ac
+++ b/configure.ac
@@ -327,6 +327,26 @@ if test x$use_pshared = xy; then
 fi
 AM_CONDITIONAL(XENO_PSHARED,[test x$use_pshared = xy])
 
+dnl Allocator selection
+
+localmem_allocator=heapmem
+AC_MSG_CHECKING([for process-local memory allocator])
+AC_ARG_WITH(localmem,
+AS_HELP_STRING([--with-localmem=],[Select process-local 
memory allocator]),
+[
+   case "$withval" in
+   "" | y | ye | yes | n | no)
+   AC_MSG_ERROR([You must supply an argument to --with-localmem])
+ ;;
+   heapmem|tlsf)
+  localmem_allocator=$withval
+  ;;
+   *)
+   AC_MSG_ERROR([--localmem-allocator=])
+   esac
+])
+AC_MSG_RESULT($localmem_allocator)
+
 dnl Registry support in user-space (FUSE-based, default: off)
 
 use_registry=
@@ -610,12 +630,31 @@ AM_CONDITIONAL(CONFIG_XENO_SHARED,[test "$enable_shared" 
= 'yes'])
 # Default sampling period (ns) used in various tests
 
AC_DEFINE_UNQUOTED(CONFIG_XENO_DEFAULT_PERIOD,$CONFIG_XENO_DEFAULT_PERIOD,[config])
 
-dnl Allocator for Copperplate
-dnl Note: in dual kernel mode, we don't want malloc, no matter what.
-dnl We switch to malloc only over the Mercury core in debug mode, to ease
-dnl debugging with valgrind, instrumented glibc etc.
-AM_CONDITIONAL(XENO_TLSF,[test $rtcore_type = cobalt -o x$debug_mode = x])
-test $rtcore_type = cobalt -o x$debug_mode = x && 
AC_DEFINE(CONFIG_XENO_TLSF,1,[config])
+dnl Allocator for Copperplate. Note: in dual kernel mode, we don't
+dnl want malloc, no matter what: pick either heapmem or tlsf, defaults
+dnl to heapmem. Force switch to malloc over the Mercury core in debug
+dnl mode, to ease debugging with valgrind, instrumented glibc etc.
+
+if test $rtcore_type = cobalt -o x$debug_mode = x; then
+   case $localmem_allocator in
+   heapmem)
+   AC_DEFINE(CONFIG_XENO_HEAPMEM,1,[config])
+   use_heapmem=y
+   use_tlsf=
+   ;;
+   tlsf)
+   AC_DEFINE(CONFIG_XENO_TLSF,1,[config])
+   use_tlsf=y
+   use_heapmem=
+   ;;
+   esac
+else
+   use_heapmem=
+   use_tlsf=
+AC_MSG_WARN([using malloc() for private memory in debug mode])
+fi
+AM_CONDITIONAL(XENO_TLSF,[test x$use_tlsf = xy])
+AM_CONDITIONAL(XENO_HEAPMEM,[test x$use_heapmem = xy])
 
 dnl Check for atomic builtins. For now we only check for the legacy
 dnl interface, i.e. __sync_*.
diff --git a/include/copperplate/heapobj.h b/include/copperplate/heapobj.h
index dc2a45d..c8a7773 100644
--- a/include/copperplate/heapobj.h
+++ b/include/copperplate/heapobj.h
@@ -139,7 +139,71 @@ static inline char *pvstrdup(const char *ptr)
return strcpy(str, ptr);
 }
 
-#else /* !CONFIG_XENO_TLSF, i.e. malloc */
+#elif defined(CONFIG_XENO_HEAPMEM)
+
+#include 
+
+extern struct heap_memory heapmem_main;
+
+static inline
+void pvheapobj_destroy(struct heapobj *hobj)
+{
+   heapmem_destroy(hobj->pool);
+}
+
+static inline
+int pvheapobj_extend(struct heapobj *hobj, size_t size, void *mem)
+{
+   return heapmem_extend(hobj->pool, mem, size);
+}
+
+static inline
+void *pvheapobj_alloc(struct heapobj *hobj, size_t size)
+{
+   return heapmem_alloc(hobj->pool, size);
+}
+
+static inline
+void pvheapobj_free(struct heapobj *hobj, void *ptr)
+{
+   heapmem_free(hobj->pool, ptr);
+}
+
+static inline
+size_t pvheapobj_validate(struct heapobj *hobj, void *ptr)
+{
+   ssize_t size = heapmem_check(hobj->pool, ptr);
+   return size < 0 ? 0 : size;
+}
+
+static inline
+size_t pvheapobj_inquire(struct heapobj *hobj)
+{
+   return heapmem_used_size(hobj->pool);
+}
+
+static inline void *pvmalloc(size_t size)
+{
+   return heapmem_alloc(_main, size);
+}
+
+static inline void pvfree(void *ptr)
+{
+   heapmem_free(_main, ptr);
+}
+
+static inline char *pvstrdup(const char *ptr)
+{
+   char *str;
+
+   str = (char *)pvmalloc(strlen(ptr) + 1);
+   if (str == NULL)
+   return NULL;
+
+   return strcpy(str, ptr);
+}
+
+#else /* !CONFIG_XENO_HEAPMEM, i.e. malloc */
 
 #include 
 
@@ 

[Xenomai-git] Philippe Gerum : copperplate/heapobj: enable heapmem for private memory

2018-04-27 Thread git repository hosting
Module: xenomai-3
Branch: wip/heapmem
Commit: 26fbb2c8e0116552b8dce4c1fc2a0a1036e8c402
URL:
http://git.xenomai.org/?p=xenomai-3.git;a=commit;h=26fbb2c8e0116552b8dce4c1fc2a0a1036e8c402

Author: Philippe Gerum 
Date:   Sun Apr 22 19:50:57 2018 +0200

copperplate/heapobj: enable heapmem for private memory

Make HEAPMEM the default private memory allocator for real-time
configurations (cobalt || (mercury && non-debug)).

This setting can be reverted by passing --with-localmem=tlsf.

---

 configure.ac  |   51 ++---
 include/copperplate/heapobj.h |   68 ++-
 lib/boilerplate/Makefile.am   |7 ++-
 lib/copperplate/Makefile.am   |4 ++
 lib/copperplate/heapobj-heapmem.c |   91 +
 5 files changed, 209 insertions(+), 12 deletions(-)

diff --git a/configure.ac b/configure.ac
index c0ef1df..b670206 100644
--- a/configure.ac
+++ b/configure.ac
@@ -327,6 +327,26 @@ if test x$use_pshared = xy; then
 fi
 AM_CONDITIONAL(XENO_PSHARED,[test x$use_pshared = xy])
 
+dnl Allocator selection
+
+localmem_allocator=heapmem
+AC_MSG_CHECKING([for process-local memory allocator])
+AC_ARG_WITH(localmem,
+AS_HELP_STRING([--with-localmem=],[Select process-local 
memory allocator]),
+[
+   case "$withval" in
+   "" | y | ye | yes | n | no)
+   AC_MSG_ERROR([You must supply an argument to --with-localmem])
+ ;;
+   heapmem|tlsf)
+  localmem_allocator=$withval
+  ;;
+   *)
+   AC_MSG_ERROR([--localmem-allocator=])
+   esac
+])
+AC_MSG_RESULT($localmem_allocator)
+
 dnl Registry support in user-space (FUSE-based, default: off)
 
 use_registry=
@@ -610,12 +630,31 @@ AM_CONDITIONAL(CONFIG_XENO_SHARED,[test "$enable_shared" 
= 'yes'])
 # Default sampling period (ns) used in various tests
 
AC_DEFINE_UNQUOTED(CONFIG_XENO_DEFAULT_PERIOD,$CONFIG_XENO_DEFAULT_PERIOD,[config])
 
-dnl Allocator for Copperplate
-dnl Note: in dual kernel mode, we don't want malloc, no matter what.
-dnl We switch to malloc only over the Mercury core in debug mode, to ease
-dnl debugging with valgrind, instrumented glibc etc.
-AM_CONDITIONAL(XENO_TLSF,[test $rtcore_type = cobalt -o x$debug_mode = x])
-test $rtcore_type = cobalt -o x$debug_mode = x && 
AC_DEFINE(CONFIG_XENO_TLSF,1,[config])
+dnl Allocator for Copperplate. Note: in dual kernel mode, we don't
+dnl want malloc, no matter what: pick either heapmem or tlsf, defaults
+dnl to heapmem. Force switch to malloc over the Mercury core in debug
+dnl mode, to ease debugging with valgrind, instrumented glibc etc.
+
+if test $rtcore_type = cobalt -o x$debug_mode = x; then
+   case $localmem_allocator in
+   heapmem)
+   AC_DEFINE(CONFIG_XENO_HEAPMEM,1,[config])
+   use_heapmem=y
+   use_tlsf=
+   ;;
+   tlsf)
+   AC_DEFINE(CONFIG_XENO_TLSF,1,[config])
+   use_tlsf=y
+   use_heapmem=
+   ;;
+   esac
+else
+   use_heapmem=
+   use_tlsf=
+AC_MSG_WARN([using malloc() for private memory in debug mode])
+fi
+AM_CONDITIONAL(XENO_TLSF,[test x$use_tlsf = xy])
+AM_CONDITIONAL(XENO_HEAPMEM,[test x$use_heapmem = xy])
 
 dnl Check for atomic builtins. For now we only check for the legacy
 dnl interface, i.e. __sync_*.
diff --git a/include/copperplate/heapobj.h b/include/copperplate/heapobj.h
index dc2a45d..c8a7773 100644
--- a/include/copperplate/heapobj.h
+++ b/include/copperplate/heapobj.h
@@ -139,7 +139,71 @@ static inline char *pvstrdup(const char *ptr)
return strcpy(str, ptr);
 }
 
-#else /* !CONFIG_XENO_TLSF, i.e. malloc */
+#elif defined(CONFIG_XENO_HEAPMEM)
+
+#include 
+
+extern struct heap_memory heapmem_main;
+
+static inline
+void pvheapobj_destroy(struct heapobj *hobj)
+{
+   heapmem_destroy(hobj->pool);
+}
+
+static inline
+int pvheapobj_extend(struct heapobj *hobj, size_t size, void *mem)
+{
+   return heapmem_extend(hobj->pool, mem, size);
+}
+
+static inline
+void *pvheapobj_alloc(struct heapobj *hobj, size_t size)
+{
+   return heapmem_alloc(hobj->pool, size);
+}
+
+static inline
+void pvheapobj_free(struct heapobj *hobj, void *ptr)
+{
+   heapmem_free(hobj->pool, ptr);
+}
+
+static inline
+size_t pvheapobj_validate(struct heapobj *hobj, void *ptr)
+{
+   ssize_t size = heapmem_check(hobj->pool, ptr);
+   return size < 0 ? 0 : size;
+}
+
+static inline
+size_t pvheapobj_inquire(struct heapobj *hobj)
+{
+   return heapmem_used_size(hobj->pool);
+}
+
+static inline void *pvmalloc(size_t size)
+{
+   return heapmem_alloc(_main, size);
+}
+
+static inline void pvfree(void *ptr)
+{
+   heapmem_free(_main, ptr);
+}
+
+static inline char *pvstrdup(const char *ptr)
+{
+   char *str;
+
+   str = (char *)pvmalloc(strlen(ptr) + 1);
+   if (str == NULL)
+   return NULL;
+
+   return strcpy(str, ptr);
+}
+
+#else /* !CONFIG_XENO_HEAPMEM, i.e. malloc */
 
 #include 
 
@@ 

[Xenomai-git] Philippe Gerum : copperplate/heapobj: enable heapmem for private memory

2018-04-26 Thread git repository hosting
Module: xenomai-3
Branch: wip/heapmem
Commit: a36437ed07959f21cf7d63510a6bf8d53db54bbb
URL:
http://git.xenomai.org/?p=xenomai-3.git;a=commit;h=a36437ed07959f21cf7d63510a6bf8d53db54bbb

Author: Philippe Gerum 
Date:   Sun Apr 22 19:50:57 2018 +0200

copperplate/heapobj: enable heapmem for private memory

Make HEAPMEM the default private memory allocator for real-time
configurations (cobalt || (mercury && non-debug)).

This setting can be reverted by passing --with-localmem=tlsf.

---

 configure.ac  |   51 ++---
 include/copperplate/heapobj.h |   68 ++-
 lib/boilerplate/Makefile.am   |7 ++-
 lib/copperplate/Makefile.am   |4 ++
 lib/copperplate/heapobj-heapmem.c |   91 +
 5 files changed, 209 insertions(+), 12 deletions(-)

diff --git a/configure.ac b/configure.ac
index 61ebcbe..2caa4f3 100644
--- a/configure.ac
+++ b/configure.ac
@@ -327,6 +327,26 @@ if test x$use_pshared = xy; then
 fi
 AM_CONDITIONAL(XENO_PSHARED,[test x$use_pshared = xy])
 
+dnl Allocator selection
+
+localmem_allocator=heapmem
+AC_MSG_CHECKING([for process-local memory allocator])
+AC_ARG_WITH(localmem,
+AS_HELP_STRING([--with-localmem=],[Select process-local 
memory allocator]),
+[
+   case "$withval" in
+   "" | y | ye | yes | n | no)
+   AC_MSG_ERROR([You must supply an argument to --with-localmem])
+ ;;
+   heapmem|tlsf)
+  localmem_allocator=$withval
+  ;;
+   *)
+   AC_MSG_ERROR([--localmem-allocator=])
+   esac
+])
+AC_MSG_RESULT($localmem_allocator)
+
 dnl Registry support in user-space (FUSE-based, default: off)
 
 use_registry=
@@ -610,12 +630,31 @@ AM_CONDITIONAL(CONFIG_XENO_SHARED,[test "$enable_shared" 
= 'yes'])
 # Default sampling period (ns) used in various tests
 
AC_DEFINE_UNQUOTED(CONFIG_XENO_DEFAULT_PERIOD,$CONFIG_XENO_DEFAULT_PERIOD,[config])
 
-dnl Allocator for Copperplate
-dnl Note: in dual kernel mode, we don't want malloc, no matter what.
-dnl We switch to malloc only over the Mercury core in debug mode, to ease
-dnl debugging with valgrind, instrumented glibc etc.
-AM_CONDITIONAL(XENO_TLSF,[test $rtcore_type = cobalt -o x$debug_mode = x])
-test $rtcore_type = cobalt -o x$debug_mode = x && 
AC_DEFINE(CONFIG_XENO_TLSF,1,[config])
+dnl Allocator for Copperplate. Note: in dual kernel mode, we don't
+dnl want malloc, no matter what: pick either heapmem or tlsf, defaults
+dnl to heapmem. Force switch to malloc over the Mercury core in debug
+dnl mode, to ease debugging with valgrind, instrumented glibc etc.
+
+if test $rtcore_type = cobalt -o x$debug_mode = x; then
+   case $localmem_allocator in
+   heapmem)
+   AC_DEFINE(CONFIG_XENO_HEAPMEM,1,[config])
+   use_heapmem=y
+   use_tlsf=
+   ;;
+   tlsf)
+   AC_DEFINE(CONFIG_XENO_TLSF,1,[config])
+   use_tlsf=y
+   use_heapmem=
+   ;;
+   esac
+else
+   use_heapmem=
+   use_tlsf=
+AC_MSG_WARN([using malloc() for private memory in debug mode])
+fi
+AM_CONDITIONAL(XENO_TLSF,[test x$use_tlsf = xy])
+AM_CONDITIONAL(XENO_HEAPMEM,[test x$use_heapmem = xy])
 
 dnl Check for atomic builtins. For now we only check for the legacy
 dnl interface, i.e. __sync_*.
diff --git a/include/copperplate/heapobj.h b/include/copperplate/heapobj.h
index dc2a45d..c8a7773 100644
--- a/include/copperplate/heapobj.h
+++ b/include/copperplate/heapobj.h
@@ -139,7 +139,71 @@ static inline char *pvstrdup(const char *ptr)
return strcpy(str, ptr);
 }
 
-#else /* !CONFIG_XENO_TLSF, i.e. malloc */
+#elif defined(CONFIG_XENO_HEAPMEM)
+
+#include 
+
+extern struct heap_memory heapmem_main;
+
+static inline
+void pvheapobj_destroy(struct heapobj *hobj)
+{
+   heapmem_destroy(hobj->pool);
+}
+
+static inline
+int pvheapobj_extend(struct heapobj *hobj, size_t size, void *mem)
+{
+   return heapmem_extend(hobj->pool, mem, size);
+}
+
+static inline
+void *pvheapobj_alloc(struct heapobj *hobj, size_t size)
+{
+   return heapmem_alloc(hobj->pool, size);
+}
+
+static inline
+void pvheapobj_free(struct heapobj *hobj, void *ptr)
+{
+   heapmem_free(hobj->pool, ptr);
+}
+
+static inline
+size_t pvheapobj_validate(struct heapobj *hobj, void *ptr)
+{
+   ssize_t size = heapmem_check(hobj->pool, ptr);
+   return size < 0 ? 0 : size;
+}
+
+static inline
+size_t pvheapobj_inquire(struct heapobj *hobj)
+{
+   return heapmem_used_size(hobj->pool);
+}
+
+static inline void *pvmalloc(size_t size)
+{
+   return heapmem_alloc(_main, size);
+}
+
+static inline void pvfree(void *ptr)
+{
+   heapmem_free(_main, ptr);
+}
+
+static inline char *pvstrdup(const char *ptr)
+{
+   char *str;
+
+   str = (char *)pvmalloc(strlen(ptr) + 1);
+   if (str == NULL)
+   return NULL;
+
+   return strcpy(str, ptr);
+}
+
+#else /* !CONFIG_XENO_HEAPMEM, i.e. malloc */
 
 #include 
 
@@ 

[Xenomai-git] Philippe Gerum : copperplate/heapobj: enable heapmem for private memory

2018-04-26 Thread git repository hosting
Module: xenomai-3
Branch: wip/heapmem
Commit: 3471a0e2ed6f0407e393ad194bd27ba5236bcef8
URL:
http://git.xenomai.org/?p=xenomai-3.git;a=commit;h=3471a0e2ed6f0407e393ad194bd27ba5236bcef8

Author: Philippe Gerum 
Date:   Sun Apr 22 19:50:57 2018 +0200

copperplate/heapobj: enable heapmem for private memory

Make HEAPMEM the default private memory allocator for real-time
configurations (cobalt || (mercury && non-debug)).

This setting can be reverted by passing --with-localmem=tlsf.

---

 configure.ac  |   51 ++---
 include/copperplate/heapobj.h |   68 ++-
 lib/boilerplate/Makefile.am   |7 ++-
 lib/copperplate/Makefile.am   |4 ++
 lib/copperplate/heapobj-heapmem.c |   91 +
 5 files changed, 209 insertions(+), 12 deletions(-)

diff --git a/configure.ac b/configure.ac
index 61ebcbe..2caa4f3 100644
--- a/configure.ac
+++ b/configure.ac
@@ -327,6 +327,26 @@ if test x$use_pshared = xy; then
 fi
 AM_CONDITIONAL(XENO_PSHARED,[test x$use_pshared = xy])
 
+dnl Allocator selection
+
+localmem_allocator=heapmem
+AC_MSG_CHECKING([for process-local memory allocator])
+AC_ARG_WITH(localmem,
+AS_HELP_STRING([--with-localmem=],[Select process-local 
memory allocator]),
+[
+   case "$withval" in
+   "" | y | ye | yes | n | no)
+   AC_MSG_ERROR([You must supply an argument to --with-localmem])
+ ;;
+   heapmem|tlsf)
+  localmem_allocator=$withval
+  ;;
+   *)
+   AC_MSG_ERROR([--localmem-allocator=])
+   esac
+])
+AC_MSG_RESULT($localmem_allocator)
+
 dnl Registry support in user-space (FUSE-based, default: off)
 
 use_registry=
@@ -610,12 +630,31 @@ AM_CONDITIONAL(CONFIG_XENO_SHARED,[test "$enable_shared" 
= 'yes'])
 # Default sampling period (ns) used in various tests
 
AC_DEFINE_UNQUOTED(CONFIG_XENO_DEFAULT_PERIOD,$CONFIG_XENO_DEFAULT_PERIOD,[config])
 
-dnl Allocator for Copperplate
-dnl Note: in dual kernel mode, we don't want malloc, no matter what.
-dnl We switch to malloc only over the Mercury core in debug mode, to ease
-dnl debugging with valgrind, instrumented glibc etc.
-AM_CONDITIONAL(XENO_TLSF,[test $rtcore_type = cobalt -o x$debug_mode = x])
-test $rtcore_type = cobalt -o x$debug_mode = x && 
AC_DEFINE(CONFIG_XENO_TLSF,1,[config])
+dnl Allocator for Copperplate. Note: in dual kernel mode, we don't
+dnl want malloc, no matter what: pick either heapmem or tlsf, defaults
+dnl to heapmem. Force switch to malloc over the Mercury core in debug
+dnl mode, to ease debugging with valgrind, instrumented glibc etc.
+
+if test $rtcore_type = cobalt -o x$debug_mode = x; then
+   case $localmem_allocator in
+   heapmem)
+   AC_DEFINE(CONFIG_XENO_HEAPMEM,1,[config])
+   use_heapmem=y
+   use_tlsf=
+   ;;
+   tlsf)
+   AC_DEFINE(CONFIG_XENO_TLSF,1,[config])
+   use_tlsf=y
+   use_heapmem=
+   ;;
+   esac
+else
+   use_heapmem=
+   use_tlsf=
+AC_MSG_WARN([using malloc() for private memory in debug mode])
+fi
+AM_CONDITIONAL(XENO_TLSF,[test x$use_tlsf = xy])
+AM_CONDITIONAL(XENO_HEAPMEM,[test x$use_heapmem = xy])
 
 dnl Check for atomic builtins. For now we only check for the legacy
 dnl interface, i.e. __sync_*.
diff --git a/include/copperplate/heapobj.h b/include/copperplate/heapobj.h
index dc2a45d..c8a7773 100644
--- a/include/copperplate/heapobj.h
+++ b/include/copperplate/heapobj.h
@@ -139,7 +139,71 @@ static inline char *pvstrdup(const char *ptr)
return strcpy(str, ptr);
 }
 
-#else /* !CONFIG_XENO_TLSF, i.e. malloc */
+#elif defined(CONFIG_XENO_HEAPMEM)
+
+#include 
+
+extern struct heap_memory heapmem_main;
+
+static inline
+void pvheapobj_destroy(struct heapobj *hobj)
+{
+   heapmem_destroy(hobj->pool);
+}
+
+static inline
+int pvheapobj_extend(struct heapobj *hobj, size_t size, void *mem)
+{
+   return heapmem_extend(hobj->pool, mem, size);
+}
+
+static inline
+void *pvheapobj_alloc(struct heapobj *hobj, size_t size)
+{
+   return heapmem_alloc(hobj->pool, size);
+}
+
+static inline
+void pvheapobj_free(struct heapobj *hobj, void *ptr)
+{
+   heapmem_free(hobj->pool, ptr);
+}
+
+static inline
+size_t pvheapobj_validate(struct heapobj *hobj, void *ptr)
+{
+   ssize_t size = heapmem_check(hobj->pool, ptr);
+   return size < 0 ? 0 : size;
+}
+
+static inline
+size_t pvheapobj_inquire(struct heapobj *hobj)
+{
+   return heapmem_used_size(hobj->pool);
+}
+
+static inline void *pvmalloc(size_t size)
+{
+   return heapmem_alloc(_main, size);
+}
+
+static inline void pvfree(void *ptr)
+{
+   heapmem_free(_main, ptr);
+}
+
+static inline char *pvstrdup(const char *ptr)
+{
+   char *str;
+
+   str = (char *)pvmalloc(strlen(ptr) + 1);
+   if (str == NULL)
+   return NULL;
+
+   return strcpy(str, ptr);
+}
+
+#else /* !CONFIG_XENO_HEAPMEM, i.e. malloc */
 
 #include 
 
@@ 

[Xenomai-git] Philippe Gerum : copperplate/heapobj: enable heapmem for private memory

2018-04-25 Thread git repository hosting
Module: xenomai-3
Branch: wip/heapmem
Commit: d516ee9ef8661d9dc65372ecfff0c6a2415ce323
URL:
http://git.xenomai.org/?p=xenomai-3.git;a=commit;h=d516ee9ef8661d9dc65372ecfff0c6a2415ce323

Author: Philippe Gerum 
Date:   Sun Apr 22 19:50:57 2018 +0200

copperplate/heapobj: enable heapmem for private memory

Make HEAPMEM the default private memory allocator for real-time
configurations (cobalt || (mercury && non-debug)).

This setting can be reverted by passing --with-localmem=tlsf.

---

 configure.ac  |   51 ++---
 include/copperplate/heapobj.h |   68 ++-
 lib/boilerplate/Makefile.am   |7 ++-
 lib/copperplate/Makefile.am   |4 ++
 lib/copperplate/heapobj-heapmem.c |   91 +
 5 files changed, 209 insertions(+), 12 deletions(-)

diff --git a/configure.ac b/configure.ac
index 61ebcbe..2caa4f3 100644
--- a/configure.ac
+++ b/configure.ac
@@ -327,6 +327,26 @@ if test x$use_pshared = xy; then
 fi
 AM_CONDITIONAL(XENO_PSHARED,[test x$use_pshared = xy])
 
+dnl Allocator selection
+
+localmem_allocator=heapmem
+AC_MSG_CHECKING([for process-local memory allocator])
+AC_ARG_WITH(localmem,
+AS_HELP_STRING([--with-localmem=],[Select process-local 
memory allocator]),
+[
+   case "$withval" in
+   "" | y | ye | yes | n | no)
+   AC_MSG_ERROR([You must supply an argument to --with-localmem])
+ ;;
+   heapmem|tlsf)
+  localmem_allocator=$withval
+  ;;
+   *)
+   AC_MSG_ERROR([--localmem-allocator=])
+   esac
+])
+AC_MSG_RESULT($localmem_allocator)
+
 dnl Registry support in user-space (FUSE-based, default: off)
 
 use_registry=
@@ -610,12 +630,31 @@ AM_CONDITIONAL(CONFIG_XENO_SHARED,[test "$enable_shared" 
= 'yes'])
 # Default sampling period (ns) used in various tests
 
AC_DEFINE_UNQUOTED(CONFIG_XENO_DEFAULT_PERIOD,$CONFIG_XENO_DEFAULT_PERIOD,[config])
 
-dnl Allocator for Copperplate
-dnl Note: in dual kernel mode, we don't want malloc, no matter what.
-dnl We switch to malloc only over the Mercury core in debug mode, to ease
-dnl debugging with valgrind, instrumented glibc etc.
-AM_CONDITIONAL(XENO_TLSF,[test $rtcore_type = cobalt -o x$debug_mode = x])
-test $rtcore_type = cobalt -o x$debug_mode = x && 
AC_DEFINE(CONFIG_XENO_TLSF,1,[config])
+dnl Allocator for Copperplate. Note: in dual kernel mode, we don't
+dnl want malloc, no matter what: pick either heapmem or tlsf, defaults
+dnl to heapmem. Force switch to malloc over the Mercury core in debug
+dnl mode, to ease debugging with valgrind, instrumented glibc etc.
+
+if test $rtcore_type = cobalt -o x$debug_mode = x; then
+   case $localmem_allocator in
+   heapmem)
+   AC_DEFINE(CONFIG_XENO_HEAPMEM,1,[config])
+   use_heapmem=y
+   use_tlsf=
+   ;;
+   tlsf)
+   AC_DEFINE(CONFIG_XENO_TLSF,1,[config])
+   use_tlsf=y
+   use_heapmem=
+   ;;
+   esac
+else
+   use_heapmem=
+   use_tlsf=
+AC_MSG_WARN([using malloc() for private memory in debug mode])
+fi
+AM_CONDITIONAL(XENO_TLSF,[test x$use_tlsf = xy])
+AM_CONDITIONAL(XENO_HEAPMEM,[test x$use_heapmem = xy])
 
 dnl Check for atomic builtins. For now we only check for the legacy
 dnl interface, i.e. __sync_*.
diff --git a/include/copperplate/heapobj.h b/include/copperplate/heapobj.h
index dc2a45d..c8a7773 100644
--- a/include/copperplate/heapobj.h
+++ b/include/copperplate/heapobj.h
@@ -139,7 +139,71 @@ static inline char *pvstrdup(const char *ptr)
return strcpy(str, ptr);
 }
 
-#else /* !CONFIG_XENO_TLSF, i.e. malloc */
+#elif defined(CONFIG_XENO_HEAPMEM)
+
+#include 
+
+extern struct heap_memory heapmem_main;
+
+static inline
+void pvheapobj_destroy(struct heapobj *hobj)
+{
+   heapmem_destroy(hobj->pool);
+}
+
+static inline
+int pvheapobj_extend(struct heapobj *hobj, size_t size, void *mem)
+{
+   return heapmem_extend(hobj->pool, mem, size);
+}
+
+static inline
+void *pvheapobj_alloc(struct heapobj *hobj, size_t size)
+{
+   return heapmem_alloc(hobj->pool, size);
+}
+
+static inline
+void pvheapobj_free(struct heapobj *hobj, void *ptr)
+{
+   heapmem_free(hobj->pool, ptr);
+}
+
+static inline
+size_t pvheapobj_validate(struct heapobj *hobj, void *ptr)
+{
+   ssize_t size = heapmem_check(hobj->pool, ptr);
+   return size < 0 ? 0 : size;
+}
+
+static inline
+size_t pvheapobj_inquire(struct heapobj *hobj)
+{
+   return heapmem_used_size(hobj->pool);
+}
+
+static inline void *pvmalloc(size_t size)
+{
+   return heapmem_alloc(_main, size);
+}
+
+static inline void pvfree(void *ptr)
+{
+   heapmem_free(_main, ptr);
+}
+
+static inline char *pvstrdup(const char *ptr)
+{
+   char *str;
+
+   str = (char *)pvmalloc(strlen(ptr) + 1);
+   if (str == NULL)
+   return NULL;
+
+   return strcpy(str, ptr);
+}
+
+#else /* !CONFIG_XENO_HEAPMEM, i.e. malloc */
 
 #include 
 
@@ 

[Xenomai-git] Philippe Gerum : copperplate/heapobj: enable heapmem for private memory

2018-04-24 Thread git repository hosting
Module: xenomai-3
Branch: wip/heapmem
Commit: 02de3d7eb1f1008afe67fdaeb92511e51ba5c41f
URL:
http://git.xenomai.org/?p=xenomai-3.git;a=commit;h=02de3d7eb1f1008afe67fdaeb92511e51ba5c41f

Author: Philippe Gerum 
Date:   Sun Apr 22 19:50:57 2018 +0200

copperplate/heapobj: enable heapmem for private memory

Make HEAPMEM the default private memory allocator for real-time
configurations (cobalt || (mercury && non-debug)).

This setting can be reverted by passing --with-localmem=tlsf.

---

 configure.ac  |   51 ++---
 include/copperplate/heapobj.h |   68 ++-
 lib/boilerplate/Makefile.am   |7 ++-
 lib/copperplate/Makefile.am   |4 ++
 lib/copperplate/heapobj-heapmem.c |   91 +
 5 files changed, 209 insertions(+), 12 deletions(-)

diff --git a/configure.ac b/configure.ac
index 61ebcbe..2caa4f3 100644
--- a/configure.ac
+++ b/configure.ac
@@ -327,6 +327,26 @@ if test x$use_pshared = xy; then
 fi
 AM_CONDITIONAL(XENO_PSHARED,[test x$use_pshared = xy])
 
+dnl Allocator selection
+
+localmem_allocator=heapmem
+AC_MSG_CHECKING([for process-local memory allocator])
+AC_ARG_WITH(localmem,
+AS_HELP_STRING([--with-localmem=],[Select process-local 
memory allocator]),
+[
+   case "$withval" in
+   "" | y | ye | yes | n | no)
+   AC_MSG_ERROR([You must supply an argument to --with-localmem])
+ ;;
+   heapmem|tlsf)
+  localmem_allocator=$withval
+  ;;
+   *)
+   AC_MSG_ERROR([--localmem-allocator=])
+   esac
+])
+AC_MSG_RESULT($localmem_allocator)
+
 dnl Registry support in user-space (FUSE-based, default: off)
 
 use_registry=
@@ -610,12 +630,31 @@ AM_CONDITIONAL(CONFIG_XENO_SHARED,[test "$enable_shared" 
= 'yes'])
 # Default sampling period (ns) used in various tests
 
AC_DEFINE_UNQUOTED(CONFIG_XENO_DEFAULT_PERIOD,$CONFIG_XENO_DEFAULT_PERIOD,[config])
 
-dnl Allocator for Copperplate
-dnl Note: in dual kernel mode, we don't want malloc, no matter what.
-dnl We switch to malloc only over the Mercury core in debug mode, to ease
-dnl debugging with valgrind, instrumented glibc etc.
-AM_CONDITIONAL(XENO_TLSF,[test $rtcore_type = cobalt -o x$debug_mode = x])
-test $rtcore_type = cobalt -o x$debug_mode = x && 
AC_DEFINE(CONFIG_XENO_TLSF,1,[config])
+dnl Allocator for Copperplate. Note: in dual kernel mode, we don't
+dnl want malloc, no matter what: pick either heapmem or tlsf, defaults
+dnl to heapmem. Force switch to malloc over the Mercury core in debug
+dnl mode, to ease debugging with valgrind, instrumented glibc etc.
+
+if test $rtcore_type = cobalt -o x$debug_mode = x; then
+   case $localmem_allocator in
+   heapmem)
+   AC_DEFINE(CONFIG_XENO_HEAPMEM,1,[config])
+   use_heapmem=y
+   use_tlsf=
+   ;;
+   tlsf)
+   AC_DEFINE(CONFIG_XENO_TLSF,1,[config])
+   use_tlsf=y
+   use_heapmem=
+   ;;
+   esac
+else
+   use_heapmem=
+   use_tlsf=
+AC_MSG_WARN([using malloc() for private memory in debug mode])
+fi
+AM_CONDITIONAL(XENO_TLSF,[test x$use_tlsf = xy])
+AM_CONDITIONAL(XENO_HEAPMEM,[test x$use_heapmem = xy])
 
 dnl Check for atomic builtins. For now we only check for the legacy
 dnl interface, i.e. __sync_*.
diff --git a/include/copperplate/heapobj.h b/include/copperplate/heapobj.h
index dc2a45d..c8a7773 100644
--- a/include/copperplate/heapobj.h
+++ b/include/copperplate/heapobj.h
@@ -139,7 +139,71 @@ static inline char *pvstrdup(const char *ptr)
return strcpy(str, ptr);
 }
 
-#else /* !CONFIG_XENO_TLSF, i.e. malloc */
+#elif defined(CONFIG_XENO_HEAPMEM)
+
+#include 
+
+extern struct heap_memory heapmem_main;
+
+static inline
+void pvheapobj_destroy(struct heapobj *hobj)
+{
+   heapmem_destroy(hobj->pool);
+}
+
+static inline
+int pvheapobj_extend(struct heapobj *hobj, size_t size, void *mem)
+{
+   return heapmem_extend(hobj->pool, mem, size);
+}
+
+static inline
+void *pvheapobj_alloc(struct heapobj *hobj, size_t size)
+{
+   return heapmem_alloc(hobj->pool, size);
+}
+
+static inline
+void pvheapobj_free(struct heapobj *hobj, void *ptr)
+{
+   heapmem_free(hobj->pool, ptr);
+}
+
+static inline
+size_t pvheapobj_validate(struct heapobj *hobj, void *ptr)
+{
+   ssize_t size = heapmem_check(hobj->pool, ptr);
+   return size < 0 ? 0 : size;
+}
+
+static inline
+size_t pvheapobj_inquire(struct heapobj *hobj)
+{
+   return heapmem_used_size(hobj->pool);
+}
+
+static inline void *pvmalloc(size_t size)
+{
+   return heapmem_alloc(_main, size);
+}
+
+static inline void pvfree(void *ptr)
+{
+   heapmem_free(_main, ptr);
+}
+
+static inline char *pvstrdup(const char *ptr)
+{
+   char *str;
+
+   str = (char *)pvmalloc(strlen(ptr) + 1);
+   if (str == NULL)
+   return NULL;
+
+   return strcpy(str, ptr);
+}
+
+#else /* !CONFIG_XENO_HEAPMEM, i.e. malloc */
 
 #include 
 
@@