warning: `extern` block uses type `std::arch::x86_64::__m128i`, which is not FFI-safe
--> src/aes_low_level/vaes.rs:265:19
|
265 | keys: *const __m128i,
| ^^^^^^^^^^^^^^ not FFI-safe
|
= note: `#[warn(improper_ctypes)]` on by default
= help: consider adding a `#[repr(C)]` or `#[repr(transparent)]` attribute to this struct
= note: this struct has unspecified layout
I think this sentence within the error message is kind of misleading: the struct has unspecified ABI, but a well-specified layout.
If the extern "C" function were to use a __m128i by value, then this could indeed be problematic since so doing relies on the ABI of that type (which, includes, among other things, the layout of the type).
However, your function does not use a __m128i by value, but through pointer indirection. This leads to relying on the ABI of a (slim) pointer, which is well defined. Later on, though, if code dereferences that pointer it can still be problematic, since so doing relies on the layout (and the layout only!) of the pointee.
But, AFAIK, the layout of a __m128i is well defined! It's a 16-byte-long and 8-byte-aligned (this is the part I'm not 100% sure about) bag of bytes.
In that case, if you (stack-)allocate, for instance, a __m128i local, and then give its address to func, all should be fine.
Thank you for the answer!
Indeed I never use it as value across FFI boundary.
So is this something that should be reported as a bug in rustc?
I'm really not very knowledgeable with FFI and especially this deep. Also this scope of functionality seems to be used by rather small number of people, so it is really hard to find answers.