JNI program work with 32bit but not 64bit JVM on jdk 1.6 & aix 5.3

T

TsanChung

My JNI program work with 32bit but not 64bit JVM on jdk 1.6 & aix 5.3.
Why?
32 bit is ok:
$ /usr/java6/jre/bin/java -d32 -jar jMultidevice.jar

64 bit fails:
$ /usr/java6_64/jre/bin/java -d64 -jar jMultidevice.jar
SSL Connect is failing
Exception in thread "main" com.mycomp.crypto.HwCryptokiException:
function 'C_Initialize' returns 0x30
at
com.mycomp.crypto.HwCryptokiException.ThrowNew(HwCryptokiException.java:
57)
at com.mycomp.crypto.HwAPI.Initialize(Native Method)
at com.mycomp.crypto.HwTokenManager.<init>(HwTokenManager.java:
107)
at
com.mycomp.crypto.HwTokenManager.getInstance(HwTokenManager.java:62)
at jMultidevice.jMultidevice.<init>(jMultidevice.java:32)
at jMultidevice.jMultidevice.main(jMultidevice.java:805)
 
L

Lothar Kimmeringer

TsanChung said:
64 bit fails:
$ /usr/java6_64/jre/bin/java -d64 -jar jMultidevice.jar
SSL Connect is failing
Exception in thread "main" com.mycomp.crypto.HwCryptokiException:
function 'C_Initialize' returns 0x30

Most likely you cast a pointer to a jint. Without knowing
C_Initialize nobody can tell for sure.


Regards, Lothar
--
Lothar Kimmeringer E-Mail: (e-mail address removed)
PGP-encrypted mails preferred (Key-ID: 0x8BC3CD81)

Always remember: The answer is forty-two, there can only be wrong
questions!
 
R

Roedy Green

My JNI program work with 32bit but not 64bit JVM on jdk 1.6 & aix 5.3.

I would assume you have to redo the Javah, and code to 64 bit C++, and
compile with a 64bit C++ compiler. It will be passing you 64 bit
addresses.
 
T

TsanChung

I would assume you have to redo the Javah, and code to 64 bit C++, and
compile with a 64bit C++ compiler. It will be passing you 64 bit
addresses.

This JNI program in C++ & jdk 6 work on 32-bit and 64-bit linux.
It is working on 32-bit aix. I am trying to make it to work on 64-bit
aix.
compile option is:
-I../../../cryptoki_vob/source/subdir -c -q64 -qwarn64 -I/usr/java6_64/
include -L/usr/lib -L/lib -L/usr/java6_64/jre/bin/classic -L/usr/
java6_64/jre/bin -I/usr/java/include -I/usr/java6/include -DOS_UNIX -
DOS_AIX -DUSE_PTHREADS -DLUNA_BIG_ENDIAN -DPKCS11_2_0 -DNDEBUG ./
HwAPI.cpp -o ./HwAPI.o -lj


"./HwAPI.cpp", line 1054.38: 1540-5334 (I) 64-bit portability :
possible difference in results if value is negative.

"./HwAPI.cpp", line 1072.24: 1540-5328 (I) 64-bit portability :
possible loss of digits through conversion of long type into int type

"./HwAPI.cpp", line 1073.24: 1540-5328 (I) 64-bit portability :
possible loss of digits through conversion of long type into int type


//line 1054:
retCode = C_GenerateKeyPair( hSession, &mech,
pubTemplate, sizeof(pubTemplate)/
sizeof(pubTemplate[0]),
privTemplate,
sizeof(privTemplate)/sizeof(privTemplate[0]),
&hPub, &hPriv);

env->ReleaseByteArrayElements(p, pbP, 0);
if( qLen )
env->ReleaseByteArrayElements(q, pbQ, 0);
if( gLen )
env->ReleaseByteArrayElements(g, pbG, 0);

if (retCode != CKR_OK) {
ThrowCryptokiException(env, "C_GenerateKeyPair", retCode);
return NULL;
}

jintArray returnValue = env->NewIntArray(2);
jint *piReturnValue = env->GetIntArrayElements(returnValue, 0);
//line 1072:
piReturnValue[0] = hPub;
//line 1073:
piReturnValue[1] = hPriv;
 
T

TsanChung

Most likely you cast a pointer to a jint. Without knowing
C_Initialize nobody can tell for sure.

Regards, Lothar
--
Lothar Kimmeringer                E-Mail: (e-mail address removed)
               PGP-encrypted mails preferred (Key-ID: 0x8BC3CD81)

Always remember: The answer is forty-two, there can only be wrong
                 questions!

There are a lot of source code so it is hard to post them.
Do you mean
"cast a pointer to a jint" is to check the different size of variables
when casting?

jint is equal to "signed 32 bits"
but size of pointer varies.
 
L

Lothar Kimmeringer

TsanChung said:
There are a lot of source code so it is hard to post them.

I didn't ask for the source ;-) But you might be able to
track down the place when checking when an error-code 0x30
is actually returned. Refactoring the C-source might help
as well or simply add printfs for a start (don't forget
to flush, otherwise you see the messages only at the end
of the lifetime of the virtual machine).
Do you mean
"cast a pointer to a jint" is to check the different size of variables
when casting?

I'm talking of a line like this:

jbyte *arr = env->GetByteArrayElements(aByteArray, 0);
return (jint) arr;

On 32-Bit-Systems this works, on 64-Bit-Systems it's breaking
because you lose half of the address. A solution (until you
have to deal with 128 Bit systems) is using jlong (that was
my solution for jCapi where I was in exactly that situation.
jint is equal to "signed 32 bits"
but size of pointer varies.

I know, but as long the size is < 32 Bit it doesn't matter.

Another reason might be that a library your JNI-library is
using is having the same problem. With a debugger or printfs
you should be able to track that down as well.


Regards, Lothar
--
Lothar Kimmeringer E-Mail: (e-mail address removed)
PGP-encrypted mails preferred (Key-ID: 0x8BC3CD81)

Always remember: The answer is forty-two, there can only be wrong
questions!
 
L

Lothar Kimmeringer

TsanChung said:
"./HwAPI.cpp", line 1072.24: 1540-5328 (I) 64-bit portability :
possible loss of digits through conversion of long type into int type

"./HwAPI.cpp", line 1073.24: 1540-5328 (I) 64-bit portability :
possible loss of digits through conversion of long type into int type [...]
&hPub, &hPriv);

What type is hPub and hPriv? I assume it's the address to a
structure containing a BigInteger (I interpret the prefix
h to be some kind of "handle").
//line 1072:
piReturnValue[0] = hPub;
//line 1073:
piReturnValue[1] = hPriv;

And here you cast an address to a jint.


Regards, Lothar
--
Lothar Kimmeringer E-Mail: (e-mail address removed)
PGP-encrypted mails preferred (Key-ID: 0x8BC3CD81)

Always remember: The answer is forty-two, there can only be wrong
questions!
 
T

TsanChung

TsanChung said:
"./HwAPI.cpp", line 1072.24: 1540-5328 (I) 64-bit portability :
possible loss of digits through conversion of long type into int type
"./HwAPI.cpp", line 1073.24: 1540-5328 (I) 64-bit portability :
possible loss of digits through conversion of long type into int type [...]
                                     &hPub, &hPriv);

What type is hPub and hPriv? I assume it's the address to a
structure containing a BigInteger (I interpret the prefix
h to be some kind of "handle").
//line 1072:
    piReturnValue[0] = hPub;
//line 1073:
 piReturnValue[1] = hPriv;

And here you cast an address to a jint.

Regards, Lothar
--
Lothar Kimmeringer                E-Mail: (e-mail address removed)
               PGP-encrypted mails preferred (Key-ID: 0x8BC3CD81)

Always remember: The answer is forty-two, there can only be wrong
                 questions!

hPub and hPriv are of type "unsigned long int" which is not defined in
JNI.
jint is "signed 32 bits" and
jlong is "signed 64 bits", so use jlong instead of jint.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,764
Messages
2,569,564
Members
45,039
Latest member
CasimiraVa

Latest Threads

Top