[foreign] RFR: Windows support

Jorn Vernee jbvernee at xs4all.nl
Wed Jan 9 21:17:06 UTC 2019


Hi,

I have fixed the last few failing tests on Windows so this is an RFR for 
adding Windows support to Panama FFI. There's a lot of changes so I've 
split it into 4 patches. We should probably focus on one of these one at 
a time, but I wanted to include all the changes needed to pass the tests 
at least. It's probably best to start with [2], since that implements 
the core functionality.

Default lib fixes [1] (needed for the default library to work on 
Windows)
Hotspot, binder tweaks [2] (Changes to the stub generation and shared 
binder code. Includes the Windows implementation of SystemABI)
jextract tweaks [3] (minor jextract portability changes)
test tweaks [4] (changes needed to run, and pass the tests on Windows)

There are some tests that are disabled:
   - EmptyStructTest; Empty structs are a GCC extension.
   - BadBitfieldTest; this is testing for a problem the MSVC ABI doesn't 
seem to have.
   - StdioTest; relies on standard system header path, which on Windows 
is more tricky to find.
   - ComplexTest; Windows complex types work very differently in C 
source, so the current test doesn't compile.
   - LongDoubleTest; long double is only 64 bits on Windows. This might 
need a replacement test still, but it should work the same as `double` 
on Windows.
   - Getpid; No getpid on Windows in the C standard.
   - UnixSystem; Windows is not unix.

(Some tests specifically for Windows could be added, but I'm leaving 
that for a different RFR)

Changes for [1]:
   - replace default library handle with a findEntryInProcess since 
Windows doesn't have an RTLD_DEFAULT equivalent.

Changes for [2]:
   - changed upcall/downcall stub generation to follow the MS ABI on 
windows (using compiler switches)
   - added SKIPs to shuffle recipe generation when e.g. the first float 
is passed in the second float register (which can be the case on 
windows).
   - moved boxValue and unboxValue into SystemABI, since they turned out 
to be ABI specific, and made tweaks to the windows version for handeling 
structs being passed by value.
   - moved upcall stub natives into shared ABI package.
   - Let each ABI have it's own VarargsInvoker implementation, since we 
need to propagate more info about which arguments are variadic on 
windows.
   - CallingSequence::storageOffset is no longer relying on 
Storage::getStorageIndex, since that is not the same as what's actually 
needed; being the index of the binding. (the 2 can differ on windows, 
but not on sysv).
   - Added Windows ABI implementation classes based on the SysV ones.
   - Let UniversalUpcallHandler write the in-memory-return pointer to RAX 
since that is required on Windows (and I think this change is portable).

Changes for [3]:
   - instead of hardcoding the size of `long` `unsigned long` and `long 
double`, delegate to libclang to tell us the size, since these types 
have different sizes on the 2 ABIs. (This is pretty ad-hoc, so probably 
needs to be improved. But, I have little experience with the jextract 
code, so I'm open to suggestion of how to better fix this)

Changes for [4]:
   - added dll exports for native symbols using compiler switches.
   - added test for small (fits-in-register) struct by-value passing, 
since windows has special handling for those.
   - removed depencies on POSIX functions from some tests where it wasn't 
really needed, so they could run on windows.
   - propagate clang library name to TestJextractFFI, since on Windows we 
need to load "libclang".
   - let Runner test use windows specific files to compare with for 
bitfields.h and simple.h
   - use `long long` instead of `long` in some cases since `long long` is 
64 bits on SysV and MSx64

Thanks,
Jorn

[1] : 
http://cr.openjdk.java.net/~jvernee/panama/webrevs/8211060/webrev.01/
[2] : 
http://cr.openjdk.java.net/~jvernee/panama/webrevs/windows/webrev.03/
[3] : 
http://cr.openjdk.java.net/~jvernee/panama/webrevs/windows_jextract/webrev.00/
[4] : 
http://cr.openjdk.java.net/~jvernee/panama/webrevs/windows_tests/webrev.02/


More information about the panama-dev mailing list