diff --git a/make/com/sun/security/auth/module/Makefile b/make/com/sun/security/auth/module/Makefile index c274fac637a48832690b8554e233e3f149420e62..2f6aabab01d458057c55dc54c0f446e0619a0b78 100644 --- a/make/com/sun/security/auth/module/Makefile +++ b/make/com/sun/security/auth/module/Makefile @@ -78,7 +78,3 @@ endif # linux # include $(BUILDDIR)/common/Library.gmk -# -# JVMDI implementation lives in the VM. -# -OTHER_LDLIBS = $(JVMLIB) diff --git a/make/common/Defs.gmk b/make/common/Defs.gmk index e46aedeffe1431033f9a656f11cd91412fe8ef54..99d1ed1a69ec879039c0da279f14687bc3f69b10 100644 --- a/make/common/Defs.gmk +++ b/make/common/Defs.gmk @@ -220,14 +220,30 @@ JDK_LOCALES = ja zh_CN JRE_NONEXIST_LOCALES = en en_US de_DE es_ES fr_FR it_IT ja_JP ko_KR sv_SE zh # -# All libraries except libjava and libjvm itself link against libjvm and -# libjava, the latter for its exported common utilities. libjava only links -# against libjvm. Programs' makefiles take their own responsibility for +# For now, most libraries except libjava and libjvm itself link against libjvm +# and libjava, the latter for its exported common utilities. libjava only +# links against libjvm. Programs' makefiles take their own responsibility for # adding other libs. # +# The makefiles for these packages do not link against libjvm and libjava. +# This list will eventually go away and each Programs' makefiles +# will have to explicitly declare that they want to link to libjava/libjvm +# +NO_JAVALIB_PKGS = \ + sun.security.mscapi \ + sun.security.krb5 \ + sun.security.pkcs11 \ + sun.security.jgss \ + sun.security.jgss.wrapper \ + sun.security.ec \ + sun.security.smartcardio \ + com.sun.security.auth.module + ifdef PACKAGE # put JAVALIB first, but do not lose any platform specific values.... - LDLIBS_COMMON = $(JAVALIB) + ifeq (,$(findstring $(PACKAGE),$(NO_JAVALIB_PKGS))) + LDLIBS_COMMON = $(JAVALIB) + endif endif # PACKAGE # diff --git a/make/common/Library.gmk b/make/common/Library.gmk index 9999406b71864ae12b613fef698248a1aec0f068..6c9b97997ce45b7cc8cdc8c8e112e81b162aad83 100644 --- a/make/common/Library.gmk +++ b/make/common/Library.gmk @@ -165,7 +165,7 @@ $(ACTUAL_LIBRARY):: $(OBJDIR)/$(LIBRARY).lcf $(LINK) -dll -out:$(OBJDIR)/$(@F) \ -map:$(OBJDIR)/$(LIBRARY).map \ $(LFLAGS) @$(OBJDIR)/$(LIBRARY).lcf \ - $(OTHER_LCF) $(JAVALIB) $(LDLIBS) + $(OTHER_LCF) $(LDLIBS) $(CP) $(OBJDIR)/$(@F) $@ @$(call binary_file_verification,$@) $(CP) $(OBJDIR)/$(LIBRARY).map $(@D) diff --git a/make/sun/security/ec/Makefile b/make/sun/security/ec/Makefile index 4c95e33bde73346ec36381f6aba16712bfc9d491..146a24e7a9b1e5306a267145aef3c9ef813a2970 100644 --- a/make/sun/security/ec/Makefile +++ b/make/sun/security/ec/Makefile @@ -192,10 +192,8 @@ ifeq ($(NATIVE_ECC_AVAILABLE), true) # # Libraries to link # - ifeq ($(PLATFORM), windows) - OTHER_LDLIBS += $(JVMLIB) - else - OTHER_LDLIBS = -ldl $(JVMLIB) $(LIBCXX) + ifneq ($(PLATFORM), windows) + OTHER_LDLIBS = $(LIBCXX) endif include $(BUILDDIR)/common/Mapfile-vers.gmk diff --git a/make/sun/security/jgss/wrapper/Makefile b/make/sun/security/jgss/wrapper/Makefile index c7c0a6a1672d5e700ca29c08333de437ba845073..fead6e2e8d16fdb0aba5322d9df0146b9d167cef 100644 --- a/make/sun/security/jgss/wrapper/Makefile +++ b/make/sun/security/jgss/wrapper/Makefile @@ -72,5 +72,6 @@ include $(BUILDDIR)/common/Library.gmk # Libraries to link # ifneq ($(PLATFORM), windows) - OTHER_LDLIBS = -ldl $(JVMLIB) + OTHER_LDLIBS = -ldl endif + diff --git a/make/sun/security/krb5/Makefile b/make/sun/security/krb5/Makefile index 3b6d4f62046ce957e6a5664929cf74a36b298969..848a694b7b534137d1a554afd250ea2a4697e96f 100644 --- a/make/sun/security/krb5/Makefile +++ b/make/sun/security/krb5/Makefile @@ -69,15 +69,6 @@ else include $(BUILDDIR)/common/Classes.gmk endif # PLATFORM -# -# Libraries to link -# -ifeq ($(PLATFORM), windows) - OTHER_LDLIBS = $(JVMLIB) -else - OTHER_LDLIBS = -ldl $(JVMLIB) -endif - build: ifeq ($(PLATFORM),windows) $(call make-launcher, kinit, sun.security.krb5.internal.tools.Kinit, , ) diff --git a/make/sun/security/mscapi/Makefile b/make/sun/security/mscapi/Makefile index 405941fe7bad6ec73dd2319a7937cd98260855d3..389d5a1a01644bcfbcdf125e3afb5c1b1accca00 100644 --- a/make/sun/security/mscapi/Makefile +++ b/make/sun/security/mscapi/Makefile @@ -159,7 +159,7 @@ include $(BUILDDIR)/common/Library.gmk # Libraries to link # ifeq ($(PLATFORM), windows) - OTHER_LDLIBS += $(JVMLIB) Crypt32.Lib + OTHER_LDLIBS += Crypt32.Lib endif # diff --git a/make/sun/security/pkcs11/Makefile b/make/sun/security/pkcs11/Makefile index 2d59f13a01820339e48804f59ec1df9d9ad61a3d..04057765a36b92e4180ef701510446ef0d95cac3 100644 --- a/make/sun/security/pkcs11/Makefile +++ b/make/sun/security/pkcs11/Makefile @@ -159,10 +159,8 @@ include $(BUILDDIR)/common/Library.gmk # # Libraries to link # -ifeq ($(PLATFORM), windows) - OTHER_LDLIBS = $(JVMLIB) -else - OTHER_LDLIBS = -ldl $(JVMLIB) +ifneq ($(PLATFORM), windows) + OTHER_LDLIBS = -ldl endif # Other config files diff --git a/make/sun/security/smartcardio/Makefile b/make/sun/security/smartcardio/Makefile index 75b315d6f523080afef522528f3d8f69f6a16dc2..1dae7a11f165a3c1d105539b8c8e7a4b9593fdc6 100644 --- a/make/sun/security/smartcardio/Makefile +++ b/make/sun/security/smartcardio/Makefile @@ -73,8 +73,8 @@ include $(BUILDDIR)/common/Library.gmk # Libraries to link # ifeq ($(PLATFORM), windows) - OTHER_LDLIBS = $(JVMLIB) winscard.lib + OTHER_LDLIBS = winscard.lib else - OTHER_LDLIBS = -ldl $(JVMLIB) + OTHER_LDLIBS = -ldl OTHER_CFLAGS = -D__sun_jdk endif diff --git a/src/share/native/sun/security/pkcs11/wrapper/p11_convert.c b/src/share/native/sun/security/pkcs11/wrapper/p11_convert.c index c32a278b585af95335db28efe2ac94497b25f328..34080238b1b671e33d999086b9874169ee315d67 100644 --- a/src/share/native/sun/security/pkcs11/wrapper/p11_convert.c +++ b/src/share/native/sun/security/pkcs11/wrapper/p11_convert.c @@ -273,7 +273,7 @@ CK_VERSION_PTR jVersionToCKVersionPtr(JNIEnv *env, jobject jVersion) /* allocate memory for CK_VERSION pointer */ ckpVersion = (CK_VERSION_PTR) malloc(sizeof(CK_VERSION)); if (ckpVersion == NULL) { - JNU_ThrowOutOfMemoryError(env, 0); + throwOutOfMemoryError(env, 0); return NULL; } ckpVersion->major = jByteToCKByte(jMajor); @@ -326,7 +326,7 @@ CK_DATE * jDateObjectPtrToCKDatePtr(JNIEnv *env, jobject jDate) /* allocate memory for CK_DATE pointer */ ckpDate = (CK_DATE *) malloc(sizeof(CK_DATE)); if (ckpDate == NULL) { - JNU_ThrowOutOfMemoryError(env, 0); + throwOutOfMemoryError(env, 0); return NULL; } @@ -340,7 +340,7 @@ CK_DATE * jDateObjectPtrToCKDatePtr(JNIEnv *env, jobject jDate) jTempChars = (jchar*) malloc((ckLength) * sizeof(jchar)); if (jTempChars == NULL) { free(ckpDate); - JNU_ThrowOutOfMemoryError(env, 0); + throwOutOfMemoryError(env, 0); return NULL; } (*env)->GetCharArrayRegion(env, jYear, 0, ckLength, jTempChars); @@ -364,7 +364,7 @@ CK_DATE * jDateObjectPtrToCKDatePtr(JNIEnv *env, jobject jDate) jTempChars = (jchar*) malloc((ckLength) * sizeof(jchar)); if (jTempChars == NULL) { free(ckpDate); - JNU_ThrowOutOfMemoryError(env, 0); + throwOutOfMemoryError(env, 0); return NULL; } (*env)->GetCharArrayRegion(env, jMonth, 0, ckLength, jTempChars); @@ -388,7 +388,7 @@ CK_DATE * jDateObjectPtrToCKDatePtr(JNIEnv *env, jobject jDate) jTempChars = (jchar*) malloc((ckLength) * sizeof(jchar)); if (jTempChars == NULL) { free(ckpDate); - JNU_ThrowOutOfMemoryError(env, 0); + throwOutOfMemoryError(env, 0); return NULL; } (*env)->GetCharArrayRegion(env, jDay, 0, ckLength, jTempChars); @@ -558,7 +558,7 @@ CK_TLS_PRF_PARAMS jTlsPrfParamsToCKTlsPrfParam(JNIEnv *env, jobject jParam) if (ckParam.pulOutputLen == NULL) { free(ckParam.pSeed); free(ckParam.pLabel); - JNU_ThrowOutOfMemoryError(env, 0); + throwOutOfMemoryError(env, 0); return ckParam; } jByteArrayToCKByteArray(env, jOutput, &(ckParam.pOutput), ckParam.pulOutputLen); @@ -665,7 +665,7 @@ CK_SSL3_KEY_MAT_PARAMS jSsl3KeyMatParamToCKSsl3KeyMatParam(JNIEnv *env, jobject if (ckParam.pReturnedKeyMaterial == NULL) { free(ckParam.RandomInfo.pClientRandom); free(ckParam.RandomInfo.pServerRandom); - JNU_ThrowOutOfMemoryError(env, 0); + throwOutOfMemoryError(env, 0); return ckParam; } @@ -1013,7 +1013,7 @@ void jMechanismParameterToCKMechanismParameterSlow(JNIEnv *env, jobject jParam, ckpParam = (CK_SSL3_MASTER_KEY_DERIVE_PARAMS_PTR) malloc(sizeof(CK_SSL3_MASTER_KEY_DERIVE_PARAMS)); if (ckpParam == NULL) { - JNU_ThrowOutOfMemoryError(env, 0); + throwOutOfMemoryError(env, 0); return; } @@ -1040,7 +1040,7 @@ void jMechanismParameterToCKMechanismParameterSlow(JNIEnv *env, jobject jParam, ckpParam = (CK_SSL3_KEY_MAT_PARAMS_PTR) malloc(sizeof(CK_SSL3_KEY_MAT_PARAMS)); if (ckpParam == NULL) { - JNU_ThrowOutOfMemoryError(env, 0); + throwOutOfMemoryError(env, 0); return; } @@ -1067,7 +1067,7 @@ void jMechanismParameterToCKMechanismParameterSlow(JNIEnv *env, jobject jParam, ckpParam = (CK_TLS_PRF_PARAMS_PTR) malloc(sizeof(CK_TLS_PRF_PARAMS)); if (ckpParam == NULL) { - JNU_ThrowOutOfMemoryError(env, 0); + throwOutOfMemoryError(env, 0); return; } @@ -1094,7 +1094,7 @@ void jMechanismParameterToCKMechanismParameterSlow(JNIEnv *env, jobject jParam, ckpParam = (CK_AES_CTR_PARAMS_PTR) malloc(sizeof(CK_AES_CTR_PARAMS)); if (ckpParam == NULL) { - JNU_ThrowOutOfMemoryError(env, 0); + throwOutOfMemoryError(env, 0); return; } @@ -1121,7 +1121,7 @@ void jMechanismParameterToCKMechanismParameterSlow(JNIEnv *env, jobject jParam, ckpParam = (CK_RSA_PKCS_OAEP_PARAMS_PTR) malloc(sizeof(CK_RSA_PKCS_OAEP_PARAMS)); if (ckpParam == NULL) { - JNU_ThrowOutOfMemoryError(env, 0); + throwOutOfMemoryError(env, 0); return; } @@ -1148,7 +1148,7 @@ void jMechanismParameterToCKMechanismParameterSlow(JNIEnv *env, jobject jParam, ckpParam = (CK_PBE_PARAMS_PTR) malloc(sizeof(CK_PBE_PARAMS)); if (ckpParam == NULL) { - JNU_ThrowOutOfMemoryError(env, 0); + throwOutOfMemoryError(env, 0); return; } @@ -1175,7 +1175,7 @@ void jMechanismParameterToCKMechanismParameterSlow(JNIEnv *env, jobject jParam, ckpParam = (CK_PKCS5_PBKD2_PARAMS_PTR) malloc(sizeof(CK_PKCS5_PBKD2_PARAMS)); if (ckpParam == NULL) { - JNU_ThrowOutOfMemoryError(env, 0); + throwOutOfMemoryError(env, 0); return; } @@ -1202,7 +1202,7 @@ void jMechanismParameterToCKMechanismParameterSlow(JNIEnv *env, jobject jParam, ckpParam = (CK_RSA_PKCS_PSS_PARAMS_PTR) malloc(sizeof(CK_RSA_PKCS_PSS_PARAMS)); if (ckpParam == NULL) { - JNU_ThrowOutOfMemoryError(env, 0); + throwOutOfMemoryError(env, 0); return; } @@ -1229,7 +1229,7 @@ void jMechanismParameterToCKMechanismParameterSlow(JNIEnv *env, jobject jParam, ckpParam = (CK_ECDH1_DERIVE_PARAMS_PTR) malloc(sizeof(CK_ECDH1_DERIVE_PARAMS)); if (ckpParam == NULL) { - JNU_ThrowOutOfMemoryError(env, 0); + throwOutOfMemoryError(env, 0); return; } @@ -1256,7 +1256,7 @@ void jMechanismParameterToCKMechanismParameterSlow(JNIEnv *env, jobject jParam, ckpParam = (CK_ECDH2_DERIVE_PARAMS_PTR) malloc(sizeof(CK_ECDH2_DERIVE_PARAMS)); if (ckpParam == NULL) { - JNU_ThrowOutOfMemoryError(env, 0); + throwOutOfMemoryError(env, 0); return; } @@ -1283,7 +1283,7 @@ void jMechanismParameterToCKMechanismParameterSlow(JNIEnv *env, jobject jParam, ckpParam = (CK_X9_42_DH1_DERIVE_PARAMS_PTR) malloc(sizeof(CK_X9_42_DH1_DERIVE_PARAMS)); if (ckpParam == NULL) { - JNU_ThrowOutOfMemoryError(env, 0); + throwOutOfMemoryError(env, 0); return; } @@ -1310,7 +1310,7 @@ void jMechanismParameterToCKMechanismParameterSlow(JNIEnv *env, jobject jParam, ckpParam = (CK_X9_42_DH2_DERIVE_PARAMS_PTR) malloc(sizeof(CK_X9_42_DH2_DERIVE_PARAMS)); if (ckpParam == NULL) { - JNU_ThrowOutOfMemoryError(env, 0); + throwOutOfMemoryError(env, 0); return; } diff --git a/src/share/native/sun/security/pkcs11/wrapper/p11_digest.c b/src/share/native/sun/security/pkcs11/wrapper/p11_digest.c index b7288c1c84249b1f04903a2cca833411d96e3325..d33e4e206f3085c77be5fcc6d9852c0d41fccd62 100644 --- a/src/share/native/sun/security/pkcs11/wrapper/p11_digest.c +++ b/src/share/native/sun/security/pkcs11/wrapper/p11_digest.c @@ -131,7 +131,7 @@ JNIEXPORT jint JNICALL Java_sun_security_pkcs11_wrapper_PKCS11_C_1DigestSingle /* always use single part op, even for large data */ bufP = (CK_BYTE_PTR) malloc((size_t)jInLen); if (bufP == NULL) { - JNU_ThrowOutOfMemoryError(env, 0); + throwOutOfMemoryError(env, 0); return 0; } } @@ -190,7 +190,7 @@ JNIEXPORT void JNICALL Java_sun_security_pkcs11_wrapper_PKCS11_C_1DigestUpdate bufLen = min(MAX_HEAP_BUFFER_LEN, jInLen); bufP = (CK_BYTE_PTR) malloc((size_t)bufLen); if (bufP == NULL) { - JNU_ThrowOutOfMemoryError(env, 0); + throwOutOfMemoryError(env, 0); return; } } diff --git a/src/share/native/sun/security/pkcs11/wrapper/p11_dual.c b/src/share/native/sun/security/pkcs11/wrapper/p11_dual.c index 1d030c51e86cd8d1345553c111ff5c4c32164462..a76e4042f9b4b206f34aa9fe888e517d2448a71e 100644 --- a/src/share/native/sun/security/pkcs11/wrapper/p11_dual.c +++ b/src/share/native/sun/security/pkcs11/wrapper/p11_dual.c @@ -92,7 +92,7 @@ JNIEXPORT jbyteArray JNICALL Java_sun_security_pkcs11_wrapper_PKCS11_C_1DigestEn ckpEncryptedPart = (CK_BYTE_PTR) malloc(ckEncryptedPartLength * sizeof(CK_BYTE)); if (ckpEncryptedPart == NULL) { free(ckpPart); - JNU_ThrowOutOfMemoryError(env, 0); + throwOutOfMemoryError(env, 0); return NULL; } @@ -144,7 +144,7 @@ JNIEXPORT jbyteArray JNICALL Java_sun_security_pkcs11_wrapper_PKCS11_C_1DecryptD ckpPart = (CK_BYTE_PTR) malloc(ckPartLength * sizeof(CK_BYTE)); if (ckpPart == NULL) { free(ckpEncryptedPart); - JNU_ThrowOutOfMemoryError(env, 0); + throwOutOfMemoryError(env, 0); return NULL; } @@ -196,7 +196,7 @@ JNIEXPORT jbyteArray JNICALL Java_sun_security_pkcs11_wrapper_PKCS11_C_1SignEncr ckpEncryptedPart = (CK_BYTE_PTR) malloc(ckEncryptedPartLength * sizeof(CK_BYTE)); if (ckpEncryptedPart == NULL) { free(ckpPart); - JNU_ThrowOutOfMemoryError(env, 0); + throwOutOfMemoryError(env, 0); return NULL; } @@ -248,7 +248,7 @@ JNIEXPORT jbyteArray JNICALL Java_sun_security_pkcs11_wrapper_PKCS11_C_1DecryptV ckpPart = (CK_BYTE_PTR) malloc(ckPartLength * sizeof(CK_BYTE)); if (ckpPart == NULL) { free(ckpEncryptedPart); - JNU_ThrowOutOfMemoryError(env, 0); + throwOutOfMemoryError(env, 0); return NULL; } diff --git a/src/share/native/sun/security/pkcs11/wrapper/p11_general.c b/src/share/native/sun/security/pkcs11/wrapper/p11_general.c index a48c08b4db686387da1caf1bb9d9c4e7f36ab37f..14085a16213f67bffa2ad7dc3f25ca57050a4814 100644 --- a/src/share/native/sun/security/pkcs11/wrapper/p11_general.c +++ b/src/share/native/sun/security/pkcs11/wrapper/p11_general.c @@ -71,7 +71,10 @@ jfieldID mech_pParameterID; jclass jByteArrayClass; jclass jLongClass; +JavaVM* jvm = NULL; + JNIEXPORT jint JNICALL JNI_OnLoad(JavaVM *vm, void *reserved) { + jvm = vm; return JNI_VERSION_1_4; } @@ -351,7 +354,7 @@ Java_sun_security_pkcs11_wrapper_PKCS11_C_1GetSlotList ckpSlotList = (CK_SLOT_ID_PTR) malloc(ckTokenNumber * sizeof(CK_SLOT_ID)); if (ckpSlotList == NULL) { - JNU_ThrowOutOfMemoryError(env, 0); + throwOutOfMemoryError(env, 0); return NULL; } @@ -652,7 +655,7 @@ Java_sun_security_pkcs11_wrapper_PKCS11_C_1GetMechanismList ckpMechanismList = (CK_MECHANISM_TYPE_PTR) malloc(ckMechanismNumber * sizeof(CK_MECHANISM_TYPE)); if (ckpMechanismList == NULL) { - JNU_ThrowOutOfMemoryError(env, 0); + throwOutOfMemoryError(env, 0); return NULL; } diff --git a/src/share/native/sun/security/pkcs11/wrapper/p11_keymgmt.c b/src/share/native/sun/security/pkcs11/wrapper/p11_keymgmt.c index 7f987fb3c26bd4c8b84d136bae3f4cc7a7c510dd..e74230f17a61167982d7c7eec67ced871728b5ea 100644 --- a/src/share/native/sun/security/pkcs11/wrapper/p11_keymgmt.c +++ b/src/share/native/sun/security/pkcs11/wrapper/p11_keymgmt.c @@ -165,7 +165,7 @@ JNIEXPORT jlongArray JNICALL Java_sun_security_pkcs11_wrapper_PKCS11_C_1Generate if (ckMechanism.pParameter != NULL_PTR) { free(ckMechanism.pParameter); } - JNU_ThrowOutOfMemoryError(env, 0); + throwOutOfMemoryError(env, 0); return NULL; } ckpPublicKeyHandle = ckpKeyHandles; /* first element of array is Public Key */ @@ -253,7 +253,7 @@ JNIEXPORT jbyteArray JNICALL Java_sun_security_pkcs11_wrapper_PKCS11_C_1WrapKey if (ckMechanism.pParameter != NULL_PTR) { free(ckMechanism.pParameter); } - JNU_ThrowOutOfMemoryError(env, 0); + throwOutOfMemoryError(env, 0); return NULL; } diff --git a/src/share/native/sun/security/pkcs11/wrapper/p11_mutex.c b/src/share/native/sun/security/pkcs11/wrapper/p11_mutex.c index 6bc1edcd99ce1d0bc13eb916c4f706d94ec3ab39..29c80b8a799ca11dc452128d0a378756c74fcc24 100644 --- a/src/share/native/sun/security/pkcs11/wrapper/p11_mutex.c +++ b/src/share/native/sun/security/pkcs11/wrapper/p11_mutex.c @@ -92,7 +92,7 @@ CK_C_INITIALIZE_ARGS_PTR makeCKInitArgsAdapter(JNIEnv *env, jobject jInitArgs) /* convert the Java InitArgs object to a pointer to a CK_C_INITIALIZE_ARGS structure */ ckpInitArgs = (CK_C_INITIALIZE_ARGS_PTR) malloc(sizeof(CK_C_INITIALIZE_ARGS)); if (ckpInitArgs == NULL) { - JNU_ThrowOutOfMemoryError(env, 0); + throwOutOfMemoryError(env, 0); return NULL_PTR; } @@ -141,7 +141,7 @@ CK_C_INITIALIZE_ARGS_PTR makeCKInitArgsAdapter(JNIEnv *env, jobject jInitArgs) ckpGlobalInitArgs = (CK_C_INITIALIZE_ARGS_PTR) malloc(sizeof(CK_C_INITIALIZE_ARGS)); if (ckpGlobalInitArgs == NULL) { free(ckpInitArgs); - JNU_ThrowOutOfMemoryError(env, 0); + throwOutOfMemoryError(env, 0); return NULL_PTR; } @@ -178,9 +178,8 @@ CK_C_INITIALIZE_ARGS_PTR makeCKInitArgsAdapter(JNIEnv *env, jobject jInitArgs) */ CK_RV callJCreateMutex(CK_VOID_PTR_PTR ppMutex) { - JavaVM *jvm; + extern JavaVM *jvm; JNIEnv *env; - jsize actualNumberVMs; jint returnValue; jthrowable pkcs11Exception; jclass pkcs11ExceptionClass; @@ -196,8 +195,7 @@ CK_RV callJCreateMutex(CK_VOID_PTR_PTR ppMutex) /* Get the currently running Java VM */ - returnValue = JNI_GetCreatedJavaVMs(&jvm, (jsize) 1, &actualNumberVMs); - if ((returnValue != 0) || (actualNumberVMs <= 0)) { return rv ;} /* there is no VM running */ + if (jvm == NULL) { return rv ;} /* there is no VM running */ /* Determine, if current thread is already attached */ returnValue = (*jvm)->GetEnv(jvm, (void **) &env, JNI_VERSION_1_2); @@ -273,9 +271,8 @@ CK_RV callJCreateMutex(CK_VOID_PTR_PTR ppMutex) */ CK_RV callJDestroyMutex(CK_VOID_PTR pMutex) { - JavaVM *jvm; + extern JavaVM *jvm; JNIEnv *env; - jsize actualNumberVMs; jint returnValue; jthrowable pkcs11Exception; jclass pkcs11ExceptionClass; @@ -291,8 +288,7 @@ CK_RV callJDestroyMutex(CK_VOID_PTR pMutex) /* Get the currently running Java VM */ - returnValue = JNI_GetCreatedJavaVMs(&jvm, (jsize) 1, &actualNumberVMs); - if ((returnValue != 0) || (actualNumberVMs <= 0)) { return rv ; } /* there is no VM running */ + if (jvm == NULL) { return rv ; } /* there is no VM running */ /* Determine, if current thread is already attached */ returnValue = (*jvm)->GetEnv(jvm, (void **) &env, JNI_VERSION_1_2); @@ -367,9 +363,8 @@ CK_RV callJDestroyMutex(CK_VOID_PTR pMutex) */ CK_RV callJLockMutex(CK_VOID_PTR pMutex) { - JavaVM *jvm; + extern JavaVM *jvm; JNIEnv *env; - jsize actualNumberVMs; jint returnValue; jthrowable pkcs11Exception; jclass pkcs11ExceptionClass; @@ -385,8 +380,7 @@ CK_RV callJLockMutex(CK_VOID_PTR pMutex) /* Get the currently running Java VM */ - returnValue = JNI_GetCreatedJavaVMs(&jvm, (jsize) 1, &actualNumberVMs); - if ((returnValue != 0) || (actualNumberVMs <= 0)) { return rv ; } /* there is no VM running */ + if (jvm == NULL) { return rv ; } /* there is no VM running */ /* Determine, if current thread is already attached */ returnValue = (*jvm)->GetEnv(jvm, (void **) &env, JNI_VERSION_1_2); @@ -457,9 +451,8 @@ CK_RV callJLockMutex(CK_VOID_PTR pMutex) */ CK_RV callJUnlockMutex(CK_VOID_PTR pMutex) { - JavaVM *jvm; + extern JavaVM *jvm; JNIEnv *env; - jsize actualNumberVMs; jint returnValue; jthrowable pkcs11Exception; jclass pkcs11ExceptionClass; @@ -475,8 +468,7 @@ CK_RV callJUnlockMutex(CK_VOID_PTR pMutex) /* Get the currently running Java VM */ - returnValue = JNI_GetCreatedJavaVMs(&jvm, (jsize) 1, &actualNumberVMs); - if ((returnValue != 0) || (actualNumberVMs <= 0)) { return rv ; } /* there is no VM running */ + if (jvm == NULL) { return rv ; } /* there is no VM running */ /* Determine, if current thread is already attached */ returnValue = (*jvm)->GetEnv(jvm, (void **) &env, JNI_VERSION_1_2); diff --git a/src/share/native/sun/security/pkcs11/wrapper/p11_objmgmt.c b/src/share/native/sun/security/pkcs11/wrapper/p11_objmgmt.c index aea03eeba0d49b5323217cad9c166b512e2174ba..910453eacd795d06028d3b37f698eec106714e62 100644 --- a/src/share/native/sun/security/pkcs11/wrapper/p11_objmgmt.c +++ b/src/share/native/sun/security/pkcs11/wrapper/p11_objmgmt.c @@ -258,7 +258,7 @@ JNIEXPORT void JNICALL Java_sun_security_pkcs11_wrapper_PKCS11_C_1GetAttributeVa ckpAttributes[i].pValue = (void *) malloc(ckBufferLength); if (ckpAttributes[i].pValue == NULL) { freeCKAttributeArray(ckpAttributes, i); - JNU_ThrowOutOfMemoryError(env, 0); + throwOutOfMemoryError(env, 0); return; } ckpAttributes[i].ulValueLen = ckBufferLength; @@ -390,7 +390,7 @@ JNIEXPORT jlongArray JNICALL Java_sun_security_pkcs11_wrapper_PKCS11_C_1FindObje ckMaxObjectLength = jLongToCKULong(jMaxObjectCount); ckpObjectHandleArray = (CK_OBJECT_HANDLE_PTR) malloc(sizeof(CK_OBJECT_HANDLE) * ckMaxObjectLength); if (ckpObjectHandleArray == NULL) { - JNU_ThrowOutOfMemoryError(env, 0); + throwOutOfMemoryError(env, 0); return NULL; } diff --git a/src/share/native/sun/security/pkcs11/wrapper/p11_sessmgmt.c b/src/share/native/sun/security/pkcs11/wrapper/p11_sessmgmt.c index 1b7538a49a3577980849192befa3f3a99615f568..524fde013af96736004f203a4cfef0de2d0852e2 100644 --- a/src/share/native/sun/security/pkcs11/wrapper/p11_sessmgmt.c +++ b/src/share/native/sun/security/pkcs11/wrapper/p11_sessmgmt.c @@ -98,7 +98,7 @@ JNIEXPORT jlong JNICALL Java_sun_security_pkcs11_wrapper_PKCS11_C_1OpenSession if (jNotify != NULL) { notifyEncapsulation = (NotifyEncapsulation *) malloc(sizeof(NotifyEncapsulation)); if (notifyEncapsulation == NULL) { - JNU_ThrowOutOfMemoryError(env, 0); + throwOutOfMemoryError(env, 0); return 0L; } notifyEncapsulation->jApplicationData = (jApplication != NULL) @@ -301,7 +301,7 @@ JNIEXPORT jbyteArray JNICALL Java_sun_security_pkcs11_wrapper_PKCS11_C_1GetOpera ckpState = (CK_BYTE_PTR) malloc(ckStateLength); if (ckpState == NULL) { - JNU_ThrowOutOfMemoryError(env, 0); + throwOutOfMemoryError(env, 0); return NULL; } @@ -435,7 +435,7 @@ void putNotifyEntry(JNIEnv *env, CK_SESSION_HANDLE hSession, NotifyEncapsulation newNode = (NotifyListNode *) malloc(sizeof(NotifyListNode)); if (newNode == NULL) { - JNU_ThrowOutOfMemoryError(env, 0); + throwOutOfMemoryError(env, 0); return; } newNode->hSession = hSession; @@ -558,9 +558,8 @@ CK_RV notifyCallback( ) { NotifyEncapsulation *notifyEncapsulation; - JavaVM *jvm; + extern JavaVM *jvm; JNIEnv *env; - jsize actualNumberVMs; jint returnValue; jlong jSessionHandle; jlong jEvent; @@ -577,8 +576,7 @@ CK_RV notifyCallback( notifyEncapsulation = (NotifyEncapsulation *) pApplication; /* Get the currently running Java VM */ - returnValue = JNI_GetCreatedJavaVMs(&jvm, (jsize) 1, &actualNumberVMs); - if ((returnValue != 0) || (actualNumberVMs <= 0)) { return rv ; } /* there is no VM running */ + if (jvm == NULL) { return rv ; } /* there is no VM running */ /* Determine, if current thread is already attached */ returnValue = (*jvm)->GetEnv(jvm, (void **) &env, JNI_VERSION_1_2); diff --git a/src/share/native/sun/security/pkcs11/wrapper/p11_sign.c b/src/share/native/sun/security/pkcs11/wrapper/p11_sign.c index e4a43937f513b895dfd4043958adbf7e8ae6782a..e07bcf59d590b25c9e1da14179becf55ed34f604 100644 --- a/src/share/native/sun/security/pkcs11/wrapper/p11_sign.c +++ b/src/share/native/sun/security/pkcs11/wrapper/p11_sign.c @@ -132,7 +132,7 @@ JNIEXPORT jbyteArray JNICALL Java_sun_security_pkcs11_wrapper_PKCS11_C_1Sign ckpSignature = (CK_BYTE_PTR) malloc(ckSignatureLength * sizeof(CK_BYTE)); if (ckpSignature == NULL) { free(ckpData); - JNU_ThrowOutOfMemoryError(env, 0); + throwOutOfMemoryError(env, 0); return NULL; } @@ -146,7 +146,7 @@ JNIEXPORT jbyteArray JNICALL Java_sun_security_pkcs11_wrapper_PKCS11_C_1Sign ckpSignature = (CK_BYTE_PTR) malloc(256 * sizeof(CK_BYTE)); if (ckpSignature == NULL) { free(ckpData); - JNU_ThrowOutOfMemoryError(env, 0); + throwOutOfMemoryError(env, 0); return NULL; } rv = (*ckpFunctions->C_Sign)(ckSessionHandle, ckpData, ckDataLength, ckpSignature, &ckSignatureLength); @@ -156,7 +156,7 @@ JNIEXPORT jbyteArray JNICALL Java_sun_security_pkcs11_wrapper_PKCS11_C_1Sign ckpSignature = (CK_BYTE_PTR) malloc(ckSignatureLength * sizeof(CK_BYTE)); if (ckpSignature == NULL) { free(ckpData); - JNU_ThrowOutOfMemoryError(env, 0); + throwOutOfMemoryError(env, 0); return NULL; } rv = (*ckpFunctions->C_Sign)(ckSessionHandle, ckpData, ckDataLength, ckpSignature, &ckSignatureLength); @@ -210,7 +210,7 @@ JNIEXPORT void JNICALL Java_sun_security_pkcs11_wrapper_PKCS11_C_1SignUpdate bufLen = min(MAX_HEAP_BUFFER_LEN, jInLen); bufP = (CK_BYTE_PTR) malloc((size_t)bufLen); if (bufP == NULL) { - JNU_ThrowOutOfMemoryError(env, 0); + throwOutOfMemoryError(env, 0); return; } } @@ -270,7 +270,7 @@ JNIEXPORT jbyteArray JNICALL Java_sun_security_pkcs11_wrapper_PKCS11_C_1SignFina if (rv == CKR_BUFFER_TOO_SMALL) { bufP = (CK_BYTE_PTR) malloc(ckSignatureLength); if (bufP == NULL) { - JNU_ThrowOutOfMemoryError(env, 0); + throwOutOfMemoryError(env, 0); return NULL; } rv = (*ckpFunctions->C_SignFinal)(ckSessionHandle, bufP, &ckSignatureLength); @@ -355,7 +355,7 @@ JNIEXPORT jint JNICALL Java_sun_security_pkcs11_wrapper_PKCS11_C_1SignRecover } else { inBufP = (CK_BYTE_PTR) malloc((size_t)jInLen); if (inBufP == NULL) { - JNU_ThrowOutOfMemoryError(env, 0); + throwOutOfMemoryError(env, 0); return 0; } } @@ -373,7 +373,7 @@ JNIEXPORT jint JNICALL Java_sun_security_pkcs11_wrapper_PKCS11_C_1SignRecover if (inBufP != INBUF) { free(inBufP); } - JNU_ThrowOutOfMemoryError(env, 0); + throwOutOfMemoryError(env, 0); return 0; } rv = (*ckpFunctions->C_SignRecover)(ckSessionHandle, inBufP, jInLen, outBufP, &ckSignatureLength); @@ -508,7 +508,7 @@ JNIEXPORT void JNICALL Java_sun_security_pkcs11_wrapper_PKCS11_C_1VerifyUpdate bufLen = min(MAX_HEAP_BUFFER_LEN, jInLen); bufP = (CK_BYTE_PTR) malloc((size_t)bufLen); if (bufP == NULL) { - JNU_ThrowOutOfMemoryError(env, 0); + throwOutOfMemoryError(env, 0); return; } } @@ -638,7 +638,7 @@ JNIEXPORT jint JNICALL Java_sun_security_pkcs11_wrapper_PKCS11_C_1VerifyRecover } else { inBufP = (CK_BYTE_PTR) malloc((size_t)jInLen); if (inBufP == NULL) { - JNU_ThrowOutOfMemoryError(env, 0); + throwOutOfMemoryError(env, 0); return 0; } } @@ -656,7 +656,7 @@ JNIEXPORT jint JNICALL Java_sun_security_pkcs11_wrapper_PKCS11_C_1VerifyRecover outBufP = (CK_BYTE_PTR) malloc(ckDataLength); if (outBufP == NULL) { if (inBufP != INBUF) { free(inBufP); } - JNU_ThrowOutOfMemoryError(env, 0); + throwOutOfMemoryError(env, 0); return 0; } rv = (*ckpFunctions->C_VerifyRecover)(ckSessionHandle, inBufP, jInLen, outBufP, &ckDataLength); diff --git a/src/share/native/sun/security/pkcs11/wrapper/p11_util.c b/src/share/native/sun/security/pkcs11/wrapper/p11_util.c index 36a4b15943a904e116b2c03452edab70afbccb01..9436f1ece4c9dcab38323c9e3486ea590b075aae 100644 --- a/src/share/native/sun/security/pkcs11/wrapper/p11_util.c +++ b/src/share/native/sun/security/pkcs11/wrapper/p11_util.c @@ -213,28 +213,52 @@ jlong ckAssertReturnValueOK(JNIEnv *env, CK_RV returnValue) return jErrorCode ; } + /* - * This function simply throws an IOException - * - * @param env Used to call JNI funktions and to get the Exception class. - * @param message The message string of the Exception object. + * Throws a Java Exception by name + */ +void throwByName(JNIEnv *env, const char *name, const char *msg) +{ + jclass cls = (*env)->FindClass(env, name); + + if (cls != 0) /* Otherwise an exception has already been thrown */ + (*env)->ThrowNew(env, cls, msg); +} + +/* + * Throws java.lang.OutOfMemoryError + */ +void throwOutOfMemoryError(JNIEnv *env, const char *msg) +{ + throwByName(env, "java/lang/OutOfMemoryError", msg); +} + +/* + * Throws java.lang.NullPointerException + */ +void throwNullPointerException(JNIEnv *env, const char *msg) +{ + throwByName(env, "java/lang/NullPointerException", msg); +} + +/* + * Throws java.io.IOException */ -void throwIOException(JNIEnv *env, const char *message) +void throwIOException(JNIEnv *env, const char *msg) { - JNU_ThrowByName(env, CLASS_IO_EXCEPTION, message); + throwByName(env, "java/io/IOException", msg); } /* * This function simply throws a PKCS#11RuntimeException with the given - * string as its message. If the message is NULL, the exception is created - * using the default constructor. + * string as its message. * * @param env Used to call JNI funktions and to get the Exception class. * @param jmessage The message string of the Exception object. */ void throwPKCS11RuntimeException(JNIEnv *env, const char *message) { - JNU_ThrowByName(env, CLASS_PKCS11RUNTIMEEXCEPTION, message); + throwByName(env, CLASS_PKCS11RUNTIMEEXCEPTION, message); } /* @@ -318,7 +342,7 @@ void jBooleanArrayToCKBBoolArray(JNIEnv *env, const jbooleanArray jArray, CK_BBO *ckpLength = (*env)->GetArrayLength(env, jArray); jpTemp = (jboolean*) malloc((*ckpLength) * sizeof(jboolean)); if (jpTemp == NULL) { - JNU_ThrowOutOfMemoryError(env, 0); + throwOutOfMemoryError(env, 0); return; } (*env)->GetBooleanArrayRegion(env, jArray, 0, *ckpLength, jpTemp); @@ -330,7 +354,7 @@ void jBooleanArrayToCKBBoolArray(JNIEnv *env, const jbooleanArray jArray, CK_BBO *ckpArray = (CK_BBOOL*) malloc ((*ckpLength) * sizeof(CK_BBOOL)); if (*ckpArray == NULL) { free(jpTemp); - JNU_ThrowOutOfMemoryError(env, 0); + throwOutOfMemoryError(env, 0); return; } for (i=0; i<(*ckpLength); i++) { @@ -360,7 +384,7 @@ void jByteArrayToCKByteArray(JNIEnv *env, const jbyteArray jArray, CK_BYTE_PTR * *ckpLength = (*env)->GetArrayLength(env, jArray); jpTemp = (jbyte*) malloc((*ckpLength) * sizeof(jbyte)); if (jpTemp == NULL) { - JNU_ThrowOutOfMemoryError(env, 0); + throwOutOfMemoryError(env, 0); return; } (*env)->GetByteArrayRegion(env, jArray, 0, *ckpLength, jpTemp); @@ -376,7 +400,7 @@ void jByteArrayToCKByteArray(JNIEnv *env, const jbyteArray jArray, CK_BYTE_PTR * *ckpArray = (CK_BYTE_PTR) malloc ((*ckpLength) * sizeof(CK_BYTE)); if (*ckpArray == NULL) { free(jpTemp); - JNU_ThrowOutOfMemoryError(env, 0); + throwOutOfMemoryError(env, 0); return; } for (i=0; i<(*ckpLength); i++) { @@ -407,7 +431,7 @@ void jLongArrayToCKULongArray(JNIEnv *env, const jlongArray jArray, CK_ULONG_PTR *ckpLength = (*env)->GetArrayLength(env, jArray); jTemp = (jlong*) malloc((*ckpLength) * sizeof(jlong)); if (jTemp == NULL) { - JNU_ThrowOutOfMemoryError(env, 0); + throwOutOfMemoryError(env, 0); return; } (*env)->GetLongArrayRegion(env, jArray, 0, *ckpLength, jTemp); @@ -419,7 +443,7 @@ void jLongArrayToCKULongArray(JNIEnv *env, const jlongArray jArray, CK_ULONG_PTR *ckpArray = (CK_ULONG_PTR) malloc (*ckpLength * sizeof(CK_ULONG)); if (*ckpArray == NULL) { free(jTemp); - JNU_ThrowOutOfMemoryError(env, 0); + throwOutOfMemoryError(env, 0); return; } for (i=0; i<(*ckpLength); i++) { @@ -449,7 +473,7 @@ void jCharArrayToCKCharArray(JNIEnv *env, const jcharArray jArray, CK_CHAR_PTR * *ckpLength = (*env)->GetArrayLength(env, jArray); jpTemp = (jchar*) malloc((*ckpLength) * sizeof(jchar)); if (jpTemp == NULL) { - JNU_ThrowOutOfMemoryError(env, 0); + throwOutOfMemoryError(env, 0); return; } (*env)->GetCharArrayRegion(env, jArray, 0, *ckpLength, jpTemp); @@ -461,7 +485,7 @@ void jCharArrayToCKCharArray(JNIEnv *env, const jcharArray jArray, CK_CHAR_PTR * *ckpArray = (CK_CHAR_PTR) malloc (*ckpLength * sizeof(CK_CHAR)); if (*ckpArray == NULL) { free(jpTemp); - JNU_ThrowOutOfMemoryError(env, 0); + throwOutOfMemoryError(env, 0); return; } for (i=0; i<(*ckpLength); i++) { @@ -491,7 +515,7 @@ void jCharArrayToCKUTF8CharArray(JNIEnv *env, const jcharArray jArray, CK_UTF8CH *ckpLength = (*env)->GetArrayLength(env, jArray); jTemp = (jchar*) malloc((*ckpLength) * sizeof(jchar)); if (jTemp == NULL) { - JNU_ThrowOutOfMemoryError(env, 0); + throwOutOfMemoryError(env, 0); return; } (*env)->GetCharArrayRegion(env, jArray, 0, *ckpLength, jTemp); @@ -503,7 +527,7 @@ void jCharArrayToCKUTF8CharArray(JNIEnv *env, const jcharArray jArray, CK_UTF8CH *ckpArray = (CK_UTF8CHAR_PTR) malloc (*ckpLength * sizeof(CK_UTF8CHAR)); if (*ckpArray == NULL) { free(jTemp); - JNU_ThrowOutOfMemoryError(env, 0); + throwOutOfMemoryError(env, 0); return; } for (i=0; i<(*ckpLength); i++) { @@ -538,7 +562,7 @@ void jStringToCKUTF8CharArray(JNIEnv *env, const jstring jArray, CK_UTF8CHAR_PTR *ckpArray = (CK_UTF8CHAR_PTR) malloc((*ckpLength + 1) * sizeof(CK_UTF8CHAR)); if (*ckpArray == NULL) { (*env)->ReleaseStringUTFChars(env, (jstring) jArray, pCharArray); - JNU_ThrowOutOfMemoryError(env, 0); + throwOutOfMemoryError(env, 0); return; } strcpy((char*)*ckpArray, pCharArray); @@ -571,7 +595,7 @@ void jAttributeArrayToCKAttributeArray(JNIEnv *env, jobjectArray jArray, CK_ATTR *ckpLength = jLongToCKULong(jLength); *ckpArray = (CK_ATTRIBUTE_PTR) malloc(*ckpLength * sizeof(CK_ATTRIBUTE)); if (*ckpArray == NULL) { - JNU_ThrowOutOfMemoryError(env, 0); + throwOutOfMemoryError(env, 0); return; } TRACE1(", converting %d attibutes", jLength); @@ -613,7 +637,7 @@ jbyteArray ckByteArrayToJByteArray(JNIEnv *env, const CK_BYTE_PTR ckpArray, CK_U } else { jpTemp = (jbyte*) malloc((ckLength) * sizeof(jbyte)); if (jpTemp == NULL) { - JNU_ThrowOutOfMemoryError(env, 0); + throwOutOfMemoryError(env, 0); return NULL; } for (i=0; iCallBooleanMethod(env, jObject, jValueMethod); ckpValue = (CK_BBOOL *) malloc(sizeof(CK_BBOOL)); if (ckpValue == NULL) { - JNU_ThrowOutOfMemoryError(env, 0); + throwOutOfMemoryError(env, 0); return NULL; } *ckpValue = jBooleanToCKBBool(jValue); @@ -842,7 +866,7 @@ CK_BYTE_PTR jByteObjectToCKBytePtr(JNIEnv *env, jobject jObject) jValue = (*env)->CallByteMethod(env, jObject, jValueMethod); ckpValue = (CK_BYTE_PTR) malloc(sizeof(CK_BYTE)); if (ckpValue == NULL) { - JNU_ThrowOutOfMemoryError(env, 0); + throwOutOfMemoryError(env, 0); return NULL; } *ckpValue = jByteToCKByte(jValue); @@ -871,7 +895,7 @@ CK_ULONG* jIntegerObjectToCKULongPtr(JNIEnv *env, jobject jObject) jValue = (*env)->CallIntMethod(env, jObject, jValueMethod); ckpValue = (CK_ULONG *) malloc(sizeof(CK_ULONG)); if (ckpValue == NULL) { - JNU_ThrowOutOfMemoryError(env, 0); + throwOutOfMemoryError(env, 0); return NULL; } *ckpValue = jLongToCKLong(jValue); @@ -900,7 +924,7 @@ CK_ULONG* jLongObjectToCKULongPtr(JNIEnv *env, jobject jObject) jValue = (*env)->CallLongMethod(env, jObject, jValueMethod); ckpValue = (CK_ULONG *) malloc(sizeof(CK_ULONG)); if (ckpValue == NULL) { - JNU_ThrowOutOfMemoryError(env, 0); + throwOutOfMemoryError(env, 0); return NULL; } *ckpValue = jLongToCKULong(jValue); @@ -930,7 +954,7 @@ CK_CHAR_PTR jCharObjectToCKCharPtr(JNIEnv *env, jobject jObject) jValue = (*env)->CallCharMethod(env, jObject, jValueMethod); ckpValue = (CK_CHAR_PTR) malloc(sizeof(CK_CHAR)); if (ckpValue == NULL) { - JNU_ThrowOutOfMemoryError(env, 0); + throwOutOfMemoryError(env, 0); return NULL; } *ckpValue = jCharToCKChar(jValue); @@ -1087,7 +1111,7 @@ void jObjectToPrimitiveCKObjectPtrPtr(JNIEnv *env, jobject jObject, CK_VOID_PTR malloc((strlen(exceptionMsgPrefix) + strlen(classNameString) + 1)); if (exceptionMsg == NULL) { (*env)->ReleaseStringUTFChars(env, jClassNameString, classNameString); - JNU_ThrowOutOfMemoryError(env, 0); + throwOutOfMemoryError(env, 0); return; } strcpy(exceptionMsg, exceptionMsgPrefix); diff --git a/src/share/native/sun/security/pkcs11/wrapper/pkcs11wrapper.h b/src/share/native/sun/security/pkcs11/wrapper/pkcs11wrapper.h index ff6d550d5236241496326ec68a0781a7f7ecb22c..bf3adf86a9dea9063fe83a892c4aea1285b0a5d3 100644 --- a/src/share/native/sun/security/pkcs11/wrapper/pkcs11wrapper.h +++ b/src/share/native/sun/security/pkcs11/wrapper/pkcs11wrapper.h @@ -228,7 +228,6 @@ #define CLASS_PKCS11EXCEPTION "sun/security/pkcs11/wrapper/PKCS11Exception" #define CLASS_PKCS11RUNTIMEEXCEPTION "sun/security/pkcs11/wrapper/PKCS11RuntimeException" #define CLASS_FILE_NOT_FOUND_EXCEPTION "java/io/FileNotFoundException" -#define CLASS_IO_EXCEPTION "java/io/IOException" #define CLASS_C_INITIALIZE_ARGS "sun/security/pkcs11/wrapper/CK_C_INITIALIZE_ARGS" #define CLASS_CREATEMUTEX "sun/security/pkcs11/wrapper/CK_CREATEMUTEX" #define CLASS_DESTROYMUTEX "sun/security/pkcs11/wrapper/CK_DESTROYMUTEX" @@ -280,6 +279,8 @@ */ jlong ckAssertReturnValueOK(JNIEnv *env, CK_RV returnValue); +void throwOutOfMemoryError(JNIEnv *env, const char *message); +void throwNullPointerException(JNIEnv *env, const char *message); void throwIOException(JNIEnv *env, const char *message); void throwPKCS11RuntimeException(JNIEnv *env, const char *message); void throwDisconnectedRuntimeException(JNIEnv *env); diff --git a/src/solaris/native/sun/security/pkcs11/j2secmod_md.c b/src/solaris/native/sun/security/pkcs11/j2secmod_md.c index b445899f73b3a7a2d8e89924189d60db7a9b13ba..b763bc25bb423fcbfdeb6a1b4e8e789721c9bae0 100644 --- a/src/solaris/native/sun/security/pkcs11/j2secmod_md.c +++ b/src/solaris/native/sun/security/pkcs11/j2secmod_md.c @@ -40,7 +40,7 @@ void *findFunction(JNIEnv *env, jlong jHandle, const char *functionName) { if (fAddress == NULL) { char errorMessage[256]; snprintf(errorMessage, sizeof(errorMessage), "Symbol not found: %s", functionName); - JNU_ThrowNullPointerException(env, errorMessage); + throwNullPointerException(env, errorMessage); return NULL; } return fAddress; @@ -69,7 +69,7 @@ JNIEXPORT jlong JNICALL Java_sun_security_pkcs11_Secmod_nssLoadLibrary dprintf2("-handle: %u (0X%X)\n", hModule, hModule); if (hModule == NULL) { - JNU_ThrowIOException(env, dlerror()); + throwIOException(env, dlerror()); return 0; } diff --git a/src/solaris/native/sun/security/smartcardio/pcsc_md.c b/src/solaris/native/sun/security/smartcardio/pcsc_md.c index 67e452da340707956f703aeae56b69aa8ee60af3..c7379810fabe7ae3ee5bb64b5dd6f93052d995e9 100644 --- a/src/solaris/native/sun/security/smartcardio/pcsc_md.c +++ b/src/solaris/native/sun/security/smartcardio/pcsc_md.c @@ -51,12 +51,40 @@ FPTR_SCardBeginTransaction scardBeginTransaction; FPTR_SCardEndTransaction scardEndTransaction; FPTR_SCardControl scardControl; +/* + * Throws a Java Exception by name + */ +void throwByName(JNIEnv *env, const char *name, const char *msg) +{ + jclass cls = (*env)->FindClass(env, name); + + if (cls != 0) /* Otherwise an exception has already been thrown */ + (*env)->ThrowNew(env, cls, msg); +} + +/* + * Throws java.lang.NullPointerException + */ +void throwNullPointerException(JNIEnv *env, const char *msg) +{ + throwByName(env, "java/lang/NullPointerException", msg); +} + +/* + * Throws java.io.IOException + */ +void throwIOException(JNIEnv *env, const char *msg) +{ + throwByName(env, "java/io/IOException", msg); +} + + void *findFunction(JNIEnv *env, void *hModule, char *functionName) { void *fAddress = dlsym(hModule, functionName); if (fAddress == NULL) { char errorMessage[256]; snprintf(errorMessage, sizeof(errorMessage), "Symbol not found: %s", functionName); - JNU_ThrowNullPointerException(env, errorMessage); + throwNullPointerException(env, errorMessage); return NULL; } return fAddress; @@ -69,7 +97,7 @@ JNIEXPORT void JNICALL Java_sun_security_smartcardio_PlatformPCSC_initialize (*env)->ReleaseStringUTFChars(env, jLibName, libName); if (hModule == NULL) { - JNU_ThrowIOException(env, dlerror()); + throwIOException(env, dlerror()); return; } scardEstablishContext = (FPTR_SCardEstablishContext)findFunction(env, hModule, "SCardEstablishContext"); diff --git a/src/windows/native/sun/security/pkcs11/j2secmod_md.c b/src/windows/native/sun/security/pkcs11/j2secmod_md.c index 4a8d7583a4cc543d059afeace58fa9fe0298e5a3..fac24a6063fece325f035a38e52bec693e9f7eb0 100644 --- a/src/windows/native/sun/security/pkcs11/j2secmod_md.c +++ b/src/windows/native/sun/security/pkcs11/j2secmod_md.c @@ -37,7 +37,7 @@ void *findFunction(JNIEnv *env, jlong jHandle, const char *functionName) { if (fAddress == NULL) { char errorMessage[256]; _snprintf(errorMessage, sizeof(errorMessage), "Symbol not found: %s", functionName); - JNU_ThrowNullPointerException(env, errorMessage); + throwNullPointerException(env, errorMessage); return NULL; } return fAddress; @@ -78,7 +78,7 @@ JNIEXPORT jlong JNICALL Java_sun_security_pkcs11_Secmod_nssLoadLibrary NULL ); dprintf1("-error: %s\n", lpMsgBuf); - JNU_ThrowIOException(env, (char*)lpMsgBuf); + throwIOException(env, (char*)lpMsgBuf); LocalFree(lpMsgBuf); return 0; }