diff options
author | Sven Gothel <[email protected]> | 2023-11-26 09:49:12 +0100 |
---|---|---|
committer | Sven Gothel <[email protected]> | 2023-11-26 09:49:12 +0100 |
commit | c7efca6d9b0db7305f5352ebf15d915ae5a1fa24 (patch) | |
tree | 7ba72733c9296aea5ea339b3fd81d264b49d3e8c /src/native | |
parent | aea14464d521dca28165498ffe943ef1122fc2e3 (diff) |
Bug 1479: NativeLibrary: Add getNativeLibraryPath() returning queried used native library path, supported throughout DynamicLibraryBundle[Info]
Motivation: It is helpful to retrieve the actually used native library pathname,
since loading a library w/o absolute path but lookup through LD_LIBRARY_PATH
may render it hard for the user to determine which library is used.
+++
+++
Windows implementation simply can use GetModuleFileNameA() with the native library handle.
POSIX implementation may utilize a symbol-name to retrieve its address within the
loading native library used to retrieved the library information
via dladdr().
To support this feature throughout DynamicLibraryBundle and DynamicLibraryBundleInfo,
the custom DynamicLibraryBundleInfo specializations shall provide
optional symbol-names per each tool-library-name for the POSIX implementation,
see above.
public interface DynamicLibraryBundleInfo {
...
/**
* Returns optional list of optional symbol names per {@link #getToolLibNames()}
* in same order for an OS which requires the symbol's address to retrieve
* the path of the containing library.
*/
public List<String> getSymbolForToolLibPath();
...
}
Diffstat (limited to 'src/native')
-rw-r--r-- | src/native/unix/UnixDynamicLinkerImpl_JNI.c | 29 | ||||
-rw-r--r-- | src/native/windows/WindowsDynamicLinkerImpl_JNI.c | 16 |
2 files changed, 42 insertions, 3 deletions
diff --git a/src/native/unix/UnixDynamicLinkerImpl_JNI.c b/src/native/unix/UnixDynamicLinkerImpl_JNI.c index d818b3e..844002f 100644 --- a/src/native/unix/UnixDynamicLinkerImpl_JNI.c +++ b/src/native/unix/UnixDynamicLinkerImpl_JNI.c @@ -1,14 +1,22 @@ /* !---- DO NOT EDIT: This file autogenerated by com\sun\gluegen\JavaEmitter.java on Mon Jul 31 16:26:59 PDT 2006 ----! */ +#if defined(_WIN32) + // NOP +#elif defined(__linux__) + #define _GNU_SOURCE +#else + // NOP +#endif + +#include <dlfcn.h> +#include <inttypes.h> + #include <jni.h> #include <assert.h> #include "jogamp_common_os_UnixDynamicLinkerImpl.h" - #include <dlfcn.h> - #include <inttypes.h> - #ifndef RTLD_DEFAULT #define RTLD_DEFAULT ((void *) 0) #endif @@ -127,3 +135,18 @@ Java_jogamp_common_os_UnixDynamicLinkerImpl_dlsym(JNIEnv *env, jclass _unused, j return (jlong) (intptr_t) _res; } +/* + * Class: jogamp_common_os_UnixDynamicLinkerImpl + * Method: dladdr_fname + * Signature: (J)Ljava/lang/String; + */ +JNIEXPORT jstring JNICALL +Java_jogamp_common_os_UnixDynamicLinkerImpl_dladdr_1fname(JNIEnv *env, jclass _unused, jlong arg0) { + Dl_info info; + if( 0 != dladdr((void *) (intptr_t) arg0, &info) && NULL != info.dli_fname ) { + return (*env)->NewStringUTF(env, info.dli_fname); + } else { + return NULL; + } +} + diff --git a/src/native/windows/WindowsDynamicLinkerImpl_JNI.c b/src/native/windows/WindowsDynamicLinkerImpl_JNI.c index ef94bb0..1874b30 100644 --- a/src/native/windows/WindowsDynamicLinkerImpl_JNI.c +++ b/src/native/windows/WindowsDynamicLinkerImpl_JNI.c @@ -94,4 +94,20 @@ Java_jogamp_common_os_WindowsDynamicLinkerImpl_LoadLibraryW(JNIEnv *env, jclass return (jlong) (intptr_t) _res; } +/* + * Class: jogamp_common_os_WindowsDynamicLinkerImpl + * Method: GetModuleFileNameA + * Signature: (J)Ljava/lang/String; + */ +JNIEXPORT jstring JNICALL +Java_jogamp_common_os_WindowsDynamicLinkerImpl_GetModuleFileNameA(JNIEnv *env, jclass _unused, jlong hModule) { + TCHAR tpath[PATH_MAX+1]; + memset(tpath, 0, PATH_MAX+1); + DWORD size = GetModuleFileNameA((HANDLE) (intptr_t) hModule, (LPTSTR)&tpath, PATH_MAX); + if( 0 == size ) { + return NULL; + } + return (*env)->NewStringUTF(env, tpath); +} + |