BugID:16846667: support app malloc
modified:   libc/newlib_stub.c
#include "lwip/apps/telnetserver.h"
#endif
+#ifdef AOS_APP_MM
+#include <app_mm.h>
+#endif
+
#define FD_VFS_START AOS_CONFIG_VFS_FD_OFFSET
#define FD_VFS_END (FD_VFS_START + MAX_FILE_NUM - 1)
@@ -248,11 +252,15 @@ void *_malloc_r(struct _reent *ptr, size_t size)
{
void *mem;
+#ifdef AOS_APP_MM
+ mem = app_mm_malloc(size);
+#else
#if (RHINO_CONFIG_MM_DEBUG > 0u && RHINO_CONFIG_GCC_RETADDR > 0u)
mem = aos_malloc(size | AOS_UNSIGNED_INT_MSB);
aos_alloc_trace(mem, (size_t)__builtin_return_address(0));
#else
mem = aos_malloc(size);
+#endif
#endif
return mem;
@@ -262,11 +270,15 @@ void *_realloc_r(struct _reent *ptr, void *old, size_t newlen)
{
void *mem;
+#ifdef AOS_APP_MM
+ mem = app_mm_realloc(old, newlen);
+#else
#if (RHINO_CONFIG_MM_DEBUG > 0u && RHINO_CONFIG_GCC_RETADDR > 0u)
mem = aos_realloc(old, newlen | AOS_UNSIGNED_INT_MSB);
aos_alloc_trace(mem, (size_t)__builtin_return_address(0));
#else
mem = aos_realloc(old, newlen);
+#endif
#endif
return mem;
@@ -276,11 +288,15 @@ void *_calloc_r(struct _reent *ptr, size_t size, size_t len)
{
void *mem;
+#ifdef AOS_APP_MM
+ mem = app_mm_malloc(size * len);
+#else
#if (RHINO_CONFIG_MM_DEBUG > 0u && RHINO_CONFIG_GCC_RETADDR > 0u)
mem = aos_malloc((size * len) | AOS_UNSIGNED_INT_MSB);
aos_alloc_trace(mem, (size_t)__builtin_return_address(0));
#else
mem = aos_malloc(size * len);
+#endif
#endif
if (mem) {
@@ -292,7 +308,11 @@ void *_calloc_r(struct _reent *ptr, size_t size, size_t len)
void _free_r(struct _reent *ptr, void *addr)
{
+#ifdef AOS_APP_MM
+ app_mm_free(addr);
+#else
aos_free(addr);
+#endif
}
void _exit(int status)
