Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix crash in direct callbacks on mac OS aarch64 #1419

Conversation

matthiasblaesing
Copy link
Member

@matthiasblaesing matthiasblaesing commented Mar 11, 2022

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.

Closes: #1323

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 Call<type>Method(JNIEnv *env, jobject obj, jmethodID methodID, ...);

so the first three arguments are fixed and the rest is passed as
varargs.
@matthiasblaesing
Copy link
Member Author

@dkocher could you please have a look at this? After this this I still see a testfailure in the jna-platform, but I suspect, that that is problem with false assumptions.

@dbwiddis could you please have a look at this:

    [junit] Tests run: 4, Failures: 1, Errors: 0, Skipped: 0, Time elapsed: 0.137 sec
    [junit] 
    [junit] Testcase: testIteratorParentChild(com.sun.jna.platform.mac.IOKitTest):	FAILED
    [junit] null
    [junit] junit.framework.AssertionFailedError
    [junit] 	at com.sun.jna.platform.mac.IOKitTest.testIteratorParentChild(IOKitTest.java:149)
    [junit] 	at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    [junit] 	at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:77)
    [junit] 	at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    [junit] 
    [junit] 
    [junit] Test com.sun.jna.platform.mac.IOKitTest FAILED

I'm on a remote machine, where I'm just a user, so I might lack the permissions to get that information. Maybe you have an idea how I could pin point that.

@dbwiddis
Copy link
Contributor

After this this I still see a testfailure in the jna-platform, but I suspect, that that is problem with false assumptions.

As the author of that test, I concur with the "false assumptions" conclusion. The failure is that the USB Controller IO registry entry has a different name on M1 than on other Macs.

IOIterator iter = IOKitUtil.getMatchingServices("IOUSBController");
assertNotNull(iter);

I fixed this on my own project: Issue: oshi/oshi#1483 Fix: oshi/oshi#1488

I'll update the JNA test.

@matthiasblaesing matthiasblaesing force-pushed the fix_crash_directcallback_mac_aarch64 branch from eb32223 to 988cd08 Compare March 12, 2022 18:26
@matthiasblaesing
Copy link
Member Author

@dkocher @dbwiddis thank you for having a look at this.

@matthiasblaesing matthiasblaesing merged commit 0774f82 into java-native-access:master Mar 14, 2022
@matthiasblaesing matthiasblaesing deleted the fix_crash_directcallback_mac_aarch64 branch March 14, 2022 20:21
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Test failures on Apple silicon (aarch64)
2 participants