How to define a FFI LIbrary using a file handle or actual binary code, and NOT a filename?

40 views
Skip to first unread message

Rogue Wave

unread,
Sep 8, 2015, 5:57:58 PM9/8/15
to ruby-ffi
I have a weird situation, especially since I am not allowed to get into any details at all.
But I can not create a new file, nor access the file system.  I can change this one file.
So I am appending the compiled .so library to the end of a ruby file after an __END__.
I can access that binary as the DATA file handle.  So I can use that, or read from the
file handle and use that.  Is there any way to create the FFI Library using either of these?

Thanks
D Cameron Mauch

Daniel Berger

unread,
Sep 9, 2015, 9:02:27 AM9/9/15
to ruby-ffi
The fundamental problem is that dl_open only accepts a filename, not a handle.

The best answer I can find is here:

http://stackoverflow.com/questions/5053664/dlopen-from-memory (2nd answer)


In short, you'll have to use mmap and do some wiring on your own.


Regards,


Dan

Reply all
Reply to author
Forward
0 new messages