Skip to main content

Crate dlopen_rs

Crate dlopen_rs 

Source
Expand description

A Rust library that implements a series of interfaces such as dlopen and dlsym, consistent with the behavior of libc, providing robust support for dynamic library loading and symbol resolution.

This library serves four purposes:

  1. Provide a pure Rust alternative to musl ld.so or glibc ld.so.
  2. Provide loading ELF dynamic libraries support for #![no_std] targets.
  3. Easily swap out symbols in shared libraries with your own custom symbols at runtime
  4. Faster than ld.so in most cases (loading dynamic libraries and getting symbols)

Currently, it supports x86_64, RV64, and AArch64 architectures.

§Examples


fn main(){
    let path = "./target/release/libexample.so";
    let libexample = ElfLibrary::dlopen(path, OpenFlags::RTLD_LOCAL | OpenFlags::RTLD_LAZY).unwrap();

    let add = unsafe {
        libexample.get::<fn(i32, i32) -> i32>("add").unwrap()
    };
    println!("{}", add(1,1));
}

Re-exports§

pub use crate::api::dlsym::dlsym_default;
pub use crate::api::dlsym::dlsym_next;

Modules§

api
c interface

Macros§

lock_read
lock_write

Structs§

ElfLibrary
Represents a successfully loaded and relocated dynamic library.
OpenFlags
Flags that control how dynamic libraries are loaded and resolved.
Symbol
A typed symbol retrieved from a loaded ELF module.

Enums§

Error
Errors that can occur during dynamic library loading or symbol resolution.

Traits§

AsFilename

Type Aliases§

Result