Is it possible to dynamically load a @safe function from a shared library ?
Steven Schveighoffer
schveiguy at gmail.com
Fri Mar 13 20:31:16 UTC 2020
On 3/13/20 4:22 PM, wjoe wrote:
> I wasn't aware that pragma(mangle, ..) can practically name any function
> anything. So from what I understand, because, at least on Posix, since
> there's only a symbol name there's nothing I can do in my loader to
> verify that a function is or does what it claim to be/do.
But that's the same as the linker anyway. It's possible to stub the
function as @safe, but implement it as @system and just pragma(mangle)
the thing. Therefore the compiler is no safer.
I would expect that something could be written to turn a signature
string into a mangling and also provide the correct type upon return.
Something like:
auto f = getFunction!(@safe void function(int))("package.module.symbol");
and have it properly mangle the expected function name and pull it from
the dynamic library.
-Steve
More information about the Digitalmars-d-learn
mailing list