From 1ffd7187ef8ddfd3ae4975d718a27fb1ed9c863b Mon Sep 17 00:00:00 2001 From: Anhad Singh Date: Wed, 25 Dec 2024 19:27:31 +1100 Subject: [PATCH] feat(dlfcn): define RTLD_DEFAULT Signed-off-by: Anhad Singh --- src/header/dlfcn/mod.rs | 5 ++-- tests/dlopen_scopes.c | 51 +++++++++++++++++++---------------------- 2 files changed, 25 insertions(+), 31 deletions(-) diff --git a/src/header/dlfcn/mod.rs b/src/header/dlfcn/mod.rs index 324b3ba303..e1230c7dcd 100644 --- a/src/header/dlfcn/mod.rs +++ b/src/header/dlfcn/mod.rs @@ -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] diff --git a/tests/dlopen_scopes.c b/tests/dlopen_scopes.c index d639bfba53..3d8de7d74c 100644 --- a/tests/dlopen_scopes.c +++ b/tests/dlopen_scopes.c @@ -4,40 +4,35 @@ #include #include -// 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; }