/* * Copyright (C) 2017-2019 Alibaba Group Holding Limited. All rights reserved. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ /****************************************************************************** * @file _init.c * @brief source file for c++ init & uninit * @version V1.0 * @date 24. April 2019 ******************************************************************************/ #include #include #ifndef CPP_WEAK #define CPP_WEAK __attribute__((weak)) #endif extern int __dtor_end__; extern int __ctor_end__; extern int __ctor_start__; typedef void (*func_ptr) (void); CPP_WEAK void _init(void) { func_ptr *p; for (p = (func_ptr *)&__ctor_end__ - 1; p >= (func_ptr *)&__ctor_start__; p--) { (*p) (); } } CPP_WEAK void _fini(void) { func_ptr *p; for (p = (func_ptr *)&__ctor_end__; p <= (func_ptr *)&__dtor_end__ - 1; p++) { (*p) (); } }