A callback used when MojoELF needs to resolve a symbol.
Defined in <mojoelf.h>
typedef void *(*MOJOELF_ResolverCallback)(void *handle, const char *sym);| handle | a pointer returned from a previous MOJOELF_LoaderCallback, or NULL when all other options have been exhausted. |
| sym | the symbol to find an address for. |
Returns address of symbol if found, NULL if symbol isn't available.
This passes the pointer returned by MOJOELF_LoaderCallback as
handle and will call this callback once for each loaded
library until it finds one that resolves the symbol or runs out of
libraries to try.
The callback is called once for each non-NULL value that your loader previously returned, in the other they were returned, until one succeeds. If none succeeds, the callback fires one more time with the handle set to NULL. If this still doesn't return a non-NULL value, MojoELF will give up on the ELF file it was in the process of loading, due to missing dependencies.
A simple resolver callback might look like this:
extern int my_function(int argument);
void *my_resolver(void *handle, const char *sym)
{
if (strcmp(sym, "my_function") == 0)
return my_function;
// this also works for data, not just functions.
return NULL; // can't help you.
}As you can see, it isn't required to build a whole resolving infrastructure if one just wants to provide a handful of specific entry points.
Note: this callback returns NULL to specify "symbol not found" but strictly speaking, a symbol could exist at address 0x00000000. In practice, this would be ridiculous, so MojoELF makes no effort to allow this scenario.
This will be called from the same thread that called into
MOJOELF_dlopen_*. Locking is not provided by MojoELF.
This function is available since MojoELF 1.0.0.