Skip to content

Commit 7ed6644

Browse files
authored
Merge pull request #4344 from mysterywolf/exit_1
[libc][common] 精简exit和abort函数
2 parents 9bfab03 + 263d856 commit 7ed6644

File tree

5 files changed

+72
-93
lines changed

5 files changed

+72
-93
lines changed

components/libc/compilers/armlibc/syscalls.c

Lines changed: 5 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -258,23 +258,9 @@ void _ttywrch(int ch)
258258

259259
RT_WEAK void _sys_exit(int return_code)
260260
{
261-
rt_thread_t self = rt_thread_self();
262-
263-
#ifdef RT_USING_MODULE
264-
if (dlmodule_self())
265-
{
266-
dlmodule_exit(return_code);
267-
}
268-
#endif
269-
270-
if (self != RT_NULL)
271-
{
272-
rt_kprintf("thread:%-8.*s exit:%d!\n", RT_NAME_MAX, self->name, return_code);
273-
rt_thread_suspend(self);
274-
rt_schedule();
275-
}
276-
277-
while(1); /* noreturn */
261+
extern void __rt_libc_exit(int status);
262+
__rt_libc_exit(return_code);
263+
while(1);
278264
}
279265

280266
/**
@@ -320,8 +306,8 @@ int remove(const char *filename)
320306
#else
321307
int system(const char *string)
322308
{
323-
RT_ASSERT(0);
324-
for (;;);
309+
extern int __rt_libc_system(const char *string);
310+
return __rt_libc_system(string);
325311
}
326312
#endif
327313

components/libc/compilers/common/SConscript

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,13 @@ group = []
88
CPPPATH = [cwd]
99

1010
if GetDepend('RT_USING_LIBC'):
11-
src += Glob('*.c')
11+
src += Glob('*.c')
1212
else:
13-
if GetDepend('RT_LIBC_USING_TIME') and not GetDepend('RT_USING_MINILIBC'):
14-
src += ['time.c']
13+
if GetDepend('RT_LIBC_USING_TIME') and not GetDepend('RT_USING_MINILIBC'):
14+
src += ['time.c']
1515

1616
if GetDepend('RT_USING_POSIX') == False:
17-
SrcRemove(src, ['unistd.c'])
17+
SrcRemove(src, ['unistd.c'])
1818

1919
if rtconfig.CROSS_TOOL == 'keil':
2020
CPPDEFINES = ['__CLK_TCK=RT_TICK_PER_SECOND']
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
/*
2+
* Copyright (c) 2006-2018, RT-Thread Development Team
3+
*
4+
* SPDX-License-Identifier: Apache-2.0
5+
*
6+
* Change Logs:
7+
* Date Author Notes
8+
* 2021-02-15 Meco Man first version
9+
*/
10+
11+
#include <rtthread.h>
12+
#include <stdlib.h>
13+
14+
void __rt_libc_exit(int status)
15+
{
16+
rt_thread_t self = rt_thread_self();
17+
18+
#ifdef RT_USING_MODULE
19+
if (dlmodule_self())
20+
{
21+
dlmodule_exit(status);
22+
}
23+
#endif
24+
25+
if (self != RT_NULL)
26+
{
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+
}
35+
rt_thread_suspend(self);
36+
rt_schedule();
37+
}
38+
}
39+
40+
void __rt_libc_abort(void)
41+
{
42+
__rt_libc_exit(EXIT_FAILURE);
43+
}
44+
45+
int __rt_libc_system(const char *string)
46+
{
47+
/* TODO */
48+
return 0;
49+
}

components/libc/compilers/dlib/syscalls.c

Lines changed: 6 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -11,42 +11,14 @@
1111

1212
void exit (int status)
1313
{
14-
rt_thread_t self = rt_thread_self();
15-
16-
#ifdef RT_USING_MODULE
17-
if (dlmodule_self())
18-
{
19-
dlmodule_exit(status);
20-
}
21-
#endif
22-
23-
if (self != RT_NULL)
24-
{
25-
rt_kprintf("thread:%-8.*s exit:%d!\n", RT_NAME_MAX, self->name, status);
26-
rt_thread_suspend(self);
27-
rt_schedule();
28-
}
29-
30-
while(1); /* noreturn */
14+
extern void __rt_libc_exit(int status);
15+
__rt_libc_exit(status);
16+
while(1);
3117
}
3218

3319
void abort(void)
3420
{
35-
rt_thread_t self = rt_thread_self();
36-
37-
#ifdef RT_USING_MODULE
38-
if (dlmodule_self())
39-
{
40-
dlmodule_exit(-1);
41-
}
42-
#endif
43-
44-
if (self != RT_NULL)
45-
{
46-
rt_kprintf("thread:%-8.*s abort!\n", RT_NAME_MAX, self->name);
47-
rt_thread_suspend(self);
48-
rt_schedule();
49-
}
50-
51-
while(1); /* noreturn */
21+
extern void __rt_libc_abort(void);
22+
__rt_libc_abort();
23+
while(1);
5224
}

components/libc/compilers/newlib/syscalls.c

Lines changed: 8 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -286,30 +286,16 @@ _free_r (struct _reent *ptr, void *addr)
286286
void
287287
exit (int status)
288288
{
289-
rt_thread_t self = rt_thread_self();
290-
291-
#ifdef RT_USING_MODULE
292-
if (dlmodule_self())
293-
{
294-
dlmodule_exit(status);
295-
}
296-
#endif
297-
298-
if (self != RT_NULL)
299-
{
300-
rt_kprintf("thread:%-8.*s exit:%d!\n", RT_NAME_MAX, self->name, status);
301-
rt_thread_suspend(self);
302-
rt_schedule();
303-
}
304-
305-
while(1); /* noreturn */
289+
extern void __rt_libc_exit(int status);
290+
__rt_libc_exit(status);
291+
while(1);
306292
}
307293

308294
void
309295
_system(const char *s)
310296
{
311-
/* not support this call */
312-
return;
297+
extern int __rt_libc_system(const char *string);
298+
__rt_libc_system(s);
313299
}
314300

315301
void __libc_init_array(void)
@@ -319,23 +305,9 @@ void __libc_init_array(void)
319305

320306
void abort(void)
321307
{
322-
rt_thread_t self = rt_thread_self();
323-
324-
#ifdef RT_USING_MODULE
325-
if (dlmodule_self())
326-
{
327-
dlmodule_exit(-1);
328-
}
329-
#endif
330-
331-
if (self != RT_NULL)
332-
{
333-
rt_kprintf("thread:%-8.*s abort!\n", RT_NAME_MAX, self->name);
334-
rt_thread_suspend(self);
335-
rt_schedule();
336-
}
337-
338-
while(1); /* noreturn */
308+
extern void __rt_libc_abort(void);
309+
__rt_libc_abort();
310+
while(1);
339311
}
340312

341313
uid_t getuid(void)

0 commit comments

Comments
 (0)