[Vm-dev] using FFI to load symbols?

Eliot Miranda eliot.miranda at gmail.com
Wed Aug 26 18:05:10 UTC 2015


Hi Esteban,

On Wed, Aug 26, 2015 at 7:57 AM, Esteban Lorenzano <estebanlm at gmail.com>
wrote:

>
> Hi,
>
> I’m trying to access symbols through FFI (like, for instance, to access
> char **environ variable from libc).
> I know the vm has implemented
>
>
> ioLoadModule: moduleNameIndex OfLength: moduleNameLength
> ioLoadSymbol: functionNameIndex OfLength: functionNameLength FromModule:
> moduleHandle
>
> … but well, since this functions are implemented inside the executable and
> not in an external module, I cannot access them through a regular FFI call.
>

Well you can/  They are just interfaces to dlsym et al on Unix and
GetProcAddress on WIndows.  They have the advantage that they're portable.
Why would you want to access them through an FFI call?  Don't you just want
a primitive interface? See e.g. the ALien (IA32ABI) primitive interface:

/*  Attempt to find the address of a symbol in a loaded library.
    The primitive can have a signature either of the form:
    <Anywhere> primInLibrary: libraryHandle <Alien> findSymbol: symbolName
    <String> ^<Integer>
    <primitive: 'primInLibraryFindSymbol' error: errorCode module:
'IA32ABI'>
    or:
    libraryHandle <Alien> primFindSymbol: symbolName <String> ^<Integer>
    <primitive: 'primInLibraryFindSymbol' error: errorCode module:
'IA32ABI'> */

    /* IA32ABIPlugin>>#primInLibraryFindSymbol */


> I suppose this can be like that because of security reasons, but I really
> need them (this is part of my effort to provide a replacement to
> NativeBoost on Pharo)… I really want to go back to use the FFI Plugin.
>

Right.  So either use the Alien interface or copy the Alien primitives into
the FFI plugin.


>
> Is there a way to do this?
> If not, would you agree if I add a primitive “loadSymbol:fromModule:” to
> ThreadedFFIPlugin? (I know, I could fork it, but I’m really trying to get
> aligned with the current implementation of the VM and I do not want to
> start again with the problem :P)
>

Yes.  Of course.



>
> thanks!
> Esteban




-- 
_,,,^..^,,,_
best, Eliot
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.squeakfoundation.org/pipermail/vm-dev/attachments/20150826/2db6201f/attachment-0001.htm


More information about the Vm-dev mailing list