Skip to content

Commit ce76e18

Browse files
authored
Merge pull request #4398 from mysterywolf/syscallssss
[libc][newlib] 对syscall中malloc相关桩函数做出预编译调整
2 parents 893e5ad + 70f5c10 commit ce76e18

File tree

2 files changed

+61
-10
lines changed

2 files changed

+61
-10
lines changed

components/libc/compilers/newlib/minilib.c

Lines changed: 52 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,58 @@
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
{
16-
/* no use this routine to get memory */
1766
return RT_NULL;
1867
}
68+
#endif /*RT_USING_HEAP*/

components/libc/compilers/newlib/syscalls.c

Lines changed: 9 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,14 @@ _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+
return RT_NULL;
307+
}
308+
#endif /*RT_USING_HEAP*/
309+
309310
/* for exit() and abort() */
310311
__attribute__ ((noreturn)) void
311312
_exit (int status)

0 commit comments

Comments
 (0)