Skip to content

Commit ac27596

Browse files
committed
[libc][newlib] 对syscall中malloc相关桩函数做出编译调整
1 parent 8932ffd commit ac27596

File tree

2 files changed

+62
-9
lines changed

2 files changed

+62
-9
lines changed

components/libc/compilers/newlib/minilib.c

Lines changed: 52 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,59 @@
1111
#include <reent.h>
1212
#include <rtthread.h>
1313

14-
void * _sbrk_r(struct _reent *ptr, ptrdiff_t incr)
14+
#ifdef RT_USING_HEAP /* Memory routine */
15+
void *
16+
_malloc_r (struct _reent *ptr, size_t size)
17+
{
18+
void* result;
19+
20+
result = (void*)rt_malloc (size);
21+
if (result == RT_NULL)
22+
{
23+
ptr->_errno = ENOMEM;
24+
}
25+
26+
return result;
27+
}
28+
29+
void *
30+
_realloc_r (struct _reent *ptr, void *old, size_t newlen)
31+
{
32+
void* result;
33+
34+
result = (void*)rt_realloc (old, newlen);
35+
if (result == RT_NULL)
36+
{
37+
ptr->_errno = ENOMEM;
38+
}
39+
40+
return result;
41+
}
42+
43+
void *_calloc_r (struct _reent *ptr, size_t size, size_t len)
44+
{
45+
void* result;
46+
47+
result = (void*)rt_calloc (size, len);
48+
if (result == RT_NULL)
49+
{
50+
ptr->_errno = ENOMEM;
51+
}
52+
53+
return result;
54+
}
55+
56+
void
57+
_free_r (struct _reent *ptr, void *addr)
58+
{
59+
rt_free (addr);
60+
}
61+
62+
#else
63+
void *
64+
_sbrk_r(struct _reent *ptr, ptrdiff_t incr)
1565
{
1666
/* no use this routine to get memory */
1767
return RT_NULL;
1868
}
69+
#endif /*RT_USING_HEAP*/

components/libc/compilers/newlib/syscalls.c

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -189,13 +189,6 @@ _rename_r(struct _reent *ptr, const char *old, const char *new)
189189
#endif
190190
}
191191

192-
void *
193-
_sbrk_r(struct _reent *ptr, ptrdiff_t incr)
194-
{
195-
/* no use this routine to get memory */
196-
return RT_NULL;
197-
}
198-
199192
int
200193
_stat_r(struct _reent *ptr, const char *file, struct stat *pstat)
201194
{
@@ -258,7 +251,7 @@ _write_r(struct _reent *ptr, int fd, const void *buf, size_t nbytes)
258251
#endif
259252
}
260253

261-
/* Memory routine */
254+
#ifdef RT_USING_HEAP /* Memory routine */
262255
void *
263256
_malloc_r (struct _reent *ptr, size_t size)
264257
{
@@ -306,6 +299,15 @@ _free_r (struct _reent *ptr, void *addr)
306299
rt_free (addr);
307300
}
308301

302+
#else
303+
void *
304+
_sbrk_r(struct _reent *ptr, ptrdiff_t incr)
305+
{
306+
/* no use this routine to get memory */
307+
return RT_NULL;
308+
}
309+
#endif /*RT_USING_HEAP*/
310+
309311
/* for exit() and abort() */
310312
__attribute__ ((noreturn)) void
311313
_exit (int status)

0 commit comments

Comments
 (0)