diff options
| author | Bernard Xiong <[email protected]> | 2021-02-20 12:15:49 +0800 |
|---|---|---|
| committer | GitHub <[email protected]> | 2021-02-20 12:15:49 +0800 |
| commit | 4094b0e398d0ee157522ba4f450ff7fdb17ac4fd (patch) | |
| tree | 6e6b9f1b6e983cf0aaa55c81c8036162fa3f62eb | |
| parent | aa0adeccad1b74ff5ee1857b4621cff9c83682fa (diff) | |
| parent | ae2d414ca1580fc4ae8ab5618db01cb75af4d425 (diff) | |
Merge pull request #4358 from mysterywolf/master
[libc] 优化abort函数
| -rw-r--r-- | components/libc/compilers/armlibc/syscalls.c | 1 | ||||
| -rw-r--r-- | components/libc/compilers/common/stdlib.c | 15 | ||||
| -rw-r--r-- | components/libc/compilers/dlib/syscalls.c | 11 | ||||
| -rw-r--r-- | components/libc/compilers/newlib/syscalls.c | 12 |
4 files changed, 11 insertions, 28 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 <rtthread.h> -#include <stdlib.h> 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..007ea76bd1 100644 --- a/components/libc/compilers/dlib/syscalls.c +++ b/components/libc/compilers/dlib/syscalls.c @@ -6,19 +6,20 @@ * Change Logs: * Date Author Notes * 2021-02-13 Meco Man implement exit() and abort() + * 2021-02-20 Meco Man add system() */ #include <rtthread.h> -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) +int system(const char * string) { - extern void __rt_libc_abort(void); - __rt_libc_abort(); - while(1); + extern int __rt_libc_system(const char *string); + return __rt_libc_system(string); } diff --git a/components/libc/compilers/newlib/syscalls.c b/components/libc/compilers/newlib/syscalls.c index 76300f76b2..aee8ac360d 100644 --- a/components/libc/compilers/newlib/syscalls.c +++ b/components/libc/compilers/newlib/syscalls.c @@ -283,8 +283,9 @@ _free_r (struct _reent *ptr, void *addr) rt_free (addr); } -void -exit (int status) +/* for exit() and abort() */ +__attribute__ ((noreturn)) void +_exit (int status) { extern void __rt_libc_exit(int status); __rt_libc_exit(status); @@ -303,13 +304,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; |
