Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

dlmopen support #36

Open
SoniEx2 opened this issue Dec 9, 2017 · 9 comments
Open

dlmopen support #36

SoniEx2 opened this issue Dec 9, 2017 · 9 comments

Comments

@SoniEx2
Copy link

SoniEx2 commented Dec 9, 2017

No description provided.

@nagisa
Copy link
Owner

nagisa commented Jan 2, 2018

dlmopen seems like an awfully GNU-specific function that cannot be expressed in a manner portable between even unix targets.

I feel like it should be fine to expect people to bind this manually if they need the functionality provided by this function.

@SoniEx2
Copy link
Author

SoniEx2 commented Jan 2, 2018

While dlmopen is often considered a GNU extension, the concept is not GNU-specific.

For one, Windows' DLL APIs are equivalent to dlmopen. In addition to that, dlmopen is also available on SunOS/Solaris.

It would be nice if other systems adopted it, as it allows coexistence of, say, Python 2 and Python 3 in the same process space, but in the meantime we should do our best to provide it where available, and panic at runtime otherwise (just a better option than not allowing the library to compile at all, but this is up to you, obviously).

If it becomes popular enough, this should be enough to get other systems to support it, as you don't usually want your ports to just panic at runtime.

@nagisa
Copy link
Owner

nagisa commented Jun 17, 2019

I still have found no indication that any other UNIX targets other than the GNU-based ones have this function available. It is not available on macOS for example.

we should do our best to provide it where available, and panic at runtime otherwise (just a better option than not allowing the library to compile at all, but this is up to you, obviously).

It would be possible to provide it under gnu target_abi cfg, but in that case it is not obvious to those using unix-specific APIs that dlmopen API is not available outside of GNU. Hmmm…

@SoniEx2
Copy link
Author

SoniEx2 commented Jun 17, 2019

@nagisa
Copy link
Owner

nagisa commented Jul 9, 2019

There’re methods to convert to/from raw OS primitives in 0.5.2 so you can dlmopen things manually and produce Library out of that.

@aidancully
Copy link

There’re methods to convert to/from raw OS primitives in 0.5.2 so you can dlmopen things manually and produce Library out of that.

I've done that in a local project... Any chance to expose some of your dlerror functionality, so that I can re-use the same mechanisms as you have if dlmopen fails?

@nagisa
Copy link
Owner

nagisa commented Feb 26, 2021

I wouldn't be opposed to exposing with_dlerror and a similar function for Windows in some shape or form, but some thought and changes will be necessary to make the API more suitable for pub.

@ileixe
Copy link

ileixe commented Feb 26, 2024

We've got this requirement unfortunately... 😇 Is there viable workaround here? Can you locate how you overcome @aidancully ?

+        let name = CString::new(library).expect("invalid library name");
+        let pointer = unsafe { libc::dlmopen(LM_ID_NEWLM, name.as_ptr(), RTLD_LAZY | RTLD_LOCAL) };
+
+        if pointer.is_null() {
+              // I'm ignoring error here 
+        }
+
         let library = Rc::new(unsafe {
-            sys::MyLibrary::new(library)?,
+            sys::MyLibrary::from_library(Library::from(unix::Library::from_raw(pointer)))
         });

I followed what you meant. with_dlerror seems to be enough to use the API.

@nagisa
Copy link
Owner

nagisa commented Mar 1, 2024

I'll make with_dlerror public in #139. You should be able to write your code with proper error handling in place shortly (once I release 0.8.2)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants