4
0
mirror of https://github.com/RT-Thread/rt-thread.git synced 2025-02-02 06:10:25 +08:00

45 lines
1.3 KiB
C
Raw Normal View History

2013-01-08 22:40:58 +08:00
/*
2024-11-12 15:38:28 +08:00
* Copyright (c) 2006-2024 RT-Thread Development Team
2013-01-08 22:40:58 +08:00
*
2018-08-30 20:27:45 +08:00
* SPDX-License-Identifier: Apache-2.0
2013-01-08 22:40:58 +08:00
*
* Change Logs:
2018-08-30 20:27:45 +08:00
* Date Author Notes
* 2010-11-17 yi.qiu first version
2013-01-08 22:40:58 +08:00
*/
#include <rtthread.h>
#include <rtm.h>
2018-08-30 20:27:45 +08:00
#include "dlmodule.h"
2024-11-12 15:38:28 +08:00
/**
* @brief look up the address of a symbol in a dynamically loaded shared library.
*
* @param handle the handle returned by dlopen() when the library was previously loaded.
* @param symbol A string containing the name of the symbol to locate.
* @return void* On success, it returns a pointer to the symbol. Otherwise, it returns RT_NULL.
*
* @note This function is an API of POSIX standard, which is commonly used in conjunction with dlopen() to retrieve function pointers from shared libraries.
* the input symbol name, which can be the name of a function or variable, is compared with each symbol
* in the module symbol table. if the same symbol is found, return its address.
*/
2013-01-08 22:40:58 +08:00
void* dlsym(void *handle, const char* symbol)
{
2018-08-30 20:27:45 +08:00
int i;
struct rt_dlmodule *module;
2021-03-08 18:19:04 +08:00
2018-08-30 20:27:45 +08:00
RT_ASSERT(handle != RT_NULL);
2013-01-08 22:40:58 +08:00
2018-08-30 20:27:45 +08:00
module = (struct rt_dlmodule *)handle;
2013-01-08 22:40:58 +08:00
2018-08-30 20:27:45 +08:00
for(i=0; i<module->nsym; i++)
{
if (rt_strcmp(module->symtab[i].name, symbol) == 0)
return (void*)module->symtab[i].addr;
}
2013-01-08 22:40:58 +08:00
2018-08-30 20:27:45 +08:00
return RT_NULL;
2013-01-08 22:40:58 +08:00
}
RTM_EXPORT(dlsym)