Skip to content
This repository was archived by the owner on Nov 6, 2024. It is now read-only.

Commit 155e29e

Browse files
committed
doc: Add instructions for generating bindings
Describe what needs to be done to not break serialization support. Signed-off-by: Patrick Roy <roypat@amazon.co.uk>
1 parent 6f3b013 commit 155e29e

File tree

2 files changed

+27
-0
lines changed

2 files changed

+27
-0
lines changed

CONTRIBUTING.md

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,32 @@ cp arm/mod.rs arm64/
6868

6969
Also, you will need to add the new architecture to `kvm-bindings/lib.rs`.
7070

71+
When regenerating bindings, care must be taken to re-add various `zerocopy`
72+
derives under the `serde` feature. All items that require derives are
73+
listed in the `x86_64/serialize.rs` and `arm64/serialize.rs` inside the
74+
`serde_impls!` macro invocation, and missing derives will cause these
75+
modules to fail compilation. For all items listed here, the following
76+
derive should be present:
77+
78+
```rs
79+
#[cfg_attr(
80+
feature = "serde",
81+
derive(zerocopy::AsBytes, zerocopy::FromBytes, zerocopy::FromZeroes)
82+
)]
83+
```
84+
85+
Any types whose name contains a suffix akin to `__bindgen_ty_<number>` and
86+
which is contained in any struct listed in `serialize.rs` will also need
87+
to have this derive added (otherwise compilation will fail). Note that
88+
these types are not explicitly listed in `serialize.rs`, as their names
89+
can change across `bindgen.rs` versions.
90+
91+
Lastly, in `x86_64/bindings.rs`, the derives also need to be added to
92+
`struct __BindgenBitfieldUnit<Storage>` and `struct __IncompleteArrayField<T>`.
93+
Additionally, these structs need to have their layout changed from `#[repr(C)]`
94+
to `#[repr(transparent)]`. This is needed because `zerocopy` traits can only be
95+
derived on generic structures that are `repr(transparent)` or `repr(packed)`.
96+
7197
### Future Improvements
7298
All the above steps are scriptable, so in the next iteration I will add a
7399
script to generate the bindings.

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,3 +45,4 @@ bindings happens as opaque binary blobs via [`zerocopy`](https://google.github.i
4545
Due to the kernel's ABI compatibility, this means that bindings serialized
4646
in version `x` of `kvm-bindings` can be deserialized in version `y` of the
4747
crate, even if the bindings have had been regenerated in the meantime.
48+

0 commit comments

Comments
 (0)