From 40aeac8ce1342ed8175be61dc3518c11fa78ed11 Mon Sep 17 00:00:00 2001 From: su-fang Date: Mon, 26 Sep 2022 10:00:26 +0800 Subject: [PATCH] Add system-pcsclite.diff. --- debian/changelog | 6 +++ debian/rules | 14 ------- make/autoconf/lib-bundled.m4 | 39 ++++++++++++++++++ make/autoconf/spec.gmk.in | 1 + make/lib/Lib-java.smartcardio.gmk | 6 +-- .../unix/native/libj2pcsc/pcsc_md.c | 7 ++++ .../unix/native/libj2pcsc/pcsc_md.h | 40 +++++++++++++++++++ 7 files changed, 96 insertions(+), 17 deletions(-) diff --git a/debian/changelog b/debian/changelog index 7de07fa0c..8aba95f37 100644 --- a/debian/changelog +++ b/debian/changelog @@ -1,3 +1,9 @@ +openjdk-lts (11.0.16+8-ok2) yangtze; urgency=medium + + * Add system-pcsclite.diff. + + -- sufang Mon, 26 Sep 2022 09:52:24 +0800 + openjdk-lts (11.0.16+8-ok1) yangtze; urgency=medium * Build for openkylin. diff --git a/debian/rules b/debian/rules index e03379582..dfca89338 100755 --- a/debian/rules +++ b/debian/rules @@ -323,20 +323,6 @@ else ifneq (,$(filter $(distrel),focal)) export CC = $(DEB_HOST_GNU_TYPE)-gcc-9 export CXX = $(DEB_HOST_GNU_TYPE)-g++-9 bd_gcc = g++-9 , -else ifneq (,$(filter $(distrel),bullseye groovy hirsute)) - export CC = $(DEB_HOST_GNU_TYPE)-gcc-10 - export CXX = $(DEB_HOST_GNU_TYPE)-g++-10 - bd_gcc = g++-10 , -else - export CC = $(DEB_HOST_GNU_TYPE)-gcc-11 - export CXX = $(DEB_HOST_GNU_TYPE)-g++-11 - bd_gcc = g++-11 , -endif - -# until we are able to b-d on gcc-for-host ... -ifneq ($(DEB_BUILD_GNU_TYPE),$(DEB_HOST_GNU_TYPE)) - export CC = $(DEB_HOST_GNU_TYPE)-gcc - export CXX = $(DEB_HOST_GNU_TYPE)-g++ endif ifneq (,$(filter $(distrel),squeeze lucid)) diff --git a/make/autoconf/lib-bundled.m4 b/make/autoconf/lib-bundled.m4 index f5c11d4ec..5964c0900 100644 --- a/make/autoconf/lib-bundled.m4 +++ b/make/autoconf/lib-bundled.m4 @@ -38,6 +38,7 @@ AC_DEFUN_ONCE([LIB_SETUP_BUNDLED_LIBS], LIB_SETUP_ZLIB LIB_SETUP_LCMS LIB_SETUP_HARFBUZZ + LIB_SETUP_PCSCLITE ]) ################################################################################ @@ -301,3 +302,41 @@ AC_DEFUN_ONCE([LIB_SETUP_HARFBUZZ], AC_SUBST(HARFBUZZ_CFLAGS) AC_SUBST(HARFBUZZ_LIBS) ]) + +################################################################################ +# Setup pcsclite +################################################################################ +AC_DEFUN_ONCE([LIB_SETUP_PCSCLITE], +[ + AC_ARG_WITH(pcsclite, [AS_HELP_STRING([--with-pcsclite], + [use pcsclite from build system or OpenJDK source (system, bundled) @<:@bundled@:>@])]) + + AC_MSG_CHECKING([for which pcsclite to use]) + + # default is bundled + DEFAULT_PCSCLITE=bundled + # if user didn't specify, use DEFAULT_PCSCLITE + if test "x${with_pcsclite}" = "x"; then + with_libpng=${DEFAULT_PCSCLITE} + fi + + if test "x${with_pcsclite}" = "xbundled"; then + USE_EXTERNAL_PCSCLITE=false + AC_MSG_RESULT([bundled]) + elif test "x${with_pcsclite}" = "xsystem"; then + PKG_CHECK_MODULES(PCSCLITE, libpcsclite, + [ PCSCLITE_FOUND=yes ], + [ PCSCLITE_FOUND=no ]) + if test "x${PCSCLITE_FOUND}" = "xyes"; then + USE_EXTERNAL_PCSCLITE=true + AC_MSG_RESULT([system]) + else + AC_MSG_RESULT([system not found]) + AC_MSG_ERROR([--with-pcsclite=system specified, but no pcsclite found!]) + fi + else + AC_MSG_ERROR([Invalid value of --with-pcsclite: ${with_pcsclite}, use 'system' or 'bundled']) + fi + + AC_SUBST(USE_EXTERNAL_PCSCLITE) +]) diff --git a/make/autoconf/spec.gmk.in b/make/autoconf/spec.gmk.in index d4f3ea49e..322e5485e 100644 --- a/make/autoconf/spec.gmk.in +++ b/make/autoconf/spec.gmk.in @@ -768,6 +768,7 @@ ENABLE_AOT:=@ENABLE_AOT@ ENABLE_INTREE_EC:=@ENABLE_INTREE_EC@ USE_EXTERNAL_LIBJPEG:=@USE_EXTERNAL_LIBJPEG@ USE_EXTERNAL_LIBGIF:=@USE_EXTERNAL_LIBGIF@ +USE_EXTERNAL_LIBPCSCLITE:=@USE_EXTERNAL_LIBPCSCLITE@ USE_EXTERNAL_LIBZ:=@USE_EXTERNAL_LIBZ@ LIBZ_CFLAGS:=@LIBZ_CFLAGS@ LIBZ_LIBS:=@LIBZ_LIBS@ diff --git a/make/lib/Lib-java.smartcardio.gmk b/make/lib/Lib-java.smartcardio.gmk index a8c650615..e96cfb34c 100644 --- a/make/lib/Lib-java.smartcardio.gmk +++ b/make/lib/Lib-java.smartcardio.gmk @@ -30,12 +30,12 @@ include LibCommon.gmk $(eval $(call SetupJdkLibrary, BUILD_LIBJ2PCSC, \ NAME := j2pcsc, \ CFLAGS := $(CFLAGS_JDKLIB), \ - CFLAGS_unix := -D__sun_jdk, \ - EXTRA_HEADER_DIRS := libj2pcsc/MUSCLE, \ + CFLAGS_unix := -D__sun_jdk -DUSE_SYSTEM_LIBPCSCLITE, \ + EXTRA_HEADER_DIRS := /usr/include/PCSC, \ OPTIMIZATION := LOW, \ LDFLAGS := $(LDFLAGS_JDKLIB) \ $(call SET_SHARED_LIBRARY_ORIGIN), \ - LIBS_unix := $(LIBDL), \ + LIBS_unix := -lpcsclite $(LIBDL), \ LIBS_windows := winscard.lib, \ )) diff --git a/src/java.smartcardio/unix/native/libj2pcsc/pcsc_md.c b/src/java.smartcardio/unix/native/libj2pcsc/pcsc_md.c index f344f4a00..10ea63d2f 100644 --- a/src/java.smartcardio/unix/native/libj2pcsc/pcsc_md.c +++ b/src/java.smartcardio/unix/native/libj2pcsc/pcsc_md.c @@ -36,6 +36,7 @@ #include "pcsc_md.h" +#ifndef USE_SYSTEM_LIBPCSCLITE void *hModule; FPTR_SCardEstablishContext scardEstablishContext; FPTR_SCardConnect scardConnect; @@ -47,6 +48,7 @@ FPTR_SCardListReaders scardListReaders; FPTR_SCardBeginTransaction scardBeginTransaction; FPTR_SCardEndTransaction scardEndTransaction; FPTR_SCardControl scardControl; +#endif /* * Throws a Java Exception by name @@ -75,7 +77,9 @@ void throwIOException(JNIEnv *env, const char *msg) throwByName(env, "java/io/IOException", msg); } +#ifndef USE_SYSTEM_LIBPCSCLITE void *findFunction(JNIEnv *env, void *hModule, char *functionName) { + return NULL; void *fAddress = dlsym(hModule, functionName); if (fAddress == NULL) { char errorMessage[256]; @@ -85,9 +89,11 @@ void *findFunction(JNIEnv *env, void *hModule, char *functionName) { } return fAddress; } +#endif JNIEXPORT void JNICALL Java_sun_security_smartcardio_PlatformPCSC_initialize (JNIEnv *env, jclass thisClass, jstring jLibName) { +#ifndef USE_SYSTEM_LIBPCSCLITE const char *libName = (*env)->GetStringUTFChars(env, jLibName, NULL); if (libName == NULL) { throwNullPointerException(env, "PCSC library name is null"); @@ -141,4 +147,5 @@ JNIEXPORT void JNICALL Java_sun_security_smartcardio_PlatformPCSC_initialize #else scardControl = (FPTR_SCardControl) findFunction(env, hModule, "SCardControl132"); #endif // __APPLE__ +#endif } diff --git a/src/java.smartcardio/unix/native/libj2pcsc/pcsc_md.h b/src/java.smartcardio/unix/native/libj2pcsc/pcsc_md.h index db93c9cd9..847531a85 100644 --- a/src/java.smartcardio/unix/native/libj2pcsc/pcsc_md.h +++ b/src/java.smartcardio/unix/native/libj2pcsc/pcsc_md.h @@ -23,6 +23,8 @@ * questions. */ +#ifndef USE_SYSTEM_LIBPCSCLITE + typedef LONG (*FPTR_SCardEstablishContext)(DWORD dwScope, LPCVOID pvReserved1, LPCVOID pvReserved2, @@ -111,3 +113,41 @@ extern FPTR_SCardListReaders scardListReaders; extern FPTR_SCardBeginTransaction scardBeginTransaction; extern FPTR_SCardEndTransaction scardEndTransaction; extern FPTR_SCardControl scardControl; + +#else + +#define CALL_SCardEstablishContext(dwScope, pvReserved1, pvReserved2, phContext) \ + (SCardEstablishContext(dwScope, pvReserved1, pvReserved2, phContext)) + +#define CALL_SCardConnect(hContext, szReader, dwSharedMode, dwPreferredProtocols, phCard, pdwActiveProtocols) \ + (SCardConnect(hContext, szReader, dwSharedMode, dwPreferredProtocols, phCard, pdwActiveProtocols)) + +#define CALL_SCardDisconnect(hCard, dwDisposition) \ + (SCardDisconnect(hCard, dwDisposition)) + +#define CALL_SCardStatus(hCard, mszReaderNames, pcchReaderLen, pdwState, pdwProtocol, pbAtr, pcbAtrLen) \ + (SCardStatus(hCard, mszReaderNames, pcchReaderLen, pdwState, pdwProtocol, pbAtr, pcbAtrLen)) + +#define CALL_SCardGetStatusChange(hContext, dwTimeout, rgReaderStates, cReaders) \ + (SCardGetStatusChange(hContext, dwTimeout, rgReaderStates, cReaders)) + +#define CALL_SCardTransmit(hCard, pioSendPci, pbSendBuffer, cbSendLength, \ + pioRecvPci, pbRecvBuffer, pcbRecvLength) \ + (SCardTransmit(hCard, pioSendPci, pbSendBuffer, cbSendLength, \ + pioRecvPci, pbRecvBuffer, pcbRecvLength)) + +#define CALL_SCardListReaders(hContext, mszGroups, mszReaders, pcchReaders) \ + (SCardListReaders(hContext, mszGroups, mszReaders, pcchReaders)) + +#define CALL_SCardBeginTransaction(hCard) \ + (SCardBeginTransaction(hCard)) + +#define CALL_SCardEndTransaction(hCard, dwDisposition) \ + (SCardEndTransaction(hCard, dwDisposition)) + +#define CALL_SCardControl(hCard, dwControlCode, pbSendBuffer, cbSendLength, \ + pbRecvBuffer, pcbRecvLength, lpBytesReturned) \ + (SCardControl(hCard, dwControlCode, pbSendBuffer, cbSendLength, \ + pbRecvBuffer, pcbRecvLength, lpBytesReturned)) + +#endif