Skip to content

Commit 4094b0e

Browse files
authored
Merge pull request #4358 from mysterywolf/master
[libc] 优化abort函数
2 parents aa0adec + ae2d414 commit 4094b0e

File tree

4 files changed

+11
-28
lines changed

4 files changed

+11
-28
lines changed

components/libc/compilers/armlibc/syscalls.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -256,6 +256,7 @@ void _ttywrch(int ch)
256256
#endif
257257
}
258258

259+
/* for exit() and abort() */
259260
RT_WEAK void _sys_exit(int return_code)
260261
{
261262
extern void __rt_libc_exit(int status);

components/libc/compilers/common/stdlib.c

Lines changed: 1 addition & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@
99
*/
1010

1111
#include <rtthread.h>
12-
#include <stdlib.h>
1312

1413
void __rt_libc_exit(int status)
1514
{
@@ -24,24 +23,12 @@ void __rt_libc_exit(int status)
2423

2524
if (self != RT_NULL)
2625
{
27-
if(status == EXIT_FAILURE) /* abort() */
28-
{
29-
rt_kprintf("thread:%s abort!\n", self->name);
30-
}
31-
else /* exit() */
32-
{
33-
rt_kprintf("thread:%s exit:%d!\n", self->name, status);
34-
}
26+
rt_kprintf("thread:%s exit:%d!\n", self->name, status);
3527
rt_thread_suspend(self);
3628
rt_schedule();
3729
}
3830
}
3931

40-
void __rt_libc_abort(void)
41-
{
42-
__rt_libc_exit(EXIT_FAILURE);
43-
}
44-
4532
int __rt_libc_system(const char *string)
4633
{
4734
/* TODO */

components/libc/compilers/dlib/syscalls.c

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,19 +6,20 @@
66
* Change Logs:
77
* Date Author Notes
88
* 2021-02-13 Meco Man implement exit() and abort()
9+
* 2021-02-20 Meco Man add system()
910
*/
1011
#include <rtthread.h>
1112

12-
void exit (int status)
13+
/* for exit() and abort() */
14+
void __exit (int status)
1315
{
1416
extern void __rt_libc_exit(int status);
1517
__rt_libc_exit(status);
1618
while(1);
1719
}
1820

19-
void abort(void)
21+
int system(const char * string)
2022
{
21-
extern void __rt_libc_abort(void);
22-
__rt_libc_abort();
23-
while(1);
23+
extern int __rt_libc_system(const char *string);
24+
return __rt_libc_system(string);
2425
}

components/libc/compilers/newlib/syscalls.c

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -283,8 +283,9 @@ _free_r (struct _reent *ptr, void *addr)
283283
rt_free (addr);
284284
}
285285

286-
void
287-
exit (int status)
286+
/* for exit() and abort() */
287+
__attribute__ ((noreturn)) void
288+
_exit (int status)
288289
{
289290
extern void __rt_libc_exit(int status);
290291
__rt_libc_exit(status);
@@ -303,13 +304,6 @@ void __libc_init_array(void)
303304
/* we not use __libc init_aray to initialize C++ objects */
304305
}
305306

306-
void abort(void)
307-
{
308-
extern void __rt_libc_abort(void);
309-
__rt_libc_abort();
310-
while(1);
311-
}
312-
313307
uid_t getuid(void)
314308
{
315309
return 0;

0 commit comments

Comments
 (0)