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

use std::path::Path;

fn main(){
    dlopen_rs::init();
    let path = Path::new("./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));
}

Modules§

abi
c interface

Structs§

Dylib
An relocated dynamic library
ElfLibrary
An unrelocated dynamic library
OpenFlags
Control how dynamic libraries are loaded.
Symbol
A symbol from elf object

Enums§

Error
dlopen-rs error type

Functions§

init
init is responsible for the initialization of dlopen_rs, If you want to use the dynamic library that the program itself depends on, or want to use the debug function, please call it at the beginning. This is usually necessary.

Type Aliases§

Result