MCPcopy Create free account
hub / github.com/alliedmodders/sourcemod / ResolveSymbol

Method ResolveSymbol

tools/gdc/MemoryUtils.cpp:114–410  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

112}
113
114void *MemoryUtils::ResolveSymbol(void *handle, const char *symbol)
115{
116#ifdef PLATFORM_WINDOWS
117
118 return GetProcAddress((HMODULE)handle, symbol);
119
120#elif defined PLATFORM_LINUX
121
122 struct link_map *dlmap;
123 struct stat dlstat;
124 int dlfile;
125 uintptr_t map_base;
126 Elf32_Ehdr *file_hdr;
127 Elf32_Shdr *sections, *shstrtab_hdr, *symtab_hdr, *strtab_hdr;
128 Elf32_Sym *symtab;
129 const char *shstrtab, *strtab;
130 uint16_t section_count;
131 uint32_t symbol_count;
132 LibSymbolTable *libtable;
133 SymbolTable *table;
134 AddrTable *table2;
135 Symbol *symbol_entry;
136
137 dlmap = (struct link_map *)handle;
138 symtab_hdr = NULL;
139 strtab_hdr = NULL;
140 table = NULL;
141 table2 = NULL;
142
143 /* See if we already have a symbol table for this library */
144 for (size_t i = 0; i < m_SymTables.size(); i++)
145 {
146 libtable = m_SymTables[i];
147 if (libtable->lib_base == dlmap->l_addr)
148 {
149 table = &libtable->table;
150 table2 = &libtable->table2;
151 break;
152 }
153 }
154
155 /* If we don't have a symbol table for this library, then create one */
156 if (table == NULL)
157 {
158 libtable = new LibSymbolTable();
159 libtable->table.Initialize();
160 libtable->table2.Initialize();
161 libtable->lib_base = dlmap->l_addr;
162 libtable->last_pos = 0;
163 table = &libtable->table;
164 table2 = &libtable->table2;
165 m_SymTables.push_back(libtable);
166 }
167
168 /* See if the symbol is already cached in our table */
169 symbol_entry = table->FindSymbol(symbol, strlen(symbol));
170 if (symbol_entry != NULL)
171 {

Callers 2

mainFunction · 0.45
PrepSDKCall_SetSignatureFunction · 0.45

Calls 5

push_backMethod · 0.80
sizeMethod · 0.45
InitializeMethod · 0.45
FindSymbolMethod · 0.45
InternSymbolMethod · 0.45

Tested by

no test coverage detected