The most likely issue here is an improper structure size/layout mapping. Since you seem to be using term definitions, that's even more likely the case given that FreeBSD is likely to have a different struct layout than most other systems (OSX *might* be close, but I doubt it).
Try running jnaerator to ensure your struct field mappings are of the proper sizes/types.
> Hi,
> we've been trying to port my PureJavaComm to FreeBSD.
> We've got it running on i32 Intel but if fails on AMD64.
> On i32 we tested with three JVMs:
> java -version
> java version "1.6.0_07"
> Diablo Java(TM) SE Runtime Environment (build 1.6.0_07-b02)
> Diablo Java HotSpot(TM) Client VM (build 10.0-b23, mixed mode, sharing)
> java -versionjava version "1.6.0_03-p4"
> Java(TM) SE Runtime Environment (build
> 1.6.0_03-p4-root_20_mar_2012_23_51-b00)
> Java HotSpot(TM) Client VM (build
> 1.6.0_03-p4-root_20_mar_2012_23_51-b00, mixed mode)
> java -versionopenjdk version "1.6.0_30"
> OpenJDK Runtime Environment (build 1.6.0_30-b24)
> OpenJDK Client VM (build 20.0-b12, mixed mode)
> The first two works always but with the OpenJDK we get random
> crashes. I'm not much worried about that, must be a bug in OpenJDK, right?
> Or is there something we could be doing wrong with JNA so that
> it works with one JVM but not with another in the same architecure?
> However, we have not been able to get this to work with FreeBSD on AMD64.
> The code is too long to show here (though it is available from github if
> someone wants to have a look), but basically it makes a series of tests
> that open and close a serial port, configure it differently and sends/
> receives
> bytes using one or two threads to do the job.
> Depending on the order of test we can run all test successfully.
> However one test, if not run as the last test, will cause the next test
> to hang.
> The hang always happens in a call to the OS'tcgetattr()' function. Now
> how can 'tcgetattr() hang?
> We also get frequent JVM crashes.
> Any thoughts appreciated as we really do not know how to proceed with
> the debugging....
> We did manage to grab a gdb stack trace of the hang situation
> but don't know what to make of it, I'll include it here.
> Oh, ah, this is with JNA 3.2.7 and java -version
> openjdk version "1.6.0_30-debug"
> OpenJDK Runtime Environment (build 1.6.0_30-debug-b24)
> OpenJDK 64-Bit Server VM (build 20.0-b12-jvmg, mixed mode)
> br Kusti
> GNU gdb 6.1.1 [FreeBSD]
> Copyright 2004 Free Software Foundation, Inc.
> GDB is free software, covered by the GNU General Public License, and you
> are
> welcome to change it and/or distribute copies of it under certain
> conditions.
> Type "show copying" to see the conditions.
> There is absolutely no warranty for GDB. Type "show warranty" for details.
> This GDB was configured as "amd64-marcel-freebsd"...
> Attaching to program: /usr/local/openjdk6/bin/java, process 48832
> Reading symbols from /lib/libz.so.5...done.
> Loaded symbols for /lib/libz.so.5
> Reading symbols from /lib/libthr.so.3...done.
> [New Thread 802465ac0 (LWP 101008/java)]
> [New Thread 802464e80 (LWP 100999/java)]
> [New Thread 802465040 (LWP 100984/java)]
> [New Thread 802465200 (LWP 100936/java)]
> [New Thread 8024653c0 (LWP 100882/java)]
> [New Thread 802465580 (LWP 100842/java)]
> [New Thread 802465740 (LWP 100837/java)]
> [New Thread 802465900 (LWP 100588/java)]
> [New Thread 800c0ae40 (LWP 100410/java)]
> [New Thread 800c041c0 (LWP 100634/initial thread)]
> Loaded symbols for /lib/libthr.so.3
> Reading symbols from /lib/libc.so.7...done.
> Loaded symbols for /lib/libc.so.7
> Reading symbols from
> /usr/local/openjdk6/jre/lib/amd64/server/libjvm.so...done.
> Loaded symbols for /usr/local/openjdk6/jre/lib/amd64/server/libjvm.so
> Reading symbols from /usr/lib/libstdc++.so.6...done.
> Loaded symbols for /usr/lib/libstdc++.so.6
> Reading symbols from /lib/libm.so.5...done.
> Loaded symbols for /lib/libm.so.5
> Reading symbols from /lib/libgcc_s.so.1...done.
> Loaded symbols for /lib/libgcc_s.so.1
> Reading symbols from /usr/local/openjdk6/jre/lib/amd64/libverify.so...done.
> Loaded symbols for /usr/local/openjdk6/jre/lib/amd64/libverify.so
> Reading symbols from /usr/local/openjdk6/jre/lib/amd64/libjava.so...done.
> Loaded symbols for /usr/local/openjdk6/jre/lib/amd64/libjava.so
> Reading symbols from /usr/local/openjdk6/jre/lib/amd64/libzip.so...done.
> Loaded symbols for /usr/local/openjdk6/jre/lib/amd64/libzip.so
> Reading symbols from /var/tmp/jna7175363690046903331.tmp...done.
> Loaded symbols for /var/tmp/jna7175363690046903331.tmp
> Reading symbols from /libexec/ld-elf.so.1...done.
> Loaded symbols for /libexec/ld-elf.so.1
> [Switching to Thread 802465ac0 (LWP 101008/java)]
> 0x00000008007792fc in __error () from /lib/libthr.so.3
> (gdb) thread apply all bt
> Thread 10 (Thread 800c041c0 (LWP 100634/initial thread)):
> #0 0x00000008007792fc in __error () from /lib/libthr.so.3
> #1 0x000000080077617a in pthread_kill () from /lib/libthr.so.3
> #2 0x000000000040a245 in ContinueInNewThread0 (continuation=0x404d50
> <JavaMain>,
> stack_size=1048576, args=0x7fffffffdd90) at
> ../../../../src/solaris/bin/java_md.c:1816
> #3 0x00000000004085b6 in ContinueInNewThread (ifn=0x7fffffffe630, argc=1,
> argv=0x800c0b0e8,
> jarfile=0x0, classname=0x7fffffffeab7
> "purejavacomm.testsuite.TestSuite", ret=0)
> at ../../../../src/share/bin/java.c:2000
> #4 0x0000000000404d44 in main (argc=1, argv=0x800c0b0e8) at
> ../../../../src/share/bin/java.c:353
> Thread 9 (Thread 800c0ae40 (LWP 100410/java)):
> #0 0x000000082165ba30 in throwByName () from
> /var/tmp/jna7175363690046903331.tmp
> #1 0x000000082165ee80 in dispatch () from
> /var/tmp/jna7175363690046903331.tmp
> #2 0x000000081c65a920 in ?? ()
> #3 0x00007fffffbfe228 in ?? ()
> #4 0x00007fffffbfe2c8 in ?? ()
> #5 0x00007fffffbfe318 in ?? ()
> #6 0x0000000802843b53 in ?? ()
> #7 0x0000000000000000 in ?? ()
> #8 0x0000000000000000 in ?? ()
> #9 0x0000000000000000 in ?? ()
> #10 0x000000081c274718 in ?? ()
> #11 0x0000000000000000 in ?? ()
> #12 0x0000000805a30db0 in ?? ()
> #13 0x0000000805a2fe88 in ?? ()
> #14 0x00007fffffbfe2d8 in ?? ()
> #15 0x000000081c65a172 in ?? ()
> #16 0x00007fffffbfe338 in ?? ()
> #17 0x000000081c669648 in ?? ()
> #18 0x000000081c786410 in ?? ()
> #19 0x000000081c65a200 in ?? ()
> #20 0x00007fffffbfe2c8 in ?? ()
> #21 0x00007fffffbfe338 in ?? ()
> #22 0x00007fffffbfe380 in ?? ()
> #23 0x00000008028439fa in ?? ()
> #24 0x0000000000000000 in ?? ()
> #25 0x0000000805a31130 in ?? ()
> #26 0x0000000805a2fe88 in ?? ()
> #27 0x00007fffffbfe340 in ?? ()
> #28 0x000000081c65dcc8 in ?? ()
> #29 0x00007fffffbfe398 in ?? ()
> #30 0x000000081c669648 in ?? ()
> #31 0x0000000000000000 in ?? ()
> #32 0x000000081c65dd18 in ?? ()
> #33 0x00007fffffbfe338 in ?? ()
> #34 0x00007fffffbfe398 in ?? ()
> #35 0x00007fffffbfe3e0 in ?? ()
> #36 0x00000008028439fa in ?? ()
> #37 0x0000000000000000 in ?? ()
> #38 0x0000000805a2fe88 in ?? ()
> #39 0x00007fffffbfe3a0 in ?? ()
> #40 0x000000081c70c7c0 in ?? ()
> #41 0x00007fffffbfe478 in ?? ()
> #42 0x000000081c714138 in ?? ()
> #43 0x000000081c76a780 in ?? ()
> #44 0x000000081c70c9e0 in ?? ()
> #45 0x00007fffffbfe398 in ?? ()
> #46 0x00007fffffbfe460 in ?? ()
> #47 0x00007fffffbfe4e0 in ?? ()
> #48 0x0000000802843b53 in ?? ()
> #49 0x0000000000000000 in ?? ()
> #50 0x0000000000000000 in ?? ()
> #51 0x0000000000000000 in ?? ()
> #52 0x0000000000000000 in ?? ()
> #53 0x0000000000000000 in ?? ()
> #54 0x0000000000000000 in ?? ()
> #55 0xdeaddeaf00000001 in ?? ()
> #56 0x0000000805a31110 in ?? ()
> #57 0x0000000000000000 in ?? ()
> #58 0x0000000000000000 in ?? ()
> #59 0x0000000000000000 in ?? ()
> #60 0x0000000000000000 in ?? ()
> #61 0x0000000000000000 in ?? ()
> #62 0x0000000805a30a80 in ?? ()
> #63 0x0000000000000000 in ?? ()
> #64 0x0000000805a30a68 in ?? ()
> #65 0x0000000000000000 in ?? ()
> #66 0x0000000000000000 in ?? ()
> #67 0x000000081c274718 in ?? ()
> #68 0x000000080d1218a8 in ?? ()
> #69 0x0000000000000079 in ?? ()
> #70 0x0000000000000000 in ?? ()
> #71 0x00007fffffbfe490 in ?? ()
> #72 0x000000081c6b406d in ?? ()
> #73 0x00007fffffbfe528 in ?? ()
> #74 0x000000081c6b4ad0 in ?? ()
> #75 0x000000081c782c88 in ?? ()
> #76 0x000000081c6b40f0 in ?? ()
> #77 0x00007fffffbfe470 in ?? ()
> #78 0x00007fffffbfe510 in ?? ()
> #79 0x00007fffffbfe570 in ?? ()
> #80 0x000000080284402d in ?? ()
> #81 0x0000000000000000 in ?? ()
> #82 0x0000000000000000 in ?? ()
> #83 0x000000080d0f0228 in ?? ()
> #84 0x000000080d117788 in ?? ()
> #85 0x0000000805a30a68 in ?? ()
> #86 0x000000080d0f4338 in ?? ()
> #87 0x000000080d0f01a0 in ?? ()
> #88 0x000000080d0f0178 in ?? ()
> #89 0x00007fffffbfe530 in ?? ()
> #90 0x000000081c6e6d37 in ?? ()
> #91 0x00007fffffbfe598 in ?? ()
> #92 0x000000081c6e85c0 in ?? ()
> #93 0x0000000000000000 in ?? ()
> #94 0x000000081c6e6d50 in ?? ()
> #95 0x00007fffffbfe510 in ?? ()
> #96 0x00007fffffbfe588 in ?? ()
> #97 0x00007fffffbfe5e0 in ?? ()
> #98 0x0000000802843fe8 in ?? ()
> #99 0x0000000000000000 in ?? ()
> #100 0x0000000805a2fe88 in ?? ()
> #101 0x0000000000000009 in ?? ()
> #102 0x000000080d0f01a0 in ?? ()
> #103 0x00007fffffbfe5a0 in ?? ()
> #104 0x000000081c6ad52d in ?? ()
> #105 0x00007fffffbfe610 in ?? ()
> #106 0x000000081c6af6b0 in ?? ()
> #107 0x0000000000000000 in ?? ()
> #108 0x000000081c6ad548 in ?? ()
> #109 0x00007fffffbfe588 in ?? ()
> #110 0x00007fffffbfe600 in ?? ()
> #111 0x00007fffffbfe658 in ?? ()
> #112 0x0000000802843fe8 in ?? ()
> #113 0x0000000000000000 in ?? ()
> #114 0x0000000805a2fe88 in ?? ()
> #115 0x0000000805a2a6a8 in ?? ()
> #116 0x0000000000000009
...