Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Fdb Arenas allocate structs not aligned, even though
fdb_c.h
explicitly specifies a 4bytes alignment for most of them (the others using their default alignment, 8bytes in general):foundationdb-rs/foundationdb-sys/include/710/fdb_c.h
Lines 88 to 92 in e846355
These alignment constraints are translated in Rust in bindings.rs by bindgen and exported by
foundationdb_sys
:foundationdb-rs/foundationdb-sys/build.rs
Lines 114 to 115 in e846355
And inherited by their "local wrappers":
foundationdb-rs/foundationdb/src/fdb_keys.rs
Lines 156 to 158 in e846355
Data is transferred between the fdbserver and foundationdb-rs via pointers which lead to this kind of code:
foundationdb-rs/foundationdb/src/fdb_keys.rs
Lines 42 to 49 in e846355
self.keys
is a C pointer that points to aFDBKey
potentially misaligned in a Fdb Arena. In the newer versions of Rustfrom_raw_parts
panics with debug_assertions on pointer misalignment. Even if we ignore this, the fact that misaligned structs are currently read correctly is probably due to x86 compliance but is still undefined behavior.In this PR, "local wrappers" are annotated with
packed
instead oftransparent
:https://github.com/Wonshtrum/foundationdb-rs/blob/c6b198ddef85ca77bab40ea11cda1c08c9d09e35/foundationdb/src/fdb_keys.rs#L157-L159
This explicitly tells Rust that we do not expect these structs to be aligned. This removes the panics on newer versions as these structs are 1byte align (which a pointer will always be) and furthermore, we do not have to rely on x86 to magically accept unaligned structs as misalignment will be explicitly taken care of at machine code generation.
These wrappers are used everywhere in favor of their raw counterparts from
fdb_sys
, andderef
functions are rewritten using this form:https://github.com/Wonshtrum/foundationdb-rs/blob/c6b198ddef85ca77bab40ea11cda1c08c9d09e35/foundationdb/src/fdb_keys.rs#L46-L50