1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
//! Memory-safe bindings around the platform's dynamic library loading
//! primitives (`dlopen`/`dlsym` on Unix, `LoadLibraryExW`/`GetProcAddress` on
//! Windows).
//!
//! The central guarantee of this crate is that **a symbol can never outlive
//! the library it was loaded from** through safe code:
//!
//! - [`Symbol<'lib, T>`](Symbol) borrows its [`Library`], so the borrow checker
//! rejects dropping the library while a symbol is alive.
//! - [`ArcSymbol<T>`](ArcSymbol) keeps the library alive through an
//! [`Arc`](std::sync::Arc) for when a borrow is impractical (e.g. `'static`
//! storage), without resorting to `transmute`.
//! - Neither type hands out the raw function pointer through safe code:
//! functions are invoked through [`Symbol::call`], so the pointer cannot be
//! copied out and kept past an unload by accident.
//! - The [`library!`] macro generates a struct that owns the library together
//! with every resolved symbol, which is the shape the `dlsym-gen` tool emits
//! from C headers.
//!
//! ```no_run
//! # fn main() -> Result<(), dlsym::Error> {
//! use dlsym::Library;
//!
//! // SAFETY: libm has no unsound initialisers.
//! let libm = unsafe { Library::open("libm.so.6")? };
//! // SAFETY: `cos` has this signature in libm.
//! let cos = unsafe { libm.get::<unsafe extern "C" fn(f64) -> f64>(c"cos")? };
//! // SAFETY: `cos` is a pure function, valid for any `f64`.
//! assert_eq!(unsafe { cos.call((0.0,)) }, 1.0);
//!
//! drop(libm); // fine here; moving this above the call would not compile
//! # Ok(()) }
//! ```
pub use Error;
pub use Library;
pub use Bindings;
pub use SymbolName;
pub use ;
pub use ;
/// Convenience alias for results returned by this crate.
pub type Result<T, E = Error> = Result;