twall/jna — Issue #56: Exception Access Violation using Native.invokeInt
Author: skestle
Created: 2012-03-01 12:14:39+00:00
State: open

I'm getting the following c exception (presumably in the jna dll?? I've been developing with Canon's EDSDK and am returning from a dispatched event.

The last java line executed is CallbackReference callback(Object[]), and it's returning an Integer of 0.

Am I doing something wrong, is there a bug in JNA, or is this a JVM bug?

I've replicated in JNA 3.3.0 and 3.4.0, as well as jdk 6.0_17 and jre 6.0_30

```
#
# A fatal error has been detected by the Java Runtime Environment:
#
# EXCEPTION_ACCESS_VIOLATION (0xc0000005) at pc=0x18667504, pid=11744, tid=12368
#
# JRE version: 6.0_30-b12
# Java VM: Java HotSpot(TM) Client VM (20.5-b03 mixed mode windows-x86 )
# Problematic frame:
# C 0x18667504
#
# If you would like to submit a bug report, please visit:
# http://java.sun.com/webapps/bugreport/crash.jsp
# The crash happened outside the Java Virtual Machine in native code.
# See problematic frame for where to report the bug.
#

--------------- T H R E A D ---------------

Current thread (0x017d9800): JavaThread "main" [_thread_in_native, id=12368, stack(0x00370000,0x003c0000)]

siginfo: ExceptionCode=0xc0000005, reading address 0x00000000

Registers:
EAX=0x00000000, EBX=0x00000000, ECX=0x003bf0dc, EDX=0x18241b6c
ESP=0x003bf110, EBP=0x003bf150, ESI=0x18666f78, EDI=0x00000201
EIP=0x18667504, EFLAGS=0x00010246

Top of Stack: (sp=0x003bf110)
0x003bf110: 00000001 183fb61c 18962ab8 9df3eaed
0x003bf120: 18662f40 18660c68 1895caf0 18951870
0x003bf130: 00000001 00000000 18667500 00000000
0x003bf140: 003bf11c 003bf234 1842f1eb ffffffff
0x003bf150: 18662f08 1840d114 00000000 18662f40
0x003bf160: 183f047d 18660c68 000c1272 00000000
0x003bf170: 003bf1c8 00000000 773941d4 1895cac0
0x003bf180: 0000c092 18662f58 18662f40 1895cac0

Instructions: (pc=0x18667504)
0x186674e4: 03 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
0x186674f4: 00 00 00 00 a5 97 d6 18 00 00 00 8c 1c 5f 43 18
0x18667504: 02 30 00 00 70 2a 96 18 7c 2a 96 18 7c 2a 96 18
0x18667514: 01 38 00 00 99 97 d6 18 00 00 00 88 00 00 00 00

Register to memory mapping:

EAX=0x00000000 is an unknown value
EBX=0x00000000 is an unknown value
ECX=0x003bf0dc is pointing into the stack for thread: 0x017d9800
EDX=0x18241b6c is an unknown value
ESP=0x003bf110 is pointing into the stack for thread: 0x017d9800
EBP=0x003bf150 is pointing into the stack for thread: 0x017d9800
ESI=0x18666f78 is an unknown value
EDI=0x00000201 is an unknown value

Stack: [0x00370000,0x003c0000], sp=0x003bf110, free space=316k
Native frames: (J=compiled Java code, j=interpreted, Vv=VM code, C=native code)
C 0x18667504

Java frames: (J=compiled Java code, j=interpreted, Vv=VM code)
j com.sun.jna.Native.invokeInt(JI[Ljava/lang/Object;)I+0
j com.sun.jna.Function.invoke([Ljava/lang/Object;Ljava/lang/Class;Z)Ljava/lang/Object;+333
j com.sun.jna.Function.invoke(Ljava/lang/Class;[Ljava/lang/Object;Ljava/util/Map;)Ljava/lang/Object;+214
j com.sun.jna.Library$Handler.invoke(Ljava/lang/Object;Ljava/lang/reflect/Method;[Ljava/lang/Object;)Ljava/lang/Object;+341
j $Proxy2.DispatchMessage(Lcom/sun/jna/platform/win32/WinUser$MSG;)Lcom/sun/jna/platform/win32/WinDef$LRESULT;+16
j net.kestle.platform.windows.User32$.dispatchMessage(Lcom/sun/jna/platform/win32/WinUser$MSG;)Lcom/sun/jna/platform/win32/WinDef$LRESULT;+5
j EosTest$.consumeAndDispachMessage()V+27
j EosTest$.main([Ljava/lang/String;)V+110
j EosTest.main([Ljava/lang/String;)V+4
v ~StubRoutines::call_stub

--------------- P R O C E S S ---------------

Java Threads: ( => current thread )
0x019bfc00 JavaThread "Low Memory Detector" daemon [_thread_blocked, id=11988, stack(0x17cd0000,0x17d20000)]
0x019b2800 JavaThread "C1 CompilerThread0" daemon [_thread_blocked, id=12548, stack(0x17c80000,0x17cd0000)]
0x019b1800 JavaThread "Attach Listener" daemon [_thread_blocked, id=13580, stack(0x17c30000,0x17c80000)]
0x019ae800 JavaThread "Signal Dispatcher" daemon [_thread_blocked, id=11152, stack(0x17be0000,0x17c30000)]
0x01974c00 JavaThread "Finalizer" daemon [_thread_blocked, id=13724, stack(0x17b90000,0x17be0000)]
0x01970000 JavaThread "Reference Handler" daemon [_thread_blocked, id=12296, stack(0x17b40000,0x17b90000)]
=>0x017d9800 JavaThread "main" [_thread_in_native, id=12368, stack(0x00370000,0x003c0000)]

Other Threads:
0x0196cc00 VMThread [stack: 0x17af0000,0x17b40000] [id=13500]
0x019da800 WatcherThread [stack: 0x17d20000,0x17d70000] [id=7384]

VM state:not at safepoint (normal execution)

VM Mutex/Monitor currently owned by a thread: None

Heap
def new generation total 4928K, used 2377K [0x039e0000, 0x03f30000, 0x08f30000)
eden space 4416K, 44% used [0x039e0000, 0x03bcd5a0, 0x03e30000)
from space 512K, 78% used [0x03eb0000, 0x03f14e98, 0x03f30000)
to space 512K, 0% used [0x03e30000, 0x03e30000, 0x03eb0000)
tenured generation total 10944K, used 0K [0x08f30000, 0x099e0000, 0x139e0000)
the space 10944K, 0% used [0x08f30000, 0x08f30000, 0x08f30200, 0x099e0000)
compacting perm gen total 12288K, used 5795K [0x139e0000, 0x145e0000, 0x179e0000)
the space 12288K, 47% used [0x139e0000, 0x13f88ec0, 0x13f89000, 0x145e0000)
No shared spaces configured.

Code Cache [0x019e0000, 0x01a88000, 0x039e0000)
total_blobs=266 nmethods=107 adapters=95 free_code_cache=32888704 largest_free_block=0

Dynamic libraries:
0x00400000 - 0x00425000	C:\Program Files\Java\jre6\bin\javaw.exe
0x77940000 - 0x77a7c000	C:\Windows\SYSTEM32\ntdll.dll
0x76b90000 - 0x76c64000	C:\Windows\system32\kernel32.dll
0x75cc0000 - 0x75d0a000	C:\Windows\system32\KERNELBASE.dll
0x77500000 - 0x775a0000	C:\Windows\system32\ADVAPI32.dll
0x76de0000 - 0x76e8c000	C:\Windows\system32\msvcrt.dll
0x76b70000 - 0x76b89000	C:\Windows\SYSTEM32\sechost.dll
0x772b0000 - 0x77351000	C:\Windows\system32\RPCRT4.dll
0x77360000 - 0x77429000	C:\Windows\system32\USER32.dll
0x76d90000 - 0x76dde000	C:\Windows\system32\GDI32.dll
0x77b60000 - 0x77b6a000	C:\Windows\system32\LPK.dll
0x77aa0000 - 0x77b3d000	C:\Windows\system32\USP10.dll
0x77b40000 - 0x77b5f000	C:\Windows\system32\IMM32.DLL
0x77430000 - 0x774fc000	C:\Windows\system32\MSCTF.dll
0x7c340000 - 0x7c396000	C:\Program Files\Java\jre6\bin\msvcr71.dll
0x6d7f0000 - 0x6da9f000	C:\Program Files\Java\jre6\bin\client\jvm.dll
0x73900000 - 0x73932000	C:\Windows\system32\WINMM.dll
0x75a00000 - 0x75a4b000	C:\Windows\system32\apphelp.dll
0x6d7a0000 - 0x6d7ac000	C:\Program Files\Java\jre6\bin\verify.dll
0x6d320000 - 0x6d33f000	C:\Program Files\Java\jre6\bin\java.dll
0x6d7e0000 - 0x6d7ef000	C:\Program Files\Java\jre6\bin\zip.dll
0x6d000000 - 0x6d14c000	C:\Program Files\Java\jre6\bin\awt.dll
0x718d0000 - 0x71921000	C:\Windows\system32\WINSPOOL.DRV
0x77680000 - 0x777dc000	C:\Windows\system32\ole32.dll
0x748a0000 - 0x74a3e000	C:\Windows\WinSxS\x86_microsoft.windows.common-controls_6595b64144ccf1df_6.0.7600.16661_none_420fe3fa2b8113bd\COMCTL32.dll
0x77250000 - 0x772a7000	C:\Windows\system32\SHLWAPI.dll
0x75650000 - 0x75666000	C:\Windows\system32\CRYPTSP.dll
0x73d70000 - 0x73dab000	C:\Windows\system32\rsaenh.dll
0x75150000 - 0x75167000	C:\Windows\system32\USERENV.dll
0x75ad0000 - 0x75adb000	C:\Windows\system32\profapi.dll
0x75a50000 - 0x75a5c000	C:\Windows\system32\CRYPTBASE.dll
0x6d600000 - 0x6d613000	C:\Program Files\Java\jre6\bin\net.dll
0x777e0000 - 0x77815000	C:\Windows\system32\WS2_32.dll
0x76c70000 - 0x76c76000	C:\Windows\system32\NSI.dll
0x75550000 - 0x7558c000	C:\Windows\system32\mswsock.dll
0x75670000 - 0x75676000	C:\Windows\System32\wship6.dll
0x739a0000 - 0x739b0000	C:\Windows\system32\NLAapi.dll
0x753a0000 - 0x753e4000	C:\Windows\system32\DNSAPI.dll
0x6f900000 - 0x6f908000	C:\Windows\System32\winrnr.dll
0x6f8f0000 - 0x6f900000	C:\Windows\system32\napinsp.dll
0x6f8d0000 - 0x6f8e2000	C:\Windows\system32\pnrpnsp.dll
0x6f8c0000 - 0x6f8cd000	C:\Windows\system32\wshbth.dll
0x6f890000 - 0x6f8b7000	C:\Program Files\Common Files\Microsoft Shared\Windows Live\WLIDNSP.DLL
0x77a80000 - 0x77a85000	C:\Windows\system32\PSAPI.DLL
0x6f7d0000 - 0x6f7f1000	C:\Program Files\Bonjour\mdnsNSP.dll
0x73740000 - 0x7375c000	C:\Windows\system32\Iphlpapi.DLL
0x73730000 - 0x73737000	C:\Windows\system32\WINNSI.DLL
0x75060000 - 0x75065000	C:\Windows\System32\wshtcpip.dll
0x6f720000 - 0x6f726000	C:\Windows\system32\rasadhlp.dll
0x71fb0000 - 0x71fe8000	C:\Windows\System32\fwpuclnt.dll
0x18160000 - 0x181d2000	C:\Users\Stephen\AppData\Local\Temp\jna\jna4222644062414367285.dll
0x183e0000 - 0x18454000	C:\development\Projects\TechShred\CanonEos\src\main\native\EDSDK.dll
0x76e90000 - 0x7702d000	C:\Windows\system32\SETUPAPI.dll
0x75d10000 - 0x75d37000	C:\Windows\system32\CFGMGR32.dll
0x76c80000 - 0x76d0f000	C:\Windows\system32\OLEAUT32.dll
0x75b50000 - 0x75b62000	C:\Windows\system32\DEVOBJ.dll
0x74580000 - 0x745c0000	C:\Windows\system32\uxtheme.dll
0x745e0000 - 0x745f3000	C:\Windows\system32\dwmapi.dll
0x68720000 - 0x68753000	C:\Windows\system32\STI.DLL
0x18a40000 - 0x18b44000	C:\development\Projects\TechShred\CanonEos\src\main\native\EdsImage.dll
0x75b70000 - 0x75b9d000	C:\Windows\system32\WINTRUST.dll
0x75ba0000 - 0x75cbc000	C:\Windows\system32\CRYPT32.dll
0x75b40000 - 0x75b4c000	C:\Windows\system32\MSASN1.dll
0x775f0000 - 0x77673000	C:\Windows\system32\CLBCatQ.DLL
0x18b50000 - 0x18bd9000	C:\Windows\system32\PortableDeviceApi.dll
0x6e590000 - 0x6e5bb000	C:\Windows\system32\PortableDeviceTypes.dll
0x746b0000 - 0x747a5000	C:\Windows\system32\PROPSYS.dll
0x75ac0000 - 0x75ace000	C:\Windows\system32\RpcRtRemote.dll
0x75ef0000 - 0x76b39000	C:\Windows\system32\SHELL32.dll
0x6f730000 - 0x6f763000	C:\Program Files\Windows Portable Devices\SqmApi.dll

VM Arguments:
jvm_args: -Djna.library.path=src\main\native -Dfile.encoding=Cp1252 -Xbootclasspath/p:C:\development\Tools\eclipse-indigo\configuration\org.eclipse.osgi\bundles\1061\1\.cp\lib\scala-library.jar;C:\development\Tools\eclipse-indigo\configuration\org.eclipse.osgi\bundles\1061\1\.cp\lib\scala-dbc.jar;C:\development\Tools\eclipse-indigo\configuration\org.eclipse.osgi\bundles\1061\1\.cp\lib\scala-swing.jar
java_command: EosTest
Launcher Type: SUN_STANDARD

Environment Variables:
JAVA_HOME=C:\Program Files\Java\jdk1.6.0_17
CLASSPATH=.;C:\Program Files\Java\jdk1.6.0_17\lib\ext\QTJava.zip;C:\Program Files\Java\jre6\lib\ext\QTJava.zip
PATH=C:/Program Files/Java/jre6/bin/client;C:/Program Files/Java/jre6/bin;C:/Program Files/Java/jre6/lib/i386;C:\Program Files\Common Files\Microsoft Shared\Windows Live;C:\Program Files\PC Connectivity Solution\;C:\Windows\system32;C:\Windows;C:\Windows\System32\Wbem;C:\Windows\System32\WindowsPowerShell\v1.0\;C:\Program Files\Common Files\Adobe\AGL;C:\Program Files\TortoiseSVN\bin;O:\CommonPlatform\build\ant\bin;C:\Program Files\Java\jdk1.6.0_17\bin;C:\development\Tools\Maven\bin;C:\Program Files\Windows Live\Shared;C:\development\Tools\pax-runner-1.5.0\bin;C:\Program Files\Git\cmd;C:\development\Tools\sbt;C:\Program Files\TortoiseHg\;C:\Program Files\QuickTime\QTSystem\;C:\development\Tools\eclipse-indigo;
USERNAME=Stephen
OS=Windows_NT
PROCESSOR_IDENTIFIER=x86 Family 6 Model 15 Stepping 10, GenuineIntel

--------------- S Y S T E M ---------------

OS: Windows 7 Build 7600

CPU:total 2 (2 cores per cpu, 1 threads per core) family 6 model 15 stepping 10, cmov, cx8, fxsr, mmx, sse, sse2, sse3, ssse3

Memory: 4k page, physical 3145016k(222444k free), swap 7503996k(2463040k free)

vm_info: Java HotSpot(TM) Client VM (20.5-b03) for windows-x86 JRE (1.6.0_30-b12), built on Nov 10 2011 01:51:00 by "java_re" with MS VC++ 7.1 (VS2003)

time: Fri Mar 02 00:51:33 2012
elapsed time: 9 seconds
```