-
-
Save anonymous/4feb29bbec79f9a124e0 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <assert.h> | |
#include <stdlib.h> | |
#include <dlfcn.h> | |
int main() { | |
void *lib = dlopen("./libfoo.so", RTLD_NOW | RTLD_DEEPBIND); | |
assert(lib); | |
void* (*foo_fn)(void) = dlsym(lib, "foo"); | |
assert(foo_fn); | |
void *foo_ptr = foo_fn(); | |
assert(foo_ptr); | |
free(foo_ptr); | |
void* (*bar_fn)(void) = dlsym(lib, "bar"); | |
assert(bar_fn); | |
void *bar_ptr = bar_fn(); | |
assert(bar_ptr); | |
free(bar_ptr); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
extern crate libc; | |
extern { | |
fn strdup(a: *mut u8) -> *mut u8; | |
} | |
#[no_mangle] | |
pub unsafe extern fn foo() -> *mut u8 { | |
strdup("foo\0".as_ptr() as *mut _) | |
} | |
#[no_mangle] | |
pub unsafe extern fn bar() -> *mut u8 { | |
libc::malloc(8) as *mut _ | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment