From 4fe93881b071ea664b9a5b89c073ad46b9d3e312 Mon Sep 17 00:00:00 2001 From: Meco Man <920369182@qq.com> Date: Sat, 13 Nov 2021 16:22:09 -0500 Subject: [PATCH] =?UTF-8?q?[dlib][armlibc]=20=E5=86=85=E5=AD=98=E5=87=BD?= =?UTF-8?q?=E6=95=B0=E5=9C=A8HEAP=E6=B2=A1=E6=9C=89=E5=BC=80=E5=90=AF?= =?UTF-8?q?=E6=97=B6=E5=A2=9E=E5=8A=A0=E9=94=99=E8=AF=AF=E8=AD=A6=E5=91=8A?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- components/libc/compilers/armlibc/mem_std.c | 36 ++++++++++++++++-- components/libc/compilers/armlibc/syscalls.c | 2 +- components/libc/compilers/dlib/syscall_mem.c | 38 ++++++++++++++++--- .../libc/compilers/dlib/syscall_write.c | 2 +- 4 files changed, 67 insertions(+), 11 deletions(-) diff --git a/components/libc/compilers/armlibc/mem_std.c b/components/libc/compilers/armlibc/mem_std.c index fbfd17eee1..f8a81c7873 100644 --- a/components/libc/compilers/armlibc/mem_std.c +++ b/components/libc/compilers/armlibc/mem_std.c @@ -4,40 +4,68 @@ * SPDX-License-Identifier: Apache-2.0 * * 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 #include -#ifdef RT_USING_HEAP +#ifndef RT_USING_HEAP +#define DBG_TAG "armlibc.mem" +#define DBG_LVL DBG_INFO +#include + +#define _NO_HEAP_ERROR() do{LOG_E("Please enable RT_USING_HEAP");\ + RT_ASSERT(0);\ + }while(0) +#endif /* RT_USING_HEAP */ #ifdef __CC_ARM /* avoid the heap and heap-using library functions supplied by arm */ #pragma import(__use_no_heap) -#endif +#endif /* __CC_ARM */ void *malloc(size_t n) { +#ifdef RT_USING_HEAP return rt_malloc(n); +#else + _NO_HEAP_ERROR(); + return RT_NULL; +#endif } RTM_EXPORT(malloc); void *realloc(void *rmem, size_t newsize) { +#ifdef RT_USING_HEAP return rt_realloc(rmem, newsize); +#else + _NO_HEAP_ERROR(); + return RT_NULL; +#endif } RTM_EXPORT(realloc); void *calloc(size_t nelem, size_t elsize) { +#ifdef RT_USING_HEAP return rt_calloc(nelem, elsize); +#else + _NO_HEAP_ERROR(); + return RT_NULL; +#endif } RTM_EXPORT(calloc); void free(void *rmem) { +#ifdef RT_USING_HEAP rt_free(rmem); +#else + _NO_HEAP_ERROR(); +#endif } RTM_EXPORT(free); -#endif diff --git a/components/libc/compilers/armlibc/syscalls.c b/components/libc/compilers/armlibc/syscalls.c index c8609a92f3..b6448f2165 100644 --- a/components/libc/compilers/armlibc/syscalls.c +++ b/components/libc/compilers/armlibc/syscalls.c @@ -25,7 +25,7 @@ #include "libc.h" #endif -#define DBG_TAG "Keil.armlibc.syscalls" +#define DBG_TAG "armlibc.syscalls" #define DBG_LVL DBG_INFO #include diff --git a/components/libc/compilers/dlib/syscall_mem.c b/components/libc/compilers/dlib/syscall_mem.c index 9c6de64455..74b960f0b9 100644 --- a/components/libc/compilers/dlib/syscall_mem.c +++ b/components/libc/compilers/dlib/syscall_mem.c @@ -6,27 +6,55 @@ * Change Logs: * Date Author Notes * 2015-01-28 Bernard first version + * 2021-11-13 Meco Man implement no-heap warning */ #include +#include -#ifdef RT_USING_HEAP -void *malloc(rt_size_t n) +#ifndef RT_USING_HEAP +#define DBG_TAG "dlib.syscall_mem" +#define DBG_LVL DBG_INFO +#include +#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); +#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); +#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); +#else + _NO_HEAP_ERROR(); + return RT_NULL; +#endif } void free(void *rmem) { +#ifdef RT_USING_HEAP rt_free(rmem); -} +#else + _NO_HEAP_ERROR(); #endif +} diff --git a/components/libc/compilers/dlib/syscall_write.c b/components/libc/compilers/dlib/syscall_write.c index c0729afd69..9a7707e9d3 100644 --- a/components/libc/compilers/dlib/syscall_write.c +++ b/components/libc/compilers/dlib/syscall_write.c @@ -15,7 +15,7 @@ #include "libc.h" #endif -#define DBG_TAG "IAR.dlib.syscall_write" +#define DBG_TAG "dlib.syscall_write" #define DBG_LVL DBG_INFO #include -- GitLab