1 #include <stdlib.h> 2 #include <stdint.h> 3 #include "libc.h" 4 #ifdef __LITEOS_A__ 5 #include <signal.h> 6 #include <atomic.h> 7 #include <pthread.h> 8 #include "syscall.h" 9 #include <bits/errno.h> 10 #ifdef __LITEOS_DEBUG__ 11 #include <stdbool.h> 12 #include <debug.h> 13 extern bool g_enable_check; 14 extern void mem_check_deinit(void); 15 extern void clean_recycle_list(bool clean_all); 16 #endif 17 18 pthread_mutex_t __exit_mutex = PTHREAD_MUTEX_INITIALIZER; 19 #endif dummy()20static void dummy() 21 { 22 } 23 24 /* atexit.c and __stdio_exit.c override these. the latter is linked 25 * as a consequence of linking either __toread.c or __towrite.c. */ 26 weak_alias(dummy, __funcs_on_exit); 27 weak_alias(dummy, __stdio_exit); 28 weak_alias(dummy, _fini); 29 30 extern weak hidden void (*const __fini_array_start)(void), (*const __fini_array_end)(void); 31 libc_exit_fini(void)32static void libc_exit_fini(void) 33 { 34 uintptr_t a = (uintptr_t)&__fini_array_end; 35 for (; a>(uintptr_t)&__fini_array_start; a-=sizeof(void(*)())) 36 (*(void (**)())(a-sizeof(void(*)())))(); 37 _fini(); 38 } 39 40 weak_alias(libc_exit_fini, __libc_exit_fini); 41 42 #if !defined(__LITEOS__) && !defined(__HISPARK_LINUX__) 43 extern void __cxa_thread_finalize(); 44 #endif 45 exit(int code)46_Noreturn void exit(int code) 47 { 48 #ifdef __LITEOS_A__ 49 sigset_t set; 50 51 __block_app_sigs(&set); 52 53 int ret = pthread_mutex_trylock(&__exit_mutex); 54 if (ret == EBUSY) { 55 pthread_exit(NULL); 56 } 57 58 #ifdef __LITEOS_DEBUG__ 59 if (g_enable_check) { 60 check_leak(); 61 check_heap_integrity(); 62 mem_check_deinit(); 63 clean_recycle_list(true); 64 } 65 #endif 66 #endif 67 68 #if !defined(__LITEOS__) && !defined(__HISPARK_LINUX__) 69 // Call thread_local dtors. 70 __cxa_thread_finalize(); 71 #endif 72 __funcs_on_exit(); 73 __libc_exit_fini(); 74 __stdio_exit(); 75 _Exit(code); 76 } 77