mirror of
https://github.com/RT-Thread/rt-thread.git
synced 2025-02-22 06:05:23 +08:00
Merge pull request #5100 from mysterywolf/libcarrary
[libc][newlib] 优化syscall 重构_libc_init_array 防止gcc下芯片无法启动
This commit is contained in:
commit
66ad092f06
@ -18,11 +18,10 @@ if rtconfig.PLATFORM == 'gcc':
|
|||||||
LIBS += ['c', 'm']
|
LIBS += ['c', 'm']
|
||||||
|
|
||||||
src += Glob('*.c')
|
src += Glob('*.c')
|
||||||
SrcRemove(src, ['minilib.c'])
|
|
||||||
if GetDepend('RT_USING_MODULE') == False:
|
if GetDepend('RT_USING_MODULE') == False:
|
||||||
SrcRemove(src, ['libc_syms.c'])
|
SrcRemove(src, ['libc_syms.c'])
|
||||||
else:
|
else:
|
||||||
src += ['minilib.c']
|
src += ['syscalls.c']
|
||||||
|
|
||||||
group = DefineGroup('libc', src, depend = [], CPPPATH = CPPPATH, CPPDEFINES = CPPDEFINES, LIBS = LIBS)
|
group = DefineGroup('libc', src, depend = [], CPPPATH = CPPPATH, CPPDEFINES = CPPDEFINES, LIBS = LIBS)
|
||||||
|
|
||||||
|
@ -1,66 +0,0 @@
|
|||||||
/*
|
|
||||||
* Copyright (c) 2006-2021, RT-Thread Development Team
|
|
||||||
*
|
|
||||||
* SPDX-License-Identifier: Apache-2.0
|
|
||||||
*
|
|
||||||
* Change Logs:
|
|
||||||
* Date Author Notes
|
|
||||||
* 2021-02-23 Meco Man first version
|
|
||||||
*/
|
|
||||||
|
|
||||||
#include <reent.h>
|
|
||||||
#include <rtthread.h>
|
|
||||||
|
|
||||||
#ifdef RT_USING_HEAP /* Memory routine */
|
|
||||||
#include <sys/errno.h>
|
|
||||||
|
|
||||||
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)
|
|
||||||
{
|
|
||||||
return RT_NULL;
|
|
||||||
}
|
|
||||||
#endif /*RT_USING_HEAP*/
|
|
@ -11,17 +11,81 @@
|
|||||||
* 2020-02-24 Meco Man fix bug of _isatty_r()
|
* 2020-02-24 Meco Man fix bug of _isatty_r()
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include <reent.h>
|
|
||||||
#include <errno.h>
|
|
||||||
#include <stdio.h>
|
|
||||||
#include <sys/time.h>
|
|
||||||
|
|
||||||
#include <rtthread.h>
|
#include <rtthread.h>
|
||||||
|
#include <stddef.h>
|
||||||
|
#include <sys/errno.h>
|
||||||
|
|
||||||
|
#define DBG_TAG "newlib.syscalls"
|
||||||
|
#define DBG_LVL DBG_INFO
|
||||||
|
#include <rtdbg.h>
|
||||||
|
|
||||||
|
#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)
|
||||||
|
{
|
||||||
|
LOG_E("Please enable RT_USING_HEAP or RT_USING_LIBC");
|
||||||
|
RT_ASSERT(0);
|
||||||
|
return RT_NULL;
|
||||||
|
}
|
||||||
|
#endif /*RT_USING_HEAP*/
|
||||||
|
|
||||||
|
void __libc_init_array(void)
|
||||||
|
{
|
||||||
|
/* we not use __libc init_aray to initialize C++ objects */
|
||||||
|
/* __libc_init_array is ARM code, not Thumb; it will cause a hardfault. */
|
||||||
|
}
|
||||||
|
|
||||||
|
#ifdef RT_USING_LIBC
|
||||||
|
#include <reent.h>
|
||||||
|
#include <stdio.h>
|
||||||
#ifdef RT_USING_DFS
|
#ifdef RT_USING_DFS
|
||||||
#include <dfs_posix.h>
|
#include <dfs_posix.h>
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifdef RT_USING_MODULE
|
#ifdef RT_USING_MODULE
|
||||||
#include <dlmodule.h>
|
#include <dlmodule.h>
|
||||||
#endif
|
#endif
|
||||||
@ -233,59 +297,12 @@ _ssize_t _write_r(struct _reent *ptr, int fd, const void *buf, size_t nbytes)
|
|||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifdef RT_USING_HEAP /* Memory routine */
|
void _system(const char *s)
|
||||||
void *_malloc_r (struct _reent *ptr, size_t size)
|
|
||||||
{
|
{
|
||||||
void* result;
|
extern int __rt_libc_system(const char *string);
|
||||||
|
__rt_libc_system(s);
|
||||||
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)
|
|
||||||
{
|
|
||||||
return RT_NULL;
|
|
||||||
}
|
|
||||||
#endif /*RT_USING_HEAP*/
|
|
||||||
|
|
||||||
/* for exit() and abort() */
|
/* for exit() and abort() */
|
||||||
__attribute__ ((noreturn)) void _exit (int status)
|
__attribute__ ((noreturn)) void _exit (int status)
|
||||||
{
|
{
|
||||||
@ -294,17 +311,6 @@ __attribute__ ((noreturn)) void _exit (int status)
|
|||||||
while(1);
|
while(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
void _system(const char *s)
|
|
||||||
{
|
|
||||||
extern int __rt_libc_system(const char *string);
|
|
||||||
__rt_libc_system(s);
|
|
||||||
}
|
|
||||||
|
|
||||||
void __libc_init_array(void)
|
|
||||||
{
|
|
||||||
/* we not use __libc init_aray to initialize C++ objects */
|
|
||||||
}
|
|
||||||
|
|
||||||
mode_t umask(mode_t mask)
|
mode_t umask(mode_t mask)
|
||||||
{
|
{
|
||||||
return 022;
|
return 022;
|
||||||
@ -320,3 +326,5 @@ These functions are implemented and replaced by the 'common/time.c' file
|
|||||||
int _gettimeofday_r(struct _reent *ptr, struct timeval *__tp, void *__tzp);
|
int _gettimeofday_r(struct _reent *ptr, struct timeval *__tp, void *__tzp);
|
||||||
_CLOCK_T_ _times_r(struct _reent *ptr, struct tms *ptms);
|
_CLOCK_T_ _times_r(struct _reent *ptr, struct tms *ptms);
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
#endif /* RT_USING_LIBC */
|
||||||
|
Loading…
x
Reference in New Issue
Block a user