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

w32 struct return values #490

Closed
twall opened this issue Aug 24, 2015 · 2 comments
Closed

w32 struct return values #490

twall opened this issue Aug 24, 2015 · 2 comments

Comments

@twall
Copy link
Contributor

twall commented Aug 24, 2015

If JNA is compiled with a different compiler than your target library, you may see a crash when returning a struct of size greater than 8 bytes. This is because GCC, mingw-gcc, and MSVC don't necessarily agree on how to handle such a scenario.

This turned up when building and testing with mingw32 (x86 target) calling a callback with a returned struct. There is some accommodation within libffi to handle GCC vs MSVC calling conventions, but the JNA code should really test all permutations to ensure it works properly:

Simple call to native function returning struct:

  • Java -> JNA (mingw) -> native (MSVC)
  • Java -> JNA (MSVC) -> native (mingw)
  • Java -> JNA (MSVC) -> native (MSVC) (tested, OK)
  • Java -> JNA (mingw) -> native (mingw) (tested, OK)

Call to native function returning struct returned by a provided callback. Note that the calling and callback handling glue (libffi) will always be compiled by the same compiler:

  • Java -> JNA (mingw) -> native (mingw) -> JNA (callback mingw) (tested, fails)
  • Java -> JNA (MSVC) -> native (MSVC) -> JNA (callback MSVC) (tested, OK)
  • Java -> JNA (MSVC) -> native (mingw) -> JNA (callback MSVC)
  • Java -> JNA (mingw) -> native (MSVC) -> JNA (callback mingw)
@twall
Copy link
Contributor Author

twall commented Sep 7, 2015

This is caused by a merge error in libffi proper, filed an issue.

@twall
Copy link
Contributor Author

twall commented Sep 7, 2015

The FFI_MS_CDECL ABI will only have an effect in closures. Its usage in ffi_call() is irrelevant, since ffi_call generally ignores what the callee does to the stack, manually providing storage for a returned structure.

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

No branches or pull requests

1 participant