Skip to content

Commit 4fe9388

Browse files
committed
[dlib][armlibc] 内存函数在HEAP没有开启时增加错误警告
1 parent 9254d1a commit 4fe9388

File tree

4 files changed

+67
-11
lines changed

4 files changed

+67
-11
lines changed

components/libc/compilers/armlibc/mem_std.c

Lines changed: 32 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,40 +4,68 @@
44
* SPDX-License-Identifier: Apache-2.0
55
*
66
* Change Logs:
7-
* 2014-08-03 bernard Add file header.
7+
* Date Author Notes
8+
* 2014-08-03 bernard Add file header
9+
* 2021-11-13 Meco Man implement no-heap warning
810
*/
911

1012
#include <rtthread.h>
1113
#include <stddef.h>
1214

13-
#ifdef RT_USING_HEAP
15+
#ifndef RT_USING_HEAP
16+
#define DBG_TAG "armlibc.mem"
17+
#define DBG_LVL DBG_INFO
18+
#include <rtdbg.h>
19+
20+
#define _NO_HEAP_ERROR() do{LOG_E("Please enable RT_USING_HEAP");\
21+
RT_ASSERT(0);\
22+
}while(0)
23+
#endif /* RT_USING_HEAP */
1424

1525
#ifdef __CC_ARM
1626
/* avoid the heap and heap-using library functions supplied by arm */
1727
#pragma import(__use_no_heap)
18-
#endif
28+
#endif /* __CC_ARM */
1929

2030
void *malloc(size_t n)
2131
{
32+
#ifdef RT_USING_HEAP
2233
return rt_malloc(n);
34+
#else
35+
_NO_HEAP_ERROR();
36+
return RT_NULL;
37+
#endif
2338
}
2439
RTM_EXPORT(malloc);
2540

2641
void *realloc(void *rmem, size_t newsize)
2742
{
43+
#ifdef RT_USING_HEAP
2844
return rt_realloc(rmem, newsize);
45+
#else
46+
_NO_HEAP_ERROR();
47+
return RT_NULL;
48+
#endif
2949
}
3050
RTM_EXPORT(realloc);
3151

3252
void *calloc(size_t nelem, size_t elsize)
3353
{
54+
#ifdef RT_USING_HEAP
3455
return rt_calloc(nelem, elsize);
56+
#else
57+
_NO_HEAP_ERROR();
58+
return RT_NULL;
59+
#endif
3560
}
3661
RTM_EXPORT(calloc);
3762

3863
void free(void *rmem)
3964
{
65+
#ifdef RT_USING_HEAP
4066
rt_free(rmem);
67+
#else
68+
_NO_HEAP_ERROR();
69+
#endif
4170
}
4271
RTM_EXPORT(free);
43-
#endif

components/libc/compilers/armlibc/syscalls.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525
#include "libc.h"
2626
#endif
2727

28-
#define DBG_TAG "Keil.armlibc.syscalls"
28+
#define DBG_TAG "armlibc.syscalls"
2929
#define DBG_LVL DBG_INFO
3030
#include <rtdbg.h>
3131

components/libc/compilers/dlib/syscall_mem.c

Lines changed: 33 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,27 +6,55 @@
66
* Change Logs:
77
* Date Author Notes
88
* 2015-01-28 Bernard first version
9+
* 2021-11-13 Meco Man implement no-heap warning
910
*/
1011
#include <rtthread.h>
12+
#include <stddef.h>
1113

12-
#ifdef RT_USING_HEAP
13-
void *malloc(rt_size_t n)
14+
#ifndef RT_USING_HEAP
15+
#define DBG_TAG "dlib.syscall_mem"
16+
#define DBG_LVL DBG_INFO
17+
#include <rtdbg.h>
18+
#define _NO_HEAP_ERROR() do{LOG_E("Please enable RT_USING_HEAP");\
19+
RT_ASSERT(0);\
20+
}while(0)
21+
#endif /* RT_USING_HEAP */
22+
23+
void *malloc(size_t n)
1424
{
25+
#ifdef RT_USING_HEAP
1526
return rt_malloc(n);
27+
#else
28+
_NO_HEAP_ERROR();
29+
return RT_NULL;
30+
#endif
1631
}
1732

18-
void *realloc(void *rmem, rt_size_t newsize)
33+
void *realloc(void *rmem, size_t newsize)
1934
{
35+
#ifdef RT_USING_HEAP
2036
return rt_realloc(rmem, newsize);
37+
#else
38+
_NO_HEAP_ERROR();
39+
return RT_NULL;
40+
#endif
2141
}
2242

23-
void *calloc(rt_size_t nelem, rt_size_t elsize)
43+
void *calloc(size_t nelem, size_t elsize)
2444
{
45+
#ifdef RT_USING_HEAP
2546
return rt_calloc(nelem, elsize);
47+
#else
48+
_NO_HEAP_ERROR();
49+
return RT_NULL;
50+
#endif
2651
}
2752

2853
void free(void *rmem)
2954
{
55+
#ifdef RT_USING_HEAP
3056
rt_free(rmem);
31-
}
57+
#else
58+
_NO_HEAP_ERROR();
3259
#endif
60+
}

components/libc/compilers/dlib/syscall_write.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
#include "libc.h"
1616
#endif
1717

18-
#define DBG_TAG "IAR.dlib.syscall_write"
18+
#define DBG_TAG "dlib.syscall_write"
1919
#define DBG_LVL DBG_INFO
2020
#include <rtdbg.h>
2121

0 commit comments

Comments
 (0)