mirror of
https://github.com/openjdk/jdk.git
synced 2025-08-28 23:34:52 +02:00
8254231: Implementation of Foreign Linker API (Incubator)
Reviewed-by: coleenp, ihse, dholmes, vlivanov
This commit is contained in:
parent
53f38353e0
commit
0fb31dbf3a
212 changed files with 67390 additions and 179 deletions
|
@ -26,6 +26,7 @@
|
|||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <windows.h>
|
||||
#include <psapi.h>
|
||||
#include <locale.h>
|
||||
|
||||
#include "jni.h"
|
||||
|
@ -35,6 +36,31 @@ 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 (int 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.
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue