summaryrefslogtreecommitdiff
path: root/components/libc/compilers/newlib/syscalls.c
diff options
context:
space:
mode:
authorMeco Jianting Man <[email protected]>2021-09-27 06:16:39 -0500
committerGitHub <[email protected]>2021-09-27 06:16:39 -0500
commit37d4abb822c60872bf21f6a1bb0b61e8e1409cc7 (patch)
treeac8e69dbd720d5ad50529a029ba81c9fc9e7d9f9 /components/libc/compilers/newlib/syscalls.c
parent8e287cfdf70da52937eebe59a1e2527775dd1f0c (diff)
parent94bd9f96a4b49e94916a2904eea882792e0460d2 (diff)
Merge branch 'master' into libc_stdio
Diffstat (limited to 'components/libc/compilers/newlib/syscalls.c')
-rw-r--r--components/libc/compilers/newlib/syscalls.c141
1 files changed, 75 insertions, 66 deletions
diff --git a/components/libc/compilers/newlib/syscalls.c b/components/libc/compilers/newlib/syscalls.c
index 7ba06312ea..1cb7475fe1 100644
--- a/components/libc/compilers/newlib/syscalls.c
+++ b/components/libc/compilers/newlib/syscalls.c
@@ -12,17 +12,82 @@
*/
#include <reent.h>
-#include <sys/errno.h>
-#include <stdio.h>
+#include <rtthread.h>
+#include <stddef.h>
#include <unistd.h>
-#include <sys/time.h>
+#include <sys/errno.h>
-#include <rtthread.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
#include <dfs_posix.h>
#endif
-
#ifdef RT_USING_MODULE
#include <dlmodule.h>
#endif
@@ -246,58 +311,11 @@ _ssize_t _write_r(struct _reent *ptr, int fd, const void *buf, size_t nbytes)
#endif
}
-#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)
+void _system(const char *s)
{
- return RT_NULL;
+ extern int __rt_libc_system(const char *string);
+ __rt_libc_system(s);
}
-#endif /*RT_USING_HEAP*/
/* for exit() and abort() */
__attribute__ ((noreturn)) void _exit (int status)
@@ -307,17 +325,6 @@ __attribute__ ((noreturn)) void _exit (int status)
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)
{
return 022;
@@ -333,3 +340,5 @@ These functions are implemented and replaced by the 'common/time.c' file
int _gettimeofday_r(struct _reent *ptr, struct timeval *__tp, void *__tzp);
_CLOCK_T_ _times_r(struct _reent *ptr, struct tms *ptms);
*/
+
+#endif /* RT_USING_LIBC */