[foreign-memaccess+abi] RFR: 8287516: Implement fallback Linker [v5]
Maurizio Cimadamore
mcimadamore at openjdk.org
Fri Jan 20 13:07:11 UTC 2023
On Fri, 20 Jan 2023 13:02:52 GMT, Jorn Vernee <jvernee at openjdk.org> wrote:
>> src/java.base/share/classes/jdk/internal/foreign/abi/fallback/FFIType.java line 129:
>>
>>> 127: try (Arena verifyArena = Arena.openConfined()) {
>>> 128: MemorySegment offsetsOut = verifyArena.allocate(SIZE_T.byteSize() * filteredLayouts.size());
>>> 129: LibFallback.getStructOffsets(structType, offsetsOut, abi);
>>
>> Maybe I'm being paranoid, but libFFI has its own way to determine a struct layout given the struct fields, based on what the ABI types are. But the Panama layout API is more expressive than that, and it allows, theoretically, to pass arguments that have stricter or larger alignment constraints - which can end up in more or less padding being inserted (from clients), and in different struct layout sizes.
>>
>> So, my question is: should we double check that what we get back from libFFI is actually compatible with what we have in the group layout before proceeding?
>
> Yes, that is exactly what this code (`verifyStructType`) is trying to do.
>
> Note that we also already reject layouts that do not have natural alignment [1](https://github.com/openjdk/panama-foreign/blob/foreign-memaccess%2Babi/src/java.base/share/classes/jdk/internal/foreign/abi/AbstractLinker.java#L111) Though, we might want to relax that constraint in the future.
More specifically, if a struct has extra padding, then I wonder if libFFI could expect a struct size that is smaller than the size of the memory segment passed in by a Panama client (because that segment also has the extra padding). In our usual JDK-driven classification, we would take the struct, extract its field components and place them on registers and/or stack slots. But with libFFI, we just have to provide the struct segment in a buffer, which then libFFI will act upon - if there is a size mismatch there, I think it might have dire consequences?
-------------
PR: https://git.openjdk.org/panama-foreign/pull/770
More information about the panama-dev
mailing list