diff options
author | Sven Gothel <[email protected]> | 2021-01-25 01:28:36 +0100 |
---|---|---|
committer | Sven Gothel <[email protected]> | 2021-01-25 01:28:36 +0100 |
commit | b371af6d83e0fb94cba02ec6c2837bf58c2eea39 (patch) | |
tree | 48999c7e269409ebe389e5d5e72ca141d8b9eea7 /java_jni/jni/jau/UnixDynamicLinkerImpl_JNI.cxx | |
parent | 1ba932716f2d382af56bf8ea69a57666e2c835d6 (diff) |
Java import and modularization: jaulib_base, jaulib_jni, jaulib_net, jaulib_pkg (WIP)
Diffstat (limited to 'java_jni/jni/jau/UnixDynamicLinkerImpl_JNI.cxx')
-rw-r--r-- | java_jni/jni/jau/UnixDynamicLinkerImpl_JNI.cxx | 138 |
1 files changed, 138 insertions, 0 deletions
diff --git a/java_jni/jni/jau/UnixDynamicLinkerImpl_JNI.cxx b/java_jni/jni/jau/UnixDynamicLinkerImpl_JNI.cxx new file mode 100644 index 0000000..9a7a57c --- /dev/null +++ b/java_jni/jni/jau/UnixDynamicLinkerImpl_JNI.cxx @@ -0,0 +1,138 @@ +/* !---- DO NOT EDIT: This file autogenerated by com\sun\gluegen\JavaEmitter.java on Mon Jul 31 16:26:59 PDT 2006 ----! */ + +#include <jni.h> + +#include <assert.h> + +#include "jau_sys_dl_UnixDynamicLinkerImpl.h" + + #include <dlfcn.h> + #include <inttypes.h> + +#ifndef RTLD_DEFAULT + #define RTLD_DEFAULT ((void *) 0) +#endif + +// #define DEBUG_DLOPEN 1 + +#ifdef DEBUG_DLOPEN + typedef void *(*DLOPEN_FPTR_TYPE)(const char *filename, int flag); + #define VERBOSE_ON 1 +#endif + +// #define VERBOSE_ON 1 + +#ifdef VERBOSE_ON + #ifdef ANDROID + #include <android/log.h> + #define DBG_PRINT(...) __android_log_print(ANDROID_LOG_DEBUG, "JogAmp", __VA_ARGS__) + #else + #define DBG_PRINT(...) fprintf(stderr, __VA_ARGS__); fflush(stderr) + #endif +#else + #define DBG_PRINT(...) +#endif + +/* + * Class: jau_sys_dl_UnixDynamicLinkerImpl + * Method: dlclose + * Signature: (J)I + */ +JNIEXPORT jint JNICALL +Java_jau_sys_dl_UnixDynamicLinkerImpl_dlclose(JNIEnv *env, jclass _unused, jlong arg0) { + (void)env; + (void)_unused; + + int _res; + _res = dlclose((void *) (intptr_t) arg0); + return _res; +} + + +/* + * Class: jau_sys_dl_UnixDynamicLinkerImpl + * Method: dlerror + * Signature: ()Ljava/lang/String; + */ +JNIEXPORT jstring JNICALL +Java_jau_sys_dl_UnixDynamicLinkerImpl_dlerror(JNIEnv *env, jclass _unused) { + (void)_unused; + + char * _res; + _res = dlerror(); + if (_res == NULL) return NULL; return env->NewStringUTF(_res); +} + +/* + * Class: jau_sys_dl_UnixDynamicLinkerImpl + * Method: dlopen + * Signature: (Ljava/lang/String;I)J + */ +JNIEXPORT jlong JNICALL +Java_jau_sys_dl_UnixDynamicLinkerImpl_dlopen(JNIEnv *env, jclass _unused, jstring arg0, jint arg1) { + (void)_unused; + + const char* _UTF8arg0 = NULL; + void * _res; +#ifdef DEBUG_DLOPEN + DLOPEN_FPTR_TYPE dlopenFunc = NULL; + DBG_PRINT("XXX dlopen.0\n"); +#endif + + if (arg0 != NULL) { + if (arg0 != NULL) { + _UTF8arg0 = env->GetStringUTFChars(arg0, (jboolean*)NULL); + if (_UTF8arg0 == NULL) { + env->ThrowNew(env->FindClass("java/lang/OutOfMemoryError"), + "Failed to get UTF-8 chars for argument \"arg0\" in native dispatcher for \"dlopen\""); + return 0; + } + } + } +#ifdef DEBUG_DLOPEN + dlopenFunc = (DLOPEN_FPTR_TYPE) dlsym(RTLD_DEFAULT, "dlopen"); + DBG_PRINT("XXX dlopen.1: lib %s, dlopen-fptr %p %p (%d)\n", _UTF8arg0, dlopen, dlopenFunc, dlopen==dlopenFunc); + _res = dlopen((char *) _UTF8arg0, (int) arg1); + DBG_PRINT("XXX dlopen.2: %p\n", _res); +#else + _res = dlopen((char *) _UTF8arg0, (int) arg1); +#endif + if (arg0 != NULL) { + env->ReleaseStringUTFChars(arg0, _UTF8arg0); + } +#ifdef DEBUG_DLOPEN + DBG_PRINT("XXX dlopen.X\n"); +#endif + return (jlong) (intptr_t) _res; +} + +/* + * Class: jau_sys_dl_UnixDynamicLinkerImpl + * Method: dlsym + * Signature: (JLjava/lang/String;)J + */ +JNIEXPORT jlong JNICALL +Java_jau_sys_dl_UnixDynamicLinkerImpl_dlsym(JNIEnv *env, jclass _unused, jlong arg0, jstring arg1) { + (void)_unused; + + const char* _UTF8arg1 = NULL; + void * _res; + if (arg1 != NULL) { + if (arg1 != NULL) { + _UTF8arg1 = env->GetStringUTFChars(arg1, (jboolean*)NULL); + if (_UTF8arg1 == NULL) { + env->ThrowNew(env->FindClass("java/lang/OutOfMemoryError"), + "Failed to get UTF-8 chars for argument \"arg1\" in native dispatcher for \"dlsym\""); + return 0; + } + } + } + _res = dlsym((void *) (intptr_t) arg0, (char *) _UTF8arg1); + DBG_PRINT("XXX dlsym: handle %p, symbol %s -> %p\n", (void *) (intptr_t) arg0, _UTF8arg1, _res); + + if (arg1 != NULL) { + env->ReleaseStringUTFChars(arg1, _UTF8arg1); + } + return (jlong) (intptr_t) _res; +} + |