From eaa3454bbece542d43b9470f7bb65198ee395d75 Mon Sep 17 00:00:00 2001 From: Meco Man <920369182@qq.com> Date: Sat, 20 Feb 2021 11:31:58 +0800 Subject: [PATCH 1/3] =?UTF-8?q?=E4=BC=98=E5=8C=96abort=E5=87=BD=E6=95=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- components/libc/compilers/armlibc/syscalls.c | 1 + components/libc/compilers/common/stdlib.c | 15 +-------------- components/libc/compilers/dlib/syscalls.c | 10 ++-------- components/libc/compilers/newlib/syscalls.c | 11 ++--------- 4 files changed, 6 insertions(+), 31 deletions(-) diff --git a/components/libc/compilers/armlibc/syscalls.c b/components/libc/compilers/armlibc/syscalls.c index 37f296fc3a..d17460b413 100644 --- a/components/libc/compilers/armlibc/syscalls.c +++ b/components/libc/compilers/armlibc/syscalls.c @@ -256,6 +256,7 @@ void _ttywrch(int ch) #endif } +/* for exit() and abort() */ RT_WEAK void _sys_exit(int return_code) { extern void __rt_libc_exit(int status); diff --git a/components/libc/compilers/common/stdlib.c b/components/libc/compilers/common/stdlib.c index b485bbd836..9f801ab966 100644 --- a/components/libc/compilers/common/stdlib.c +++ b/components/libc/compilers/common/stdlib.c @@ -9,7 +9,6 @@ */ #include -#include void __rt_libc_exit(int status) { @@ -24,24 +23,12 @@ void __rt_libc_exit(int status) if (self != RT_NULL) { - if(status == EXIT_FAILURE) /* abort() */ - { - rt_kprintf("thread:%s abort!\n", self->name); - } - else /* exit() */ - { - rt_kprintf("thread:%s exit:%d!\n", self->name, status); - } + rt_kprintf("thread:%s exit:%d!\n", self->name, status); rt_thread_suspend(self); rt_schedule(); } } -void __rt_libc_abort(void) -{ - __rt_libc_exit(EXIT_FAILURE); -} - int __rt_libc_system(const char *string) { /* TODO */ diff --git a/components/libc/compilers/dlib/syscalls.c b/components/libc/compilers/dlib/syscalls.c index 10155948ba..346a766d53 100644 --- a/components/libc/compilers/dlib/syscalls.c +++ b/components/libc/compilers/dlib/syscalls.c @@ -9,16 +9,10 @@ */ #include -void exit (int status) +/* for exit() and abort() */ +void __exit (int status) { extern void __rt_libc_exit(int status); __rt_libc_exit(status); while(1); } - -void abort(void) -{ - extern void __rt_libc_abort(void); - __rt_libc_abort(); - while(1); -} diff --git a/components/libc/compilers/newlib/syscalls.c b/components/libc/compilers/newlib/syscalls.c index 76300f76b2..916922a7fe 100644 --- a/components/libc/compilers/newlib/syscalls.c +++ b/components/libc/compilers/newlib/syscalls.c @@ -283,8 +283,8 @@ _free_r (struct _reent *ptr, void *addr) rt_free (addr); } -void -exit (int status) +__attribute__ ((noreturn)) void +_exit (int status) { extern void __rt_libc_exit(int status); __rt_libc_exit(status); @@ -303,13 +303,6 @@ void __libc_init_array(void) /* we not use __libc init_aray to initialize C++ objects */ } -void abort(void) -{ - extern void __rt_libc_abort(void); - __rt_libc_abort(); - while(1); -} - uid_t getuid(void) { return 0; From 0ce0e2c234601712b3ae5ae6fddd5d862d202f18 Mon Sep 17 00:00:00 2001 From: Meco Man <920369182@qq.com> Date: Sat, 20 Feb 2021 11:35:41 +0800 Subject: [PATCH 2/3] update --- components/libc/compilers/newlib/syscalls.c | 1 + 1 file changed, 1 insertion(+) diff --git a/components/libc/compilers/newlib/syscalls.c b/components/libc/compilers/newlib/syscalls.c index 916922a7fe..aee8ac360d 100644 --- a/components/libc/compilers/newlib/syscalls.c +++ b/components/libc/compilers/newlib/syscalls.c @@ -283,6 +283,7 @@ _free_r (struct _reent *ptr, void *addr) rt_free (addr); } +/* for exit() and abort() */ __attribute__ ((noreturn)) void _exit (int status) { From ae2d414ca1580fc4ae8ab5618db01cb75af4d425 Mon Sep 17 00:00:00 2001 From: Meco Man <920369182@qq.com> Date: Sat, 20 Feb 2021 11:57:41 +0800 Subject: [PATCH 3/3] add system() for IAR --- components/libc/compilers/dlib/syscalls.c | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/components/libc/compilers/dlib/syscalls.c b/components/libc/compilers/dlib/syscalls.c index 346a766d53..007ea76bd1 100644 --- a/components/libc/compilers/dlib/syscalls.c +++ b/components/libc/compilers/dlib/syscalls.c @@ -6,6 +6,7 @@ * Change Logs: * Date Author Notes * 2021-02-13 Meco Man implement exit() and abort() + * 2021-02-20 Meco Man add system() */ #include @@ -16,3 +17,9 @@ void __exit (int status) __rt_libc_exit(status); while(1); } + +int system(const char * string) +{ + extern int __rt_libc_system(const char *string); + return __rt_libc_system(string); +}