8268129: LibraryLookup::ofDefault leaks symbols from loaded libraries

Reviewed-by: jvernee, psandoz
This commit is contained in:
Maurizio Cimadamore 2021-06-04 12:53:17 +00:00
parent 40c9e258b5
commit 59a539fef1
47 changed files with 730 additions and 725 deletions

View file

@ -26,7 +26,6 @@
#include <stdlib.h>
#include <string.h>
#include <windows.h>
#include <psapi.h>
#include <locale.h>
#include "jni.h"
@ -36,31 +35,6 @@ void* getProcessHandle() {
return (void*)GetModuleHandle(NULL);
}
/*
* Windows doesn't have an RTLD_DEFAULT equivalent, so in stead we have to
* iterate over all the modules loaded by the process to implement the
* default library behaviour.
*/
void* findEntryInProcess(const char* name) {
HANDLE hProcess = GetCurrentProcess();
HMODULE hMods[1024];
DWORD cbNeeded; // array size in bytes
// first come, first served
if (EnumProcessModules(hProcess, hMods, sizeof(hMods), &cbNeeded)) {
for (size_t i = 0; i < (cbNeeded / sizeof(HMODULE)); i++) {
HMODULE mod = hMods[i];
FARPROC proc = GetProcAddress(mod, name);
if(proc != NULL) {
return proc;
}
}
}
return NULL;
}
/*
* Windows symbols can be simple like JNI_OnLoad or __stdcall format
* like _JNI_OnLoad@8. We need to handle both.