feat(dlfcn): define RTLD_DEFAULT
Signed-off-by: Anhad Singh <andypython@protonmail.com>
This commit is contained in:
@@ -21,13 +21,12 @@ use crate::{
|
||||
|
||||
pub const RTLD_LAZY: c_int = 1 << 0;
|
||||
pub const RTLD_NOW: c_int = 1 << 1;
|
||||
// FIXME(andypython):
|
||||
// #ifdef _GNU_SOURCE
|
||||
pub const RTLD_NOLOAD: c_int = 1 << 2;
|
||||
// #endif
|
||||
pub const RTLD_GLOBAL: c_int = 1 << 8;
|
||||
pub const RTLD_LOCAL: c_int = 0x0000;
|
||||
|
||||
pub const RTLD_DEFAULT: *mut c_void = 0 as *mut c_void; // XXX: cbindgen doesn't like ptr::null_mut()
|
||||
|
||||
static ERROR_NOT_SUPPORTED: CStr = c_str!("dlfcn not supported");
|
||||
|
||||
#[thread_local]
|
||||
|
||||
+23
-28
@@ -4,40 +4,35 @@
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
// FIXME(andpython): should be defined in dlfcn.h
|
||||
#ifndef RTLD_DEFAULT
|
||||
#define RTLD_DEFAULT NULL
|
||||
#endif
|
||||
|
||||
int main(void) {
|
||||
void *handle = dlopen("libfoobar.so", RTLD_LAZY | RTLD_LOCAL);
|
||||
if (!handle) {
|
||||
printf("dlopen(libfoobar.so): %s\n", dlerror());
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
void *handle = dlopen("libfoobar.so", RTLD_LAZY | RTLD_LOCAL);
|
||||
if (!handle) {
|
||||
printf("dlopen(libfoobar.so): %s\n", dlerror());
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
|
||||
assert(dlsym(handle, "BAR") != NULL);
|
||||
assert(dlsym(handle, "FOO") != NULL);
|
||||
// not in the global scope
|
||||
assert(dlsym(RTLD_DEFAULT, "BAR") == NULL);
|
||||
assert(dlsym(RTLD_DEFAULT, "FOO") == NULL);
|
||||
assert(dlsym(handle, "BAR") != NULL);
|
||||
assert(dlsym(handle, "FOO") != NULL);
|
||||
// not in the global scope
|
||||
assert(dlsym(RTLD_DEFAULT, "BAR") == NULL);
|
||||
assert(dlsym(RTLD_DEFAULT, "FOO") == NULL);
|
||||
|
||||
void *self = dlopen(NULL, RTLD_LAZY | RTLD_LOCAL);
|
||||
if (!self) {
|
||||
printf("dlopen(NULL): %s\n", dlerror());
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
void *self = dlopen(NULL, RTLD_LAZY | RTLD_LOCAL);
|
||||
if (!self) {
|
||||
printf("dlopen(NULL): %s\n", dlerror());
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
|
||||
assert(dlsym(self, "FOO") == NULL);
|
||||
assert(dlsym(self, "BAR") == NULL);
|
||||
assert(dlsym(self, "FOO") == NULL);
|
||||
assert(dlsym(self, "BAR") == NULL);
|
||||
|
||||
assert(dlclose(self) == 0);
|
||||
assert(dlclose(self) == 0);
|
||||
|
||||
// Promote the library to the global scope.
|
||||
assert(dlopen("libfoobar.so", /* RTLD_NOLOAD |*/ RTLD_NOW | RTLD_GLOBAL));
|
||||
// Promote the library to the global scope.
|
||||
assert(dlopen("libfoobar.so", /* RTLD_NOLOAD |*/ RTLD_NOW | RTLD_GLOBAL));
|
||||
|
||||
assert(dlsym(RTLD_DEFAULT, "FOO") != NULL);
|
||||
assert(dlsym(RTLD_DEFAULT, "BAR") != NULL);
|
||||
assert(dlsym(RTLD_DEFAULT, "FOO") != NULL);
|
||||
assert(dlsym(RTLD_DEFAULT, "BAR") != NULL);
|
||||
|
||||
return EXIT_SUCCESS;
|
||||
return EXIT_SUCCESS;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user