提交 4fe93881 编写于 作者: mysterywolf's avatar mysterywolf

[dlib][armlibc] 内存函数在HEAP没有开启时增加错误警告

上级 9254d1a3
...@@ -4,40 +4,68 @@ ...@@ -4,40 +4,68 @@
* SPDX-License-Identifier: Apache-2.0 * SPDX-License-Identifier: Apache-2.0
* *
* Change Logs: * Change Logs:
* 2014-08-03 bernard Add file header. * Date Author Notes
* 2014-08-03 bernard Add file header
* 2021-11-13 Meco Man implement no-heap warning
*/ */
#include <rtthread.h> #include <rtthread.h>
#include <stddef.h> #include <stddef.h>
#ifdef RT_USING_HEAP #ifndef RT_USING_HEAP
#define DBG_TAG "armlibc.mem"
#define DBG_LVL DBG_INFO
#include <rtdbg.h>
#define _NO_HEAP_ERROR() do{LOG_E("Please enable RT_USING_HEAP");\
RT_ASSERT(0);\
}while(0)
#endif /* RT_USING_HEAP */
#ifdef __CC_ARM #ifdef __CC_ARM
/* avoid the heap and heap-using library functions supplied by arm */ /* avoid the heap and heap-using library functions supplied by arm */
#pragma import(__use_no_heap) #pragma import(__use_no_heap)
#endif #endif /* __CC_ARM */
void *malloc(size_t n) void *malloc(size_t n)
{ {
#ifdef RT_USING_HEAP
return rt_malloc(n); return rt_malloc(n);
#else
_NO_HEAP_ERROR();
return RT_NULL;
#endif
} }
RTM_EXPORT(malloc); RTM_EXPORT(malloc);
void *realloc(void *rmem, size_t newsize) void *realloc(void *rmem, size_t newsize)
{ {
#ifdef RT_USING_HEAP
return rt_realloc(rmem, newsize); return rt_realloc(rmem, newsize);
#else
_NO_HEAP_ERROR();
return RT_NULL;
#endif
} }
RTM_EXPORT(realloc); RTM_EXPORT(realloc);
void *calloc(size_t nelem, size_t elsize) void *calloc(size_t nelem, size_t elsize)
{ {
#ifdef RT_USING_HEAP
return rt_calloc(nelem, elsize); return rt_calloc(nelem, elsize);
#else
_NO_HEAP_ERROR();
return RT_NULL;
#endif
} }
RTM_EXPORT(calloc); RTM_EXPORT(calloc);
void free(void *rmem) void free(void *rmem)
{ {
#ifdef RT_USING_HEAP
rt_free(rmem); rt_free(rmem);
#else
_NO_HEAP_ERROR();
#endif
} }
RTM_EXPORT(free); RTM_EXPORT(free);
#endif
...@@ -25,7 +25,7 @@ ...@@ -25,7 +25,7 @@
#include "libc.h" #include "libc.h"
#endif #endif
#define DBG_TAG "Keil.armlibc.syscalls" #define DBG_TAG "armlibc.syscalls"
#define DBG_LVL DBG_INFO #define DBG_LVL DBG_INFO
#include <rtdbg.h> #include <rtdbg.h>
......
...@@ -6,27 +6,55 @@ ...@@ -6,27 +6,55 @@
* Change Logs: * Change Logs:
* Date Author Notes * Date Author Notes
* 2015-01-28 Bernard first version * 2015-01-28 Bernard first version
* 2021-11-13 Meco Man implement no-heap warning
*/ */
#include <rtthread.h> #include <rtthread.h>
#include <stddef.h>
#ifdef RT_USING_HEAP #ifndef RT_USING_HEAP
void *malloc(rt_size_t n) #define DBG_TAG "dlib.syscall_mem"
#define DBG_LVL DBG_INFO
#include <rtdbg.h>
#define _NO_HEAP_ERROR() do{LOG_E("Please enable RT_USING_HEAP");\
RT_ASSERT(0);\
}while(0)
#endif /* RT_USING_HEAP */
void *malloc(size_t n)
{ {
#ifdef RT_USING_HEAP
return rt_malloc(n); return rt_malloc(n);
#else
_NO_HEAP_ERROR();
return RT_NULL;
#endif
} }
void *realloc(void *rmem, rt_size_t newsize) void *realloc(void *rmem, size_t newsize)
{ {
#ifdef RT_USING_HEAP
return rt_realloc(rmem, newsize); return rt_realloc(rmem, newsize);
#else
_NO_HEAP_ERROR();
return RT_NULL;
#endif
} }
void *calloc(rt_size_t nelem, rt_size_t elsize) void *calloc(size_t nelem, size_t elsize)
{ {
#ifdef RT_USING_HEAP
return rt_calloc(nelem, elsize); return rt_calloc(nelem, elsize);
#else
_NO_HEAP_ERROR();
return RT_NULL;
#endif
} }
void free(void *rmem) void free(void *rmem)
{ {
#ifdef RT_USING_HEAP
rt_free(rmem); rt_free(rmem);
} #else
_NO_HEAP_ERROR();
#endif #endif
}
...@@ -15,7 +15,7 @@ ...@@ -15,7 +15,7 @@
#include "libc.h" #include "libc.h"
#endif #endif
#define DBG_TAG "IAR.dlib.syscall_write" #define DBG_TAG "dlib.syscall_write"
#define DBG_LVL DBG_INFO #define DBG_LVL DBG_INFO
#include <rtdbg.h> #include <rtdbg.h>
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册