rlib
Convenience library for useful things
Loading...
Searching...
No Matches
Dynamic modules

Open shared libraries at runtime, resolve exported symbols and walk named sections. More...

Typedefs

typedef rpointer RMODULE
 Opaque module handle returned by r_module_open.
 

Enumerations

enum  RModuleError { R_MODULE_ERROR_OK = 0 , R_MODULE_ERROR_NOT_FOUND }
 Result of r_module_open. More...
 

Functions

RMODULE r_module_open (const rchar *path, rboolean lazy, RModuleError *err)
 Open the shared library at path.
 
rpointer r_module_lookup (RMODULE mod, const rchar *sym)
 Resolve symbol sym in mod.
 
void r_module_close (RMODULE mod)
 Close mod and release any backing OS resources.
 
rpointer r_module_find_section (RMODULE mod, const rchar *name, rssize nsize, rsize *secsize)
 Locate a named section within mod's loaded image.
 

Detailed Description

Open shared libraries at runtime, resolve exported symbols and walk named sections.

The implementation maps onto dlopen / dlsym / dlclose on Unix and LoadLibrary / GetProcAddress / FreeLibrary on Windows.

Enumeration Type Documentation

◆ RModuleError

Result of r_module_open.

Enumerator
R_MODULE_ERROR_OK 

Module loaded successfully.

R_MODULE_ERROR_NOT_FOUND 

File missing or could not be loaded.

Function Documentation

◆ r_module_find_section()

rpointer r_module_find_section ( RMODULE  mod,
const rchar *  name,
rssize  nsize,
rsize *  secsize 
)

Locate a named section within mod's loaded image.

Useful for embedding read-only data tables and reaching them by section name (e.g. ELF .rodata.foo, Mach-O __DATA,foo, PE .rdata$foo) without exporting a symbol.

Parameters
modModule handle.
nameSection name.
nsizeLength of name in bytes, or -1 for strlen.
secsizeOut-pointer that receives the section's byte size.
Returns
Pointer to the section's start, or NULL if absent.

◆ r_module_lookup()

rpointer r_module_lookup ( RMODULE  mod,
const rchar *  sym 
)

Resolve symbol sym in mod.

Returns
Pointer to the symbol's address, or NULL if unresolved.

◆ r_module_open()

RMODULE r_module_open ( const rchar *  path,
rboolean  lazy,
RModuleError *  err 
)

Open the shared library at path.

Parameters
pathFilesystem path to a .so / .dylib / .dll.
lazyTRUE for lazy symbol binding (RTLD_LAZY), FALSE for eager (RTLD_NOW).
errOptional out-pointer that receives a RModuleError code.
Returns
Module handle on success, NULL on failure (see err).