/* ---------------------------------------------------------------------------- * Copyright (c) Huawei Technologies Co., Ltd. 2013-2019. All rights reserved. * Description: Dynload ElfLib HeadFile * Author: Huawei LiteOS Team * Create: 2013-01-01 * Redistribution and use in source and binary forms, with or without modification, * are permitted provided that the following conditions are met: * 1. Redistributions of source code must retain the above copyright notice, this list of * conditions and the following disclaimer. * 2. Redistributions in binary form must reproduce the above copyright notice, this list * of conditions and the following disclaimer in the documentation and/or other materials * provided with the distribution. * 3. Neither the name of the copyright holder nor the names of its contributors may be used * to endorse or promote products derived from this software without specific prior written * permission. * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * --------------------------------------------------------------------------- */ /** * @defgroup los_dynload Dynamic loading * @ingroup kernel */ #ifndef _LOS_LD_ELFLIB_H #define _LOS_LD_ELFLIB_H #include "los_typedef.h" #ifdef __cplusplus #if __cplusplus extern "C" { #endif /* __cplusplus */ #endif /* __cplusplus */ #ifdef LOSCFG_KERNEL_DYNLOAD_DYN #ifdef LOSCFG_DYNLOAD_DYN_FROM_FS /** * @ingroup los_dynload * Define an enum type indicates load strategy. * * Type of load strategy of dynamic load, ZIP means using zipped shared object, NOZIP means using normal shared object. */ enum LOAD_STRATEGY { ZIP, NOZIP }; /*这是一个枚举类型的定义,名称为LOAD_STRATEGY。它包含两个成员:ZIP和NOZIP。*/ /** * @ingroup los_dynload * Define the structure of the parameters used for dynamic. * * Information of specified parameters passed in during dynamic load. */ typedef struct tagDynloadParam { enum LOAD_STRATEGY enLoadStrategy; } DYNLOAD_PARAM_S; /*这个结构体可以用来存储动态加载的参数信息, 其中enLoadStrategy成员表示加载策略,可以是ZIP或者NOZIP。通过使用这个结构体, 可以将加载策略作为参数传递给相关的函数或模块。*/ /** * @ingroup los_dynload * @brief Register the dynamic parameters. * * @par Description: * This API is used to register the dynamic load parameters. * @attention * * * @param dynloadParam [IN] dynamic load parameters to be registered. * * @par Dependency: * * @see LOS_FindSymByName | LOS_LdDestroy * @since Huawei LiteOS V100R001C00 */ extern VOID LOS_DynParamReg(DYNLOAD_PARAM_S *dynloadParam); /*通过调用LOS_DynParamReg函数并传递一个指向DYNLOAD_PARAM_S类型对象的指针, 可以将动态加载的参数信息注册到相关的系统或模块中。*/ /** * @ingroup los_dynload * @brief Load a shared object file. * * @par Description: * This API is used to load a shared object file under a particular module file path. * @attention * * * @param elfFileName [IN] Shared object file path. * * @retval NULL The shared object file fails to be loaded. * @retval VOID* The shared object file is successfully loaded. * @par Dependency: * * @see LOS_ModuleUnload * @since Huawei LiteOS V100R001C00 */ extern VOID *LOS_SoLoad(CHAR *elfFileName); #endif /* LOSCFG_DYNLOAD_DYN_FROM_FS */ #ifdef LOSCFG_DYNLOAD_DYN_FROM_MEM /** * @ingroup los_dynload * @brief Load a shared object file from the memory. * * @par Description: * This API is used to load a shared object file that is in memory. * @attention * * * @param elfFileName [IN] Shared object file name. * @param fileNameLen [IN] The length of shared object file name. * @param elfFileBuf [IN] Shared object file buffer in memory. * @param bufLen [IN] the length of shared object file buffer in memory. * * @retval NULL The shared object file fails to be loaded. * @retval VOID* The shared object file is successfully loaded. * @par Dependency: * * @see LOS_ModuleUnload * @since Huawei LiteOS V200R003C00 */ extern VOID *LOS_MemLoad(const CHAR *elfFileName, UINT32 fileNameLen, const CHAR *elfFileBuf, UINT32 bufLen); #endif /* LOSCFG_DYNLOAD_DYN_FROM_MEM */ #endif /* LOSCFG_KERNEL_DYNLOAD_DYN */ /*这段代码中使用了条件编译指令#ifdef和#endif,用于在不同的编译环境下选择是否启用动态加载功能。*/ #ifdef LOSCFG_KERNEL_DYNLOAD_REL /** * @ingroup los_dynload * @brief Load a object file. * * @par Description: * This API is used to load a object file under a particular module file path. * @attention * * * @param elfFileName [IN] Object file path. * * @retval NULL The object file fails to be loaded. * @retval VOID* The object file is successfully loaded. * @par Dependency: * * @see LOS_ModuleUnload * @since Huawei LiteOS V100R001C00 */ extern VOID *LOS_ObjLoad(CHAR *elfFileName); #endif /* LOSCFG_KERNEL_DYNLOAD_REL */ /*如果宏定义LOSCFG_KERNEL_DYNLOAD_REL被定义, 则表示启用了动态链接库的重定位功能,此时函数LOS_ObjLoad被声明为外部函数, 并接受一个指向字符串类型(CHAR)的指针作为参数,返回一个VOID类型的指针。*/ /** * @ingroup los_dynload * @brief Unload a module. * * @par Description: * This API is used to unload a module with a particular module handle. * @attention * * * @param handle [IN] Module handle. * * @retval #LOS_NOK The module fails to be unloaded. * @retval #LOS_OK The module is successfully unloaded. * @par Dependency: * * @see LOS_ObjLoad * @since Huawei LiteOS V100R001C00 */ extern INT32 LOS_ModuleUnload(VOID *handle); /*通过调用LOS_ModuleUnload函数并传递一个动态库的句柄, 可以卸载该动态库并释放相关资源。*/ /** * @ingroup los_dynload * @brief Destroy a dynamic loader. * * @par Description: * This API is used to destroy a dynamic linker. * @attention * * * @param None. * * @retval None. * @par Dependency: * * @see LOS_FindSymByName * @since Huawei LiteOS V100R001C00 */ extern VOID LOS_LdDestroy(VOID); /*这段代码声明了一个外部函数LOS_LdDestroy,该函数没有参数和返回值。 通过调用LOS_LdDestroy函数,可以销毁动态加载器(Loader),释放相关资源*/ /** * @ingroup los_dynload * @brief Search for a symbol address. * * @par Description: * This API is used to search for the address of a symbol according to a particular module handle and symbol name. * @attention * * * @param handle [IN] Module handle. * @param name [IN] Name of the symbol to be searched for. * * @retval NULL The symbol address is not found. * @retval VOID* Symbol address. * @par Dependency: * * @see LOS_LdDestroy * @since Huawei LiteOS V100R001C00 */ extern VOID *LOS_FindSymByName(VOID *handle, CHAR *name); /** * @ingroup los_dynload * @brief Add a default path. * * @par Description: * This API is used to add a path to default paths. * @attention * * * @param path [IN] Path to be added to default paths. * * @retval #LOS_NOK The path is added unsuccessfully. * @retval #LOS_OK The path is added successfully. * @par Dependency: * * @see LOS_FindSymByName | LOS_LdDestroy * @since Huawei LiteOS V100R001C00 */ extern INT32 LOS_PathAdd(CHAR *path); /*通过调用LOS_PathAdd函数并传递一个路径,可以将该路径添加到动态库搜索路径中。 在动态链接库加载时,系统会按照一定的顺序搜索动态库*/ /** * @ingroup los_dynload * @brief Set the memory pool address used by dynload * * @par Description: * This API is used to set the memory pool address used by dynload. * @attention * * * @param memPool [IN] the memory pool address. * * @retval TRUE Set successful. * @retval FLASE Set failed. * @par Dependency: * * @see LOS_ModuleUnload * @since Huawei LiteOS V200R002C00 */ extern BOOL LOS_DynMemPoolSet(VOID *memPool); /*通过调用LOS_DynMemPoolSet函数并传递一个内存池指针, 可以设置动态内存池,用于在加载和执行动态链接库时分配内存。动态链接库可能 需要在运行时分配内存来存储数据和执行代码,因此需要提供一个合适的内存池。*/ #ifdef __cplusplus #if __cplusplus } #endif /* __cplusplus */ #endif /* __cplusplus */ #endif /* _LOS_LD_ELFLIB_H */