[foreign] NPE when trying to lookup a symbol in the default library when no libraries are loaded
Jorn Vernee
jbvernee at xs4all.nl
Wed Sep 12 20:35:11 UTC 2018
> Never mind I found it :)
>
> void* getDefaultHandle() {
> // FIXME: This is not yet tested on Windows.
> return getProcessHandle();
> }
And here's a possible fix [1]
This fixes 2 bugs:
1.) When no library was loaded ClassLoader#NativeLibrary#getFromClass
threw an NPE (at least on windows). That is fixed by returning
defaultLibrary.fromClass when the nativeLibraryContext is empty.
2.) The default library search was not working on windows. It was using
a default handle, which works on unix (dlsym(RTLD_DEFAULT)), but not on
windows (see https://stackoverflow.com/q/23437007). I have changed the
implementation from using a default handle to using a new native
function findEntryInProcess, which does the right thing for Windows
(iterate over all loaded modules), and does the same thing it used to
for unix. findEntry is now a Java method, and the original findEntry is
renamed to findEntry0. The NativeLibrary implementation of findEntry
forwards to findEntry0, and the anonymous class of the default library
overrides to forward to findEntryInProcess.
For future reference,
Jorn
[1] :
https://gist.github.com/JornVernee/7d45780df082cbfb27417b437c7b13a8
More information about the panama-dev
mailing list