33
34 #include "j2secmod.h"
35
36 void *findFunction(JNIEnv *env, jlong jHandle, const char *functionName) {
37 void *hModule = (void*)jlong_to_ptr(jHandle);
38 void *fAddress = dlsym(hModule, functionName);
39 if (fAddress == NULL) {
40 char errorMessage[256];
41 snprintf(errorMessage, sizeof(errorMessage), "Symbol not found: %s", functionName);
42 JNU_ThrowNullPointerException(env, errorMessage);
43 return NULL;
44 }
45 return fAddress;
46 }
47
48 JNIEXPORT jlong JNICALL Java_sun_security_pkcs11_Secmod_nssGetLibraryHandle
49 (JNIEnv *env, jclass thisClass, jstring jLibName)
50 {
51 const char *libName = (*env)->GetStringUTFChars(env, jLibName, NULL);
52 // look up existing handle only, do not load
53 void *hModule = dlopen(libName, RTLD_NOLOAD);
54 dprintf2("-handle for %s: %u\n", libName, hModule);
55 (*env)->ReleaseStringUTFChars(env, jLibName, libName);
56 return ptr_to_jlong(hModule);
57 }
58
59 JNIEXPORT jlong JNICALL Java_sun_security_pkcs11_Secmod_nssLoadLibrary
60 (JNIEnv *env, jclass thisClass, jstring jLibName)
61 {
62 void *hModule;
63 const char *libName = (*env)->GetStringUTFChars(env, jLibName, NULL);
64
65 dprintf1("-lib %s\n", libName);
66 hModule = dlopen(libName, RTLD_LAZY);
67 (*env)->ReleaseStringUTFChars(env, jLibName, libName);
68 dprintf2("-handle: %u (0X%X)\n", hModule, hModule);
69
70 if (hModule == NULL) {
71 JNU_ThrowIOException(env, dlerror());
72 return 0;
73 }
|
33
34 #include "j2secmod.h"
35
36 void *findFunction(JNIEnv *env, jlong jHandle, const char *functionName) {
37 void *hModule = (void*)jlong_to_ptr(jHandle);
38 void *fAddress = dlsym(hModule, functionName);
39 if (fAddress == NULL) {
40 char errorMessage[256];
41 snprintf(errorMessage, sizeof(errorMessage), "Symbol not found: %s", functionName);
42 JNU_ThrowNullPointerException(env, errorMessage);
43 return NULL;
44 }
45 return fAddress;
46 }
47
48 JNIEXPORT jlong JNICALL Java_sun_security_pkcs11_Secmod_nssGetLibraryHandle
49 (JNIEnv *env, jclass thisClass, jstring jLibName)
50 {
51 const char *libName = (*env)->GetStringUTFChars(env, jLibName, NULL);
52 // look up existing handle only, do not load
53 #if defined(AIX)
54 void *hModule = dlopen(libName, RTLD_LAZY);
55 #else
56 void *hModule = dlopen(libName, RTLD_NOLOAD);
57 #endif
58 dprintf2("-handle for %s: %u\n", libName, hModule);
59 (*env)->ReleaseStringUTFChars(env, jLibName, libName);
60 return ptr_to_jlong(hModule);
61 }
62
63 JNIEXPORT jlong JNICALL Java_sun_security_pkcs11_Secmod_nssLoadLibrary
64 (JNIEnv *env, jclass thisClass, jstring jLibName)
65 {
66 void *hModule;
67 const char *libName = (*env)->GetStringUTFChars(env, jLibName, NULL);
68
69 dprintf1("-lib %s\n", libName);
70 hModule = dlopen(libName, RTLD_LAZY);
71 (*env)->ReleaseStringUTFChars(env, jLibName, libName);
72 dprintf2("-handle: %u (0X%X)\n", hModule, hModule);
73
74 if (hModule == NULL) {
75 JNU_ThrowIOException(env, dlerror());
76 return 0;
77 }
|