7103549: Remove dependencies on libjava and libjvm from security libraries
Reviewed-by: vinnie, ohair, alanb, dholmes
--- a/jdk/make/com/sun/security/auth/module/Makefile Mon Oct 24 20:55:08 2011 +0100
+++ b/jdk/make/com/sun/security/auth/module/Makefile Mon Oct 24 21:03:41 2011 +0100
@@ -78,7 +78,3 @@
#
include $(BUILDDIR)/common/Library.gmk
-#
-# JVMDI implementation lives in the VM.
-#
-OTHER_LDLIBS = $(JVMLIB)
--- a/jdk/make/common/Defs.gmk Mon Oct 24 20:55:08 2011 +0100
+++ b/jdk/make/common/Defs.gmk Mon Oct 24 21:03:41 2011 +0100
@@ -220,14 +220,30 @@
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
#
--- a/jdk/make/common/Library.gmk Mon Oct 24 20:55:08 2011 +0100
+++ b/jdk/make/common/Library.gmk Mon Oct 24 21:03:41 2011 +0100
@@ -165,7 +165,7 @@
$(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)
--- a/jdk/make/sun/security/ec/Makefile Mon Oct 24 20:55:08 2011 +0100
+++ b/jdk/make/sun/security/ec/Makefile Mon Oct 24 21:03:41 2011 +0100
@@ -192,10 +192,8 @@
#
# 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
--- a/jdk/make/sun/security/jgss/wrapper/Makefile Mon Oct 24 20:55:08 2011 +0100
+++ b/jdk/make/sun/security/jgss/wrapper/Makefile Mon Oct 24 21:03:41 2011 +0100
@@ -72,5 +72,6 @@
# Libraries to link
#
ifneq ($(PLATFORM), windows)
- OTHER_LDLIBS = -ldl $(JVMLIB)
+ OTHER_LDLIBS = -ldl
endif
+
--- a/jdk/make/sun/security/krb5/Makefile Mon Oct 24 20:55:08 2011 +0100
+++ b/jdk/make/sun/security/krb5/Makefile Mon Oct 24 21:03:41 2011 +0100
@@ -69,15 +69,6 @@
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, , )
--- a/jdk/make/sun/security/mscapi/Makefile Mon Oct 24 20:55:08 2011 +0100
+++ b/jdk/make/sun/security/mscapi/Makefile Mon Oct 24 21:03:41 2011 +0100
@@ -159,7 +159,7 @@
# Libraries to link
#
ifeq ($(PLATFORM), windows)
- OTHER_LDLIBS += $(JVMLIB) Crypt32.Lib
+ OTHER_LDLIBS += Crypt32.Lib
endif
#
--- a/jdk/make/sun/security/pkcs11/Makefile Mon Oct 24 20:55:08 2011 +0100
+++ b/jdk/make/sun/security/pkcs11/Makefile Mon Oct 24 21:03:41 2011 +0100
@@ -159,10 +159,8 @@
#
# Libraries to link
#
-ifeq ($(PLATFORM), windows)
- OTHER_LDLIBS = $(JVMLIB)
-else
- OTHER_LDLIBS = -ldl $(JVMLIB)
+ifneq ($(PLATFORM), windows)
+ OTHER_LDLIBS = -ldl
endif
# Other config files
--- a/jdk/make/sun/security/smartcardio/Makefile Mon Oct 24 20:55:08 2011 +0100
+++ b/jdk/make/sun/security/smartcardio/Makefile Mon Oct 24 21:03:41 2011 +0100
@@ -73,8 +73,8 @@
# 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
--- a/jdk/src/share/native/sun/security/pkcs11/wrapper/p11_convert.c Mon Oct 24 20:55:08 2011 +0100
+++ b/jdk/src/share/native/sun/security/pkcs11/wrapper/p11_convert.c Mon Oct 24 21:03:41 2011 +0100
@@ -273,7 +273,7 @@
/* 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 @@
/* 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 @@
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 @@
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 @@
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 @@
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 @@
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 @@
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 @@
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 @@
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 @@
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 @@
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 @@
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 @@
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 @@
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 @@
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 @@
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 @@
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 @@
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;
}
--- a/jdk/src/share/native/sun/security/pkcs11/wrapper/p11_digest.c Mon Oct 24 20:55:08 2011 +0100
+++ b/jdk/src/share/native/sun/security/pkcs11/wrapper/p11_digest.c Mon Oct 24 21:03:41 2011 +0100
@@ -131,7 +131,7 @@
/* 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 @@
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;
}
}
--- a/jdk/src/share/native/sun/security/pkcs11/wrapper/p11_dual.c Mon Oct 24 20:55:08 2011 +0100
+++ b/jdk/src/share/native/sun/security/pkcs11/wrapper/p11_dual.c Mon Oct 24 21:03:41 2011 +0100
@@ -92,7 +92,7 @@
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 @@
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 @@
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 @@
ckpPart = (CK_BYTE_PTR) malloc(ckPartLength * sizeof(CK_BYTE));
if (ckpPart == NULL) {
free(ckpEncryptedPart);
- JNU_ThrowOutOfMemoryError(env, 0);
+ throwOutOfMemoryError(env, 0);
return NULL;
}
--- a/jdk/src/share/native/sun/security/pkcs11/wrapper/p11_general.c Mon Oct 24 20:55:08 2011 +0100
+++ b/jdk/src/share/native/sun/security/pkcs11/wrapper/p11_general.c Mon Oct 24 21:03:41 2011 +0100
@@ -71,7 +71,10 @@
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 @@
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 @@
ckpMechanismList = (CK_MECHANISM_TYPE_PTR)
malloc(ckMechanismNumber * sizeof(CK_MECHANISM_TYPE));
if (ckpMechanismList == NULL) {
- JNU_ThrowOutOfMemoryError(env, 0);
+ throwOutOfMemoryError(env, 0);
return NULL;
}
--- a/jdk/src/share/native/sun/security/pkcs11/wrapper/p11_keymgmt.c Mon Oct 24 20:55:08 2011 +0100
+++ b/jdk/src/share/native/sun/security/pkcs11/wrapper/p11_keymgmt.c Mon Oct 24 21:03:41 2011 +0100
@@ -165,7 +165,7 @@
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 @@
if (ckMechanism.pParameter != NULL_PTR) {
free(ckMechanism.pParameter);
}
- JNU_ThrowOutOfMemoryError(env, 0);
+ throwOutOfMemoryError(env, 0);
return NULL;
}
--- a/jdk/src/share/native/sun/security/pkcs11/wrapper/p11_mutex.c Mon Oct 24 20:55:08 2011 +0100
+++ b/jdk/src/share/native/sun/security/pkcs11/wrapper/p11_mutex.c Mon Oct 24 21:03:41 2011 +0100
@@ -92,7 +92,7 @@
/* 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 @@
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_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 @@
/* 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 callJDestroyMutex(CK_VOID_PTR pMutex)
{
- JavaVM *jvm;
+ extern JavaVM *jvm;
JNIEnv *env;
- jsize actualNumberVMs;
jint returnValue;
jthrowable pkcs11Exception;
jclass pkcs11ExceptionClass;
@@ -291,8 +288,7 @@
/* 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 callJLockMutex(CK_VOID_PTR pMutex)
{
- JavaVM *jvm;
+ extern JavaVM *jvm;
JNIEnv *env;
- jsize actualNumberVMs;
jint returnValue;
jthrowable pkcs11Exception;
jclass pkcs11ExceptionClass;
@@ -385,8 +380,7 @@
/* 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 callJUnlockMutex(CK_VOID_PTR pMutex)
{
- JavaVM *jvm;
+ extern JavaVM *jvm;
JNIEnv *env;
- jsize actualNumberVMs;
jint returnValue;
jthrowable pkcs11Exception;
jclass pkcs11ExceptionClass;
@@ -475,8 +468,7 @@
/* 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);
--- a/jdk/src/share/native/sun/security/pkcs11/wrapper/p11_objmgmt.c Mon Oct 24 20:55:08 2011 +0100
+++ b/jdk/src/share/native/sun/security/pkcs11/wrapper/p11_objmgmt.c Mon Oct 24 21:03:41 2011 +0100
@@ -258,7 +258,7 @@
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 @@
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;
}
--- a/jdk/src/share/native/sun/security/pkcs11/wrapper/p11_sessmgmt.c Mon Oct 24 20:55:08 2011 +0100
+++ b/jdk/src/share/native/sun/security/pkcs11/wrapper/p11_sessmgmt.c Mon Oct 24 21:03:41 2011 +0100
@@ -98,7 +98,7 @@
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 @@
ckpState = (CK_BYTE_PTR) malloc(ckStateLength);
if (ckpState == NULL) {
- JNU_ThrowOutOfMemoryError(env, 0);
+ throwOutOfMemoryError(env, 0);
return NULL;
}
@@ -435,7 +435,7 @@
newNode = (NotifyListNode *) malloc(sizeof(NotifyListNode));
if (newNode == NULL) {
- JNU_ThrowOutOfMemoryError(env, 0);
+ throwOutOfMemoryError(env, 0);
return;
}
newNode->hSession = hSession;
@@ -558,9 +558,8 @@
)
{
NotifyEncapsulation *notifyEncapsulation;
- JavaVM *jvm;
+ extern JavaVM *jvm;
JNIEnv *env;
- jsize actualNumberVMs;
jint returnValue;
jlong jSessionHandle;
jlong jEvent;
@@ -577,8 +576,7 @@
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);
--- a/jdk/src/share/native/sun/security/pkcs11/wrapper/p11_sign.c Mon Oct 24 20:55:08 2011 +0100
+++ b/jdk/src/share/native/sun/security/pkcs11/wrapper/p11_sign.c Mon Oct 24 21:03:41 2011 +0100
@@ -132,7 +132,7 @@
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 @@
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 @@
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 @@
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 @@
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 @@
} 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 @@
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 @@
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 @@
} 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 @@
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);
--- a/jdk/src/share/native/sun/security/pkcs11/wrapper/p11_util.c Mon Oct 24 20:55:08 2011 +0100
+++ b/jdk/src/share/native/sun/security/pkcs11/wrapper/p11_util.c Mon Oct 24 21:03:41 2011 +0100
@@ -213,28 +213,52 @@
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 throwIOException(JNIEnv *env, const char *message)
+void throwOutOfMemoryError(JNIEnv *env, const char *msg)
+{
+ throwByName(env, "java/lang/OutOfMemoryError", msg);
+}
+
+/*
+ * Throws java.lang.NullPointerException
+ */
+void throwNullPointerException(JNIEnv *env, const char *msg)
{
- JNU_ThrowByName(env, CLASS_IO_EXCEPTION, message);
+ throwByName(env, "java/lang/NullPointerException", msg);
+}
+
+/*
+ * Throws java.io.IOException
+ */
+void throwIOException(JNIEnv *env, const char *msg)
+{
+ 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 @@
*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 @@
*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 @@
*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 @@
*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 @@
*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 @@
*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 @@
*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 @@
*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 @@
*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 @@
*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 @@
*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 @@
*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 @@
} else {
jpTemp = (jbyte*) malloc((ckLength) * sizeof(jbyte));
if (jpTemp == NULL) {
- JNU_ThrowOutOfMemoryError(env, 0);
+ throwOutOfMemoryError(env, 0);
return NULL;
}
for (i=0; i<ckLength; i++) {
@@ -647,7 +671,7 @@
jpTemp = (jlong*) malloc((ckLength) * sizeof(jlong));
if (jpTemp == NULL) {
- JNU_ThrowOutOfMemoryError(env, 0);
+ throwOutOfMemoryError(env, 0);
return NULL;
}
for (i=0; i<ckLength; i++) {
@@ -678,7 +702,7 @@
jpTemp = (jchar*) malloc(ckLength * sizeof(jchar));
if (jpTemp == NULL) {
- JNU_ThrowOutOfMemoryError(env, 0);
+ throwOutOfMemoryError(env, 0);
return NULL;
}
for (i=0; i<ckLength; i++) {
@@ -709,7 +733,7 @@
jpTemp = (jchar*) malloc(ckLength * sizeof(jchar));
if (jpTemp == NULL) {
- JNU_ThrowOutOfMemoryError(env, 0);
+ throwOutOfMemoryError(env, 0);
return NULL;
}
for (i=0; i<ckLength; i++) {
@@ -812,7 +836,7 @@
jValue = (*env)->CallBooleanMethod(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 @@
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 @@
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 @@
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 @@
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 @@
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);
--- a/jdk/src/share/native/sun/security/pkcs11/wrapper/pkcs11wrapper.h Mon Oct 24 20:55:08 2011 +0100
+++ b/jdk/src/share/native/sun/security/pkcs11/wrapper/pkcs11wrapper.h Mon Oct 24 21:03:41 2011 +0100
@@ -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);
--- a/jdk/src/solaris/native/sun/security/pkcs11/j2secmod_md.c Mon Oct 24 20:55:08 2011 +0100
+++ b/jdk/src/solaris/native/sun/security/pkcs11/j2secmod_md.c Mon Oct 24 21:03:41 2011 +0100
@@ -40,7 +40,7 @@
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 @@
dprintf2("-handle: %u (0X%X)\n", hModule, hModule);
if (hModule == NULL) {
- JNU_ThrowIOException(env, dlerror());
+ throwIOException(env, dlerror());
return 0;
}
--- a/jdk/src/solaris/native/sun/security/smartcardio/pcsc_md.c Mon Oct 24 20:55:08 2011 +0100
+++ b/jdk/src/solaris/native/sun/security/smartcardio/pcsc_md.c Mon Oct 24 21:03:41 2011 +0100
@@ -51,12 +51,40 @@
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 @@
(*env)->ReleaseStringUTFChars(env, jLibName, libName);
if (hModule == NULL) {
- JNU_ThrowIOException(env, dlerror());
+ throwIOException(env, dlerror());
return;
}
scardEstablishContext = (FPTR_SCardEstablishContext)findFunction(env, hModule, "SCardEstablishContext");
--- a/jdk/src/windows/native/sun/security/pkcs11/j2secmod_md.c Mon Oct 24 20:55:08 2011 +0100
+++ b/jdk/src/windows/native/sun/security/pkcs11/j2secmod_md.c Mon Oct 24 21:03:41 2011 +0100
@@ -37,7 +37,7 @@
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 @@
NULL
);
dprintf1("-error: %s\n", lpMsgBuf);
- JNU_ThrowIOException(env, (char*)lpMsgBuf);
+ throwIOException(env, (char*)lpMsgBuf);
LocalFree(lpMsgBuf);
return 0;
}