nativelibs4java / BridJ

BridJ: blazing fast Java / C / C++ interop
https://code.google.com/archive/p/bridj/
Other
297 stars 77 forks source link

JVM crash "C [bridj.dll+0x17c7a]" #97

Open maryangelica opened 7 years ago

maryangelica commented 7 years ago

Hi guys,

I am using this library to use communicate with a DLL, I don't have the source code, I just have the example about how is called this dll using Visual Basic, here the declaration in Visual Basic:

Declare Function fiOpenPort Lib "pinpadbox.dll" (ByRef ConfigFileName As String) As Short Declare Function fiClosePort Lib "pinpadbox.dll" () As Short Declare Function fiStartOperation Lib "pinpadbox.dll" (ByRef pucTipoOperation As String, ByRef iTimeOut As Short, ByRef pucResponse As String) As Short Declare Function fiGetStatus Lib "pinpadbox.dll" (ByRef sBuffer As String, ByVal SizeBuffer As Short) As Short

And with that in mind I created this header file:

#ifndef PINPADBOX_H_
#define PINPADBOX_H_
class __declspec(dllimport) PINPADBOX
{
public:
    PINPADBOX();          // Class Constructor
    ~PINPADBOX();         // Class destructor
    short fiOpenPort(char**);   // Class function fiOpenPort
    short fiClosePort();   // Class function Subtract
    short fiStartOperation(char**,short*,char**);
    short fiGetStatus(char **,short);//I tested char & but no returns.
};
#endif /* PINPADBOX*/

I used JNAerator 0.13, the problem starts with the method fiGetStatus, because the first parameter a String by reference and each certain time update the value, sometimes I run the same lines of code and its run without problems, run again and the JVM crash showing problem on bridj.dll, this occurs at the moment the first variable returns with results. Here part of the code:

Pointer<Pointer<Byte>> getStatusPARAM1 = Pointer.pointerToCStrings("");
PINPADBOX box = new PINPADBOX();
short y2=0;
do{
 getStatusPARAM1.get().set(Byte.parseByte("0")); //I tested with getStatusPARAM1.pointerToCString("")/getStatusPARAM1.set(Pointer.pointerToCString(""));/without this line and the same error
y2 = box.fiGetStatus(getStatusPARAM1, Short.valueOf("512"));
if(y2 > 0){
for(int i=0;i<getStatusPARAM1.get().getByteBuffer(y2).remaining();i++){
String obtByte = String.valueOf((char)getStatusPARAM1.get().getByteBuffer(y2).get(i));
strBu.append(obtByte);                                              
}
if(strBu.lastIndexOf("C1")>0){                      
        break;
}
}while(resultStartOper>=0);
getStatusPARAM1.release();

The hs_err_pid is:

EXCEPTION_ACCESS_VIOLATION (0xc0000005) at pc=0x502a7c7a, pid=14540, tid=0x00005778

C [bridj.dll+0x17c7a]

Current thread (0x0013cc00): JavaThread "main" [_thread_in_native, id=22392, stack(0x00640000,0x00690000)]

siginfo: ExceptionCode=0xc0000005, reading address 0x00000000 Register to memory mapping:

EAX=0x00000000 is an unknown value EBX={method} {0x14c31aec} 'fiGetStatus' '(JS)S' in 'pinpadbox/PINPADBOX' ECX=0x00000000 is an unknown value EDX=0x15080a98 is an unknown value

Stack: [0x00640000,0x00690000], sp=0x0068f474, free space=317k Native frames: (J=compiled Java code, j=interpreted, Vv=VM code, C=native code) C [bridj.dll+0x17c7a] C [bridj.dll+0x3f04] C [bridj.dll+0x1a34] C [bridj.dll+0xb903] j pinpadbox.PINPADBOX.fiGetStatus(JS)S+0 j pinpadbox.PINPADBOX.fiGetStatus(Lorg/bridj/Pointer;S)S+6 j test.BridJCard.main([Ljava/lang/String;)V+380

Internal exceptions (10 events): Event: 0.781 Thread 0x0013cc00 Exception <a 'java/lang/NoSuchMethodError': fiGetStatus> (0x04a53150) thrown at [C:\re\workspace\8-2-build-windows-i586-cygwin\jdk8u112\7884\hotspot\src\share\vm\prims\jni.cpp, line 1613] Event: 0.781 Thread 0x0013cc00 Exception <a 'java/lang/NoSuchMethodError': fiClosePort> (0x04a53398) thrown at [C:\re\workspace\8-2-build-windows-i586-cygwin\jdk8u112\7884\hotspot\src\share\vm\prims\jni.cpp, line 1613] Event: 0.795 Thread 0x0013cc00 Exception <a 'java/lang/ArrayIndexOutOfBoundsException'> (0x04ab9710) thrown at [C:\re\workspace\8-2-build-windows-i586-cygwin\jdk8u112\7884\hotspot\src\share\vm\runtime\sharedRuntime.cpp, line 605] Event: 0.812 Thread 0x0013cc00 Exception <a 'java/lang/ArrayIndexOutOfBoundsException'> (0x04b37ed8) thrown at [C:\re\workspace\8-2-build-windows-i586-cygwin\jdk8u112\7884\hotspot\src\share\vm\runtime\sharedRuntime.cpp, line 605] Event: 0.813 Thread 0x0013cc00 Exception <a 'java/lang/ArrayIndexOutOfBoundsException'> (0x04b39620) thrown at [C:\re\workspace\8-2-build-windows-i586-cygwin\jdk8u112\7884\hotspot\src\share\vm\runtime\sharedRuntime.cpp, line 605] Event: 0.813 Thread 0x0013cc00 Exception <a 'java/lang/ArrayIndexOutOfBoundsException'> (0x04b3b1e0) thrown at [C:\re\workspace\8-2-build-windows-i586-cygwin\jdk8u112\7884\hotspot\src\share\vm\runtime\sharedRuntime.cpp, line 605] Event: 0.813 Thread 0x0013cc00 Exception <a 'java/lang/ArrayIndexOutOfBoundsException'> (0x04b3c450) thrown at [C:\re\workspace\8-2-build-windows-i586-cygwin\jdk8u112\7884\hotspot\src\share\vm\runtime\sharedRuntime.cpp, line 605] Event: 0.814 Thread 0x0013cc00 Exception <a 'java/lang/ArrayIndexOutOfBoundsException'> (0x04b3eca0) thrown at [C:\re\workspace\8-2-build-windows-i586-cygwin\jdk8u112\7884\hotspot\src\share\vm\runtime\sharedRuntime.cpp, line 605] Event: 0.814 Thread 0x0013cc00 Exception <a 'java/lang/ArrayIndexOutOfBoundsException'> (0x04b40778) thrown at [C:\re\workspace\8-2-build-windows-i586-cygwin\jdk8u112\7884\hotspot\src\share\vm\runtime\sharedRuntime.cpp, line 605] Event: 0.814 Thread 0x0013cc00 Exception <a 'java/lang/ArrayIndexOutOfBoundsException'> (0x04b419c8) thrown at [C:\re\workspace\8-2-build-windows-i586-cygwin\jdk8u112\7884\hotspot\src\share\vm\runtime\sharedRuntime.cpp, line 605]

Could you get me some clue to resolve this? I guess at the moment to recover the data, doesn't match the size of the field.... but I'm not sure.

Thanks in advance