From 51ba4b646e5e21e658c8ca77623b0cbc46e41a7a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Matthias=20Bl=C3=A4sing?= Date: Fri, 11 Mar 2022 21:52:51 +0100 Subject: [PATCH 1/3] Fix crash in direct callbacks on mac OS aarch64 libffi requires the number of fixed arguments to an ffi call to be correctly provided. For the callback case the conversion routine supplied the wrong number of arguments for the dispatch into java. The JNI callbacks have the signature: NativeType CallMethod(JNIEnv *env, jobject obj, jmethodID methodID, ...); so the first three arguments are fixed and the rest is passed as varargs. --- CHANGES.md | 1 + native/callback.c | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/CHANGES.md b/CHANGES.md index 5d3279a80c..d40aa62ff7 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -16,6 +16,7 @@ Bug Fixes --------- * [#1411](https://github.com/java-native-access/jna/pull/1411): Do not throw `Win32Exception` on success for empty section in `Kernel32Util#getPrivateProfileSection` - [@mkarg](https://github.com/mkarg). * [#1414](https://github.com/java-native-access/jna/pull/1414): Fix definition of `c.s.j.p.unix.X11.XK_Shift_R` - [@matthiasblaesing](https://github.com/matthiasblaesing). +* [#1323](https://github.com/java-native-access/jna/issues/1323). Fix crashes in direct callbacks on mac OS aarch64 - [@matthiasblaesing](https://github.com/matthiasblaesing). Release 5.10.0 ============== diff --git a/native/callback.c b/native/callback.c index b127ce41d8..99a9e831a3 100644 --- a/native/callback.c +++ b/native/callback.c @@ -288,7 +288,7 @@ create_callback(JNIEnv* env, jobject obj, jobject method, case 'D': cb->fptr_offset = OFFSETOF(env, CallDoubleMethod); break; default: cb->fptr_offset = OFFSETOF(env, CallObjectMethod); break; } - status = ffi_prep_cif_var(&cb->java_cif, java_abi, 2, argc+3, java_return_type, cb->java_arg_types); + status = ffi_prep_cif_var(&cb->java_cif, java_abi, 3, argc+3, java_return_type, cb->java_arg_types); if (!ffi_error(env, "callback setup (2)", status)) { ffi_prep_closure_loc(cb->closure, &cb->cif, dispatch_callback, cb, cb->x_closure); From ec1754d3255f6e9eaec171054413b189578d6f71 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Matthias=20Bl=C3=A4sing?= Date: Sat, 12 Mar 2022 16:02:40 +0100 Subject: [PATCH 2/3] IOKit: For testing parent-child-operator validity don't assume controller names or types --- .../platform/test/com/sun/jna/platform/mac/IOKitTest.java | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/contrib/platform/test/com/sun/jna/platform/mac/IOKitTest.java b/contrib/platform/test/com/sun/jna/platform/mac/IOKitTest.java index 02ac90f9cf..6ab22aa844 100644 --- a/contrib/platform/test/com/sun/jna/platform/mac/IOKitTest.java +++ b/contrib/platform/test/com/sun/jna/platform/mac/IOKitTest.java @@ -30,6 +30,7 @@ import static org.junit.Assert.assertNotNull; import static org.junit.Assert.assertNull; import static org.junit.Assert.assertTrue; +import static org.junit.Assume.assumeTrue; import java.util.HashSet; import java.util.Set; @@ -166,8 +167,7 @@ public void testIteratorParentChild() { // Get device name String controllerName = controllerDevice.getName(); - // Root controllers always begin with "AppleUSB" - assertEquals("AppleUSB", controllerName.substring(0, 8)); + assertNotNull(controllerName); // Get the first child, to test vs. iterator boolean testFirstChild = true; @@ -177,7 +177,6 @@ public void testIteratorParentChild() { IOIterator childIter = controllerDevice.getChildIterator(IO_SERVICE); IORegistryEntry childDevice = childIter.next(); while (childDevice != null) { - assertTrue(childDevice.conformsTo("IOUSBDevice")); long childId = childDevice.getRegistryEntryID(); assertTrue(childId > 19); assertFalse(uniqueEntryIdSet.contains(childId)); From 988cd08e1f769f51c9796c7839058f4b6f87b8c5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Matthias=20Bl=C3=A4sing?= Date: Sat, 12 Mar 2022 19:10:54 +0100 Subject: [PATCH 3/3] Fix build on appveyor (seems perl package was inconsistent without updates) --- appveyor.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/appveyor.yml b/appveyor.yml index 9c70df44d6..5f062ed88b 100644 --- a/appveyor.yml +++ b/appveyor.yml @@ -31,7 +31,7 @@ install: # Must prepend cygwin PATH to avoid "cygheap base mismatch" from Git\usr\bin\sed - cmd: set PATH=C:\cygwin64;C:\cygwin64\bin;%JAVA_HOME%\bin;%PATH%; - cmd: choco install -y -f -i %CHOCO_PACKAGES% - - cmd: '%CYGWIN_SETUP% --root C:\cygwin64 --local-package-dir C:\cygwin64\packages --quiet-mode --no-desktop --no-startmenu --packages %CYGWIN_PACKAGES%' + - cmd: '%CYGWIN_SETUP% --root C:\cygwin64 --local-package-dir C:\cygwin64\packages --quiet-mode --no-desktop --no-startmenu --upgrade-also --packages %CYGWIN_PACKAGES%' # Setup msvc environment for: