1 /* 2 * Copyright (C) 2017-2019 Alibaba Group Holding Limited 3 */ 4 /****************************************************************************** 5 * @file _init.c 6 * @brief source file for c++ init & uninit 7 * @version V1.0 8 * @date 24. April 2019 9 ******************************************************************************/ 10 11 #include <csi_config.h> 12 #include <string.h> 13 14 #ifndef CPP_WEAK 15 #define CPP_WEAK __attribute__((weak)) 16 #endif 17 18 extern int __dtor_end__; 19 extern int __ctor_end__; 20 extern int __ctor_start__; 21 22 typedef void (*func_ptr) (void); 23 _init(void)24CPP_WEAK void _init(void) 25 { 26 func_ptr *p; 27 for (p = ((func_ptr *)&__ctor_end__) - 1; p >= (func_ptr *)&__ctor_start__; p--) { 28 (*p) (); 29 } 30 } 31 _fini(void)32CPP_WEAK void _fini(void) 33 { 34 func_ptr *p; 35 for (p = (func_ptr *)&__ctor_end__; p <= ((func_ptr *)&__dtor_end__) - 1; p++) { 36 (*p) (); 37 } 38 } 39