|
libnds
|
Helpers to load dynamic libraries. More...
#include <stdio.h>#include <stdint.h>Functions | |
| int | dlclose (void *handle) |
| Frees all memory used by a dynamic library. | |
| char * | dlerror (void) |
| Returns a user-readable error string. | |
| void * | dlmembase (void *handle) |
| Returns a pointer to the base address of the code loaded with the library. | |
| void * | dlopen (const char *file, int mode) |
| Loads a dynamic library (in DSL format) into RAM. | |
| void * | dlopen_FILE (FILE *f, int mode) |
| Loads a dynamic library (in DSL format) into RAM from a FILE handle. | |
| void * | dlsym (void *handle, const char *name) |
| Returns a pointer to the requested symbol. | |
| void | dsl_set_symbol_resolver (SymbolResolverFn fn) |
Set the symbol resolver callback function. Passing NULL is allowed, and disables symbol resolution. You may provide a callback to resolve (or override) symbol values of a DSL before relocation. This is the primary way to let DSLs call functions in each other. | |
Helpers to load dynamic libraries.
The functions in this file allow the user to load DSL (Nintendo DS Loadable) files. They are a simplified version of ELF files created by dsltool, which is a tool included in BlocksDS.
| int dlclose | ( | void * | handle | ) |
| char * dlerror | ( | void | ) |
Returns a user-readable error string.
It clears the error string after being called.
| void * dlmembase | ( | void * | handle | ) |
Returns a pointer to the base address of the code loaded with the library.
The purpose of this function is to print this address to be used when debugging the code with emulators. You must provide this address when loading the elf file of the library. For example, with the GDB command line:
Note that this is a libnds-specific function.
| handle | The handle returned by dlopen(). |
| void * dlopen | ( | const char * | file, |
| int | mode | ||
| ) |
Loads a dynamic library (in DSL format) into RAM.
| file | Path of the DSL file. |
| mode | Mode in which the file will be opened. Currently, the only mode supported is RTLD_NOW | RTLD_LOCAL. Also, RTLD_LOCAL is the default setting, so it isn't required to specify it explicitly. |
| void * dlopen_FILE | ( | FILE * | f, |
| int | mode | ||
| ) |
Loads a dynamic library (in DSL format) into RAM from a FILE handle.
The handle must be opened before dlopen_FILE() is called and it must be closed after dlopen_FILE() returns. It isn't needed after the library has been loaded.
For example, you can use this to load a dynamic library that you have already loaded to RAM. You can use fmemopen() on the buffer where the library is stored and pass the resulting handle to dlopen_FILE().
| f | Open file handle to the DSL library file. |
| mode | Mode in which the file will be opened. Currently, the only mode supported is RTLD_NOW | RTLD_LOCAL. Also, RTLD_LOCAL is the default setting, so it isn't required to specify it explicitly. |
| void * dlsym | ( | void * | handle, |
| const char * | name | ||
| ) |
Returns a pointer to the requested symbol.
| handle | The handle returned by dlopen(). |
| name | The name of the requested symbol. |
| void dsl_set_symbol_resolver | ( | SymbolResolverFn | fn | ) |
Set the symbol resolver callback function. Passing NULL is allowed, and disables symbol resolution. You may provide a callback to resolve (or override) symbol values of a DSL before relocation. This is the primary way to let DSLs call functions in each other.
The callback must return whether symbol resolution succeeded as a boolean. If false is returned for any symbol, dlopen() will fail with the error "symbol resolver failed".
You should use this safety mechanism to return false if you did not resolve a symbol attributed with DSL_SYMBOL_UNRESOLVED. Not resolving these symbols while returning true will result in undefined behavior.
| fn | The symbol resolver callback function. |