The FreeRADIUS server
$Id: 15bac2a4c627c01d1aa2047687b3418955ac7f00 $
|
Wrappers around dlopen. More...
#include <freeradius-devel/util/dlist.h>
#include <freeradius-devel/util/rb.h>
#include <freeradius-devel/util/talloc.h>
#include <freeradius-devel/util/version.h>
#include <stdbool.h>
Go to the source code of this file.
Data Structures | |
struct | dl_s |
Module handle. More... | |
Macros | |
#define | DL_EXTENSION ".so" |
Typedefs | |
typedef struct dl_loader_s | dl_loader_t |
typedef int(* | dl_onload_t) (dl_t const *module, void *symbol, void *user_ctx) |
Callback to call when a module is first loaded. More... | |
typedef struct dl_s | dl_t |
Module handle. More... | |
typedef void(* | dl_unload_t) (dl_t const *module, void *symbol, void *user_ctx) |
Callback when a module is destroyed. More... | |
Functions | |
dl_t * | dl_by_name (dl_loader_t *dl_loader, char const *name, void *uctx, bool uctx_free)) |
Search for a dl's shared object in various locations. More... | |
int | dl_free (dl_t const *dl) |
"free" a dl handle, possibly actually freeing it, and unloading the library More... | |
void | dl_loader_debug (dl_loader_t *dl) |
Called from a debugger to print information about a dl_loader. More... | |
dl_loader_t * | dl_loader_init (TALLOC_CTX *ctx, void *uctx, bool uctx_free, bool defer_symbol_init) |
Initialise structures needed by the dynamic linker. More... | |
bool | dl_loader_set_static (dl_loader_t *dl_loader, bool do_static) |
Runtime override for doing static or dynamic module loading. More... | |
void * | dl_loader_uctx (dl_loader_t *dl_loader) |
Retrieve the uctx from a dl_loader. More... | |
void * | dl_open_by_sym (char const *sym_name, int flags) |
Utility function to dlopen the library containing a particular symbol. More... | |
int | dl_search_global_path_set (char const *lib_dir) |
Set the global library path. More... | |
char const * | dl_search_path (dl_loader_t *dl_loader) |
Return current library path. More... | |
int | dl_search_path_append (dl_loader_t *dl_loader, char const *lib_dir) |
Append a new search path component to the library search path. More... | |
int | dl_search_path_prepend (dl_loader_t *dl_loader, char const *lib_dir) |
Append a new search path component to the library search path. More... | |
int | dl_search_path_set (dl_loader_t *dl_loader, char const *lib_dir) |
Set the current library path. More... | |
int | dl_symbol_free_cb_register (dl_loader_t *dl_loader, unsigned int priority, char const *symbol, dl_unload_t func, void *ctx) |
Register a callback to execute when a dl with a particular symbol is unloaded. More... | |
void | dl_symbol_free_cb_unregister (dl_loader_t *dl_loader, char const *symbol, dl_unload_t func) |
Unregister an callback that was to be executed when a dl was unloaded. More... | |
int | dl_symbol_init (dl_loader_t *dl_loader, dl_t const *dl) |
Walk over the registered init callbacks, searching for the symbols they depend on. More... | |
int | dl_symbol_init_cb_register (dl_loader_t *dl_loader, unsigned int priority, char const *symbol, dl_onload_t func, void *ctx) |
Register a callback to execute when a dl with a particular symbol is first loaded. More... | |
void | dl_symbol_init_cb_unregister (dl_loader_t *dl_loader, char const *symbol, dl_onload_t func) |
Unregister an callback that was to be executed when a dl was first loaded. More... | |
Wrappers around dlopen.
Definition in file dl.h.
struct dl_s |
Module handle.
Contains module's dlhandle, and the functions it exports.
Data Fields | ||
---|---|---|
void * | handle | Handle returned by dlopen. |
bool | in_tree | Whether this dl is registered in the dl_tree. |
dl_loader_t * | loader | Loader that owns this dl. |
char const * | name | Name of the module e.g. sql. |
fr_rb_node_t | node | Entry in the rbtree module handles. |
void * | uctx | API client's opaque data. |
bool | uctx_free | Free opaque data on dl_t free (usually false). |
typedef struct dl_loader_s dl_loader_t |
typedef int(* dl_onload_t) (dl_t const *module, void *symbol, void *user_ctx) |
typedef void(* dl_unload_t) (dl_t const *module, void *symbol, void *user_ctx) |
dl_t* dl_by_name | ( | dl_loader_t * | dl_loader, |
char const * | name, | ||
void * | uctx, | ||
bool | uctx_free | ||
) |
Search for a dl's shared object in various locations.
[in] | dl_loader | Tree of dynamically loaded libraries, and callbacks. |
[in] | name | of library to load. May be a relative path. |
[in] | uctx | Data to store within the dl_t. |
[in] | uctx_free | talloc_free the passed in uctx data if this dl_t is freed. |
Definition at line 470 of file dl.c.
int dl_free | ( | dl_t const * | dl | ) |
"free" a dl handle, possibly actually freeing it, and unloading the library
This function should be used to explicitly free a dl.
Because dls are reference counted, it may not actually free the memory or unload the library, but it will reduce the reference count.
Definition at line 678 of file dl.c.
void dl_loader_debug | ( | dl_loader_t * | dl | ) |
dl_loader_t* dl_loader_init | ( | TALLOC_CTX * | ctx, |
void * | uctx, | ||
bool | uctx_free, | ||
bool | defer_symbol_init | ||
) |
Initialise structures needed by the dynamic linker.
[in] | ctx | To bind lifetime of dl_loader_t too. |
[in] | uctx | API client opaque data to store in dl_loader_t. |
[in] | uctx_free | Call talloc_free() on uctx when the dl_loader_t is freed. |
[in] | defer_symbol_init | If true, it is up to the caller to call dl_symbol_init after calling dl_by_name. This prevents any of the registered callbacks from executing until dl_symbol_init is called explicitly. |
Definition at line 885 of file dl.c.
bool dl_loader_set_static | ( | dl_loader_t * | dl_loader, |
bool | do_static | ||
) |
Runtime override for doing static or dynamic module loading.
[in] | dl_loader | to configure. |
[in] | do_static | If true, all dlopen calls result in a reference to RTLD_DEFAULT being returned which allows all the dynamic loading infrastructure to worth correctly with a monolithic binary. |
void* dl_loader_uctx | ( | dl_loader_t * | dl_loader | ) |
void* dl_open_by_sym | ( | char const * | sym_name, |
int | flags | ||
) |
Utility function to dlopen the library containing a particular symbol.
[in] | sym_name | to resolve. |
[in] | flags | to pass to dlopen. |
Definition at line 186 of file dl.c.
int dl_search_global_path_set | ( | char const * | lib_dir | ) |
char const* dl_search_path | ( | dl_loader_t * | dl_loader | ) |
int dl_search_path_append | ( | dl_loader_t * | dl_loader, |
char const * | lib_dir | ||
) |
int dl_search_path_prepend | ( | dl_loader_t * | dl_loader, |
char const * | lib_dir | ||
) |
int dl_search_path_set | ( | dl_loader_t * | dl_loader, |
char const * | lib_dir | ||
) |
int dl_symbol_free_cb_register | ( | dl_loader_t * | dl_loader, |
unsigned int | priority, | ||
char const * | symbol, | ||
dl_unload_t | func, | ||
void * | uctx | ||
) |
Register a callback to execute when a dl with a particular symbol is unloaded.
[in] | dl_loader | Tree of dynamically loaded libraries, and callbacks. |
[in] | priority | Execution priority. Callbacks with a higher priority get called first. |
[in] | symbol | that determines whether func should be called. "<modname>_" is added as a prefix to the symbol. The prefix is added because some dls are loaded with RTLD_GLOBAL into the global symbol space, so the symbols they export must be unique. May be NULL to always call the function. |
[in] | func | to register. Called then dl is unloaded. |
[in] | uctx | to pass to func. |
Definition at line 384 of file dl.c.
void dl_symbol_free_cb_unregister | ( | dl_loader_t * | dl_loader, |
char const * | symbol, | ||
dl_unload_t | func | ||
) |
Unregister an callback that was to be executed when a dl was unloaded.
[in] | dl_loader | Tree of dynamically loaded libraries, and callbacks. |
[in] | symbol | the callback is attached to. |
[in] | func | the callback. |
Definition at line 419 of file dl.c.
int dl_symbol_init | ( | dl_loader_t * | dl_loader, |
dl_t const * | dl | ||
) |
Walk over the registered init callbacks, searching for the symbols they depend on.
Allows code outside of the dl API to register initialisation functions that get executed depending on whether the dl exports a particular symbol.
This cuts down the amount of boilerplate code in 'mod_load' functions.
[in] | dl_loader | Tree of dynamically loaded libraries, and callbacks. |
[in] | dl | to search for symbols in. |
Definition at line 233 of file dl.c.
int dl_symbol_init_cb_register | ( | dl_loader_t * | dl_loader, |
unsigned int | priority, | ||
char const * | symbol, | ||
dl_onload_t | func, | ||
void * | uctx | ||
) |
Register a callback to execute when a dl with a particular symbol is first loaded.
[in] | dl_loader | Tree of dynamically loaded libraries, and callbacks. |
[in] | priority | Execution priority. Callbacks with a higher priority get called first. |
[in] | symbol | that determines whether func should be called. "<modname>_" is added as a prefix to the symbol. The prefix is added because some dls are loaded with RTLD_GLOBAL into the global symbol space, so the symbols they export must be unique. May be NULL to always call the function. |
[in] | func | to register. Called when dl is loaded. |
[in] | uctx | to pass to func. |
Definition at line 321 of file dl.c.
void dl_symbol_init_cb_unregister | ( | dl_loader_t * | dl_loader, |
char const * | symbol, | ||
dl_onload_t | func | ||
) |
Unregister an callback that was to be executed when a dl was first loaded.
[in] | dl_loader | Tree of dynamically loaded libraries, and callbacks. |
[in] | symbol | the callback is attached to. |
[in] | func | the callback. |
Definition at line 355 of file dl.c.