pub struct ElfLibrary { /* private fields */ }Expand description
Represents a successfully loaded and relocated dynamic library.
This is the primary interface for interacting with a loaded library, providing methods to look up symbols and inspect metadata.
Implementations§
Source§impl ElfLibrary
impl ElfLibrary
Source§impl ElfLibrary
impl ElfLibrary
Source§impl ElfLibrary
impl ElfLibrary
Sourcepub fn this() -> ElfLibrary
pub fn this() -> ElfLibrary
Get the main executable as an ElfLibrary. It is the same as dlopen(NULL, RTLD_NOW).
Sourcepub fn dlopen(path: impl AsFilename, flags: OpenFlags) -> Result<ElfLibrary>
pub fn dlopen(path: impl AsFilename, flags: OpenFlags) -> Result<ElfLibrary>
Load a shared library from a specified path. It is the same as dlopen.
§Example
let path = "/path/to/library.so";
let lib = ElfLibrary::dlopen(path, OpenFlags::RTLD_LOCAL).expect("Failed to load library");Sourcepub fn dlopen_from_binary(
bytes: &[u8],
path: impl AsFilename,
flags: OpenFlags,
) -> Result<ElfLibrary>
pub fn dlopen_from_binary( bytes: &[u8], path: impl AsFilename, flags: OpenFlags, ) -> Result<ElfLibrary>
Load a shared library from bytes. It is the same as dlopen. However, it can also be used in the no_std environment, and it will look for dependent libraries in those manually opened dynamic libraries.
Source§impl ElfLibrary
impl ElfLibrary
Sourcepub fn flags(&self) -> OpenFlags
pub fn flags(&self) -> OpenFlags
Get the current flags of the dynamic library from the global registry.
Sourcepub fn mapped_len(&self) -> usize
pub fn mapped_len(&self) -> usize
Gets the memory length of the elf object map.
Sourcepub fn needed_libs(&self) -> &[String]
pub fn needed_libs(&self) -> &[String]
Get the needed libs’ name of the elf object.
Sourcepub unsafe fn get<'lib, T>(&'lib self, name: &str) -> Result<Symbol<'lib, T>>
pub unsafe fn get<'lib, T>(&'lib self, name: &str) -> Result<Symbol<'lib, T>>
Get a pointer to a function or static variable by symbol name.
The symbol is interpreted as-is; no mangling is done. This means that symbols like x::y are
most likely invalid.
§Safety
Users of this API must specify the correct type of the function or variable loaded.
§Examples
unsafe {
let awesome_function: Symbol<unsafe extern fn(f64) -> f64> =
lib.get("awesome_function").unwrap();
awesome_function(0.42);
}A static variable may also be loaded and inspected:
unsafe {
let awesome_variable: Symbol<*mut f64> = lib.get("awesome_variable").unwrap();
**awesome_variable = 42.0;
};Trait Implementations§
Source§impl Clone for ElfLibrary
impl Clone for ElfLibrary
Source§fn clone(&self) -> ElfLibrary
fn clone(&self) -> ElfLibrary
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more