Merge pull request #4398 from mysterywolf/syscallssss

[libc][newlib] 对syscall中malloc相关桩函数做出预编译调整
This commit is contained in:
Bernard Xiong 2021-03-01 15:15:09 +08:00 committed by GitHub
commit ce76e18620
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 61 additions and 10 deletions

View File

@ -11,8 +11,58 @@
#include <reent.h> #include <reent.h>
#include <rtthread.h> #include <rtthread.h>
void * _sbrk_r(struct _reent *ptr, ptrdiff_t incr) #ifdef RT_USING_HEAP /* Memory routine */
void *
_malloc_r (struct _reent *ptr, size_t size)
{
void* result;
result = (void*)rt_malloc (size);
if (result == RT_NULL)
{
ptr->_errno = ENOMEM;
}
return result;
}
void *
_realloc_r (struct _reent *ptr, void *old, size_t newlen)
{
void* result;
result = (void*)rt_realloc (old, newlen);
if (result == RT_NULL)
{
ptr->_errno = ENOMEM;
}
return result;
}
void *_calloc_r (struct _reent *ptr, size_t size, size_t len)
{
void* result;
result = (void*)rt_calloc (size, len);
if (result == RT_NULL)
{
ptr->_errno = ENOMEM;
}
return result;
}
void
_free_r (struct _reent *ptr, void *addr)
{
rt_free (addr);
}
#else
void *
_sbrk_r(struct _reent *ptr, ptrdiff_t incr)
{ {
/* no use this routine to get memory */
return RT_NULL; return RT_NULL;
} }
#endif /*RT_USING_HEAP*/

View File

@ -189,13 +189,6 @@ _rename_r(struct _reent *ptr, const char *old, const char *new)
#endif #endif
} }
void *
_sbrk_r(struct _reent *ptr, ptrdiff_t incr)
{
/* no use this routine to get memory */
return RT_NULL;
}
int int
_stat_r(struct _reent *ptr, const char *file, struct stat *pstat) _stat_r(struct _reent *ptr, const char *file, struct stat *pstat)
{ {
@ -258,7 +251,7 @@ _write_r(struct _reent *ptr, int fd, const void *buf, size_t nbytes)
#endif #endif
} }
/* Memory routine */ #ifdef RT_USING_HEAP /* Memory routine */
void * void *
_malloc_r (struct _reent *ptr, size_t size) _malloc_r (struct _reent *ptr, size_t size)
{ {
@ -306,6 +299,14 @@ _free_r (struct _reent *ptr, void *addr)
rt_free (addr); rt_free (addr);
} }
#else
void *
_sbrk_r(struct _reent *ptr, ptrdiff_t incr)
{
return RT_NULL;
}
#endif /*RT_USING_HEAP*/
/* for exit() and abort() */ /* for exit() and abort() */
__attribute__ ((noreturn)) void __attribute__ ((noreturn)) void
_exit (int status) _exit (int status)