The FreeRADIUS server $Id: 15bac2a4c627c01d1aa2047687b3418955ac7f00 $
|
Wrappers around dlopen to manage loading shared objects at runtime. More...
#include <freeradius-devel/server/dl_module.h>
#include <freeradius-devel/server/log.h>
#include <freeradius-devel/util/atexit.h>
#include <freeradius-devel/util/debug.h>
#include <freeradius-devel/util/paths.h>
#include <freeradius-devel/util/syserror.h>
Go to the source code of this file.
Data Structures | |
struct | dl_loader_s |
A dynamic loader. More... | |
struct | dl_symbol_free_s |
struct | dl_symbol_init_s |
Macros | |
#define | RTLD_LOCAL (0) |
#define | RTLD_NOW (0) |
#define | RUNNING_ON_VALGRIND 0 |
Typedefs | |
typedef struct dl_symbol_free_s | dl_symbol_free_t |
Symbol dependent free callback. | |
typedef struct dl_symbol_init_s | dl_symbol_init_t |
Symbol dependent initialisation callback. | |
Functions | |
static int | _dl_free (dl_t *dl) |
Free a dl. | |
static int | _dl_loader_free (dl_loader_t *dl_loader) |
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. | |
int | dl_free (dl_t const *dl) |
"free" a dl handle, possibly actually freeing it, and unloading the library | |
static int8_t | dl_handle_cmp (void const *one, void const *two) |
Compare the name of two dl_t. | |
void | dl_loader_debug (dl_loader_t *dl) |
Called from a debugger to print information about a dl_loader. | |
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. | |
bool | dl_loader_set_static (dl_loader_t *dl_loader, bool do_static) |
Runtime override for doing static or dynamic module loading. | |
void * | dl_loader_uctx (dl_loader_t *dl_loader) |
Retrieve the uctx from a dl_loader. | |
void * | dl_open_by_sym (char const *sym_name, int flags) |
Utility function to dlopen the library containing a particular symbol. | |
int | dl_search_global_path_set (char const *lib_dir) |
Set the global library path. | |
char const * | dl_search_path (dl_loader_t *dl_loader) |
Return current library path. | |
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. | |
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. | |
int | dl_search_path_set (dl_loader_t *dl_loader, char const *lib_dir) |
Set the current library path. | |
static int | dl_symbol_free (dl_loader_t *dl_loader, dl_t const *dl) |
Walk over the registered init callbacks, searching for the symbols they depend on. | |
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. | |
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. | |
static int8_t | dl_symbol_free_cmp (void const *one, void const *two) |
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. | |
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. | |
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. | |
static int8_t | dl_symbol_init_cmp (void const *one, void const *two) |
Variables | |
static char * | dl_global_libdir = NULL |
Global search path, prepended all dlopen paths. | |
Wrappers around dlopen to manage loading shared objects at runtime.
Definition in file dl.c.
struct dl_loader_s |
Data Fields | ||
---|---|---|
bool | defer_symbol_init | Do not call dl_symbol_init in dl_loader_init. |
bool | do_dlclose | dlclose modules when we're done with them. |
bool | do_static |
Do all symbol resolution using the special RTLD_DEFAULT handle, instead of attempting to load modules using dlopen(). This is useful when FreeRADIUS has been built as a monolithic binary. |
char * | lib_dir | Where the libraries live. |
fr_dlist_head_t | sym_free |
Linked list of symbol free callbacks.
|
fr_dlist_head_t | sym_init |
Linked list of symbol init callbacks.
|
fr_rb_tree_t * | tree | Tree of shared objects loaded. |
void * | uctx | dl private extension data. |
bool | uctx_free | Free uctx when dl_loader_t is freed. |
struct dl_symbol_free_s |
Data Fields | ||
---|---|---|
fr_dlist_t | entry | Entry into the list of 'free' symbol callbacks. |
dl_unload_t | func | to call when symbol is found in a dl's symbol table. |
unsigned int | priority | Call priority. |
char const * | symbol | to search for. May be NULL in which case func is always called. |
void * | uctx | User data to pass to func. |
struct dl_symbol_init_s |
Data Fields | ||
---|---|---|
fr_dlist_t | entry | Entry into the list of 'init' symbol callbacks. |
dl_onload_t | func | to call when symbol is found in a dl's symbol table. |
unsigned int | priority | Call priority. |
char const * | symbol | to search for. May be NULL in which case func is always called. |
void * | uctx | User data to pass to func. |
typedef struct dl_symbol_free_s dl_symbol_free_t |
typedef struct dl_symbol_init_s dl_symbol_init_t |
|
static |
|
static |
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.
|
static |
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 | ||
) |
|
static |
Walk over the registered init callbacks, searching for the symbols they depend on.
Allows code outside of the dl API to register free functions that get executed depending on whether the dl exports a particular symbol.
This cuts down the amount of boilerplate code in 'mod_unload' functions.
[in] | dl_loader | Tree of dynamically loaded libraries, and callbacks. |
[in] | dl | to search for symbols in. |
Definition at line 279 of file dl.c.
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.
|
static |
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.
|
static |