1 /*
2 * Copyright (c) 2006-2024 RT-Thread Development Team
3 *
4 * SPDX-License-Identifier: Apache-2.0
5 *
6 * Change Logs:
7 * Date Author Notes
8 * 2010-11-17 yi.qiu first version
9 */
10
11 #include <rtthread.h>
12 #include <rtm.h>
13
14 #include "dlmodule.h"
15
16 /**
17 * @brief look up the address of a symbol in a dynamically loaded shared library.
18 *
19 * @param handle the handle returned by dlopen() when the library was previously loaded.
20 * @param symbol A string containing the name of the symbol to locate.
21 * @return void* On success, it returns a pointer to the symbol. Otherwise, it returns RT_NULL.
22 *
23 * @note This function is an API of POSIX standard, which is commonly used in conjunction with dlopen() to retrieve function pointers from shared libraries.
24 * the input symbol name, which can be the name of a function or variable, is compared with each symbol
25 * in the module symbol table. if the same symbol is found, return its address.
26 */
dlsym(void * handle,const char * symbol)27 void* dlsym(void *handle, const char* symbol)
28 {
29 int i;
30 struct rt_dlmodule *module;
31
32 RT_ASSERT(handle != RT_NULL);
33
34 module = (struct rt_dlmodule *)handle;
35
36 for(i=0; i<module->nsym; i++)
37 {
38 if (rt_strcmp(module->symtab[i].name, symbol) == 0)
39 return (void*)module->symtab[i].addr;
40 }
41
42 return RT_NULL;
43 }
44 RTM_EXPORT(dlsym)
45