Skip to content

Instantly share code, notes, and snippets.

@geofft
Last active August 29, 2015 14:21
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save geofft/e22e9e4b72eb460359a5 to your computer and use it in GitHub Desktop.
Save geofft/e22e9e4b72eb460359a5 to your computer and use it in GitHub Desktop.
Rust-ABI calls across dynamic libraries
#![crate_type="dylib"]
#[no_mangle]
pub fn foo(x: std::fmt::Arguments) -> i32 {
println!("{:?}", x);
3
}
#[link(name="dl")]
extern {
fn dlopen(filename: *const u8, flags: isize) -> *const u8;
fn dlsym(handle: *const u8, symbol: *const u8) -> *const u8;
}
fn main() {
let eggman = unsafe { dlopen(b"${ORIGIN}/libeggman.so\0" as *const _, 2) };
let foo: fn(x: std::fmt::Arguments) -> i32 = unsafe {
std::mem::transmute(dlsym(eggman, b"foo\0" as *const _))
};
println!("{}", foo(format_args!("{}", 17)));
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment