Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
cli: Generate driver structs automatically using bindgen
Added a build script that automatically generates rust bindings for the C structures used by the NE driver. Currently, rust does not allow to implement a destructor and to derive the `Copy` trait for a structure. By default, bindgen derives `Copy` for the generated structures. Although the behavior can be altered by using the Builder's `no_copy()` method, this will also prevent deriving `Clone` (which in turn makes the binding unusable). According to these sources (https://users.rust-lang.org/t/how-to-derive-custom-traits-for-struct-definitions-generated-by-bindgen/39710, rust-lang/rust-bindgen#1089), adding custom derives for the generated bindings is not currently supported. Update: as a workaround (for `ne_user_memory_region`), the bindgen generated struct has been kept and the CLI's MemoryRegion now contains a method for converting between its own format and the driver struct format. This is used for converting to the driver struct representation, when issuing a `NE_SET_USER_MEMORY_REGION` ioctl. The conversion between the two mentioned types is done by implementing the `From` trait for UserMemoryRegion ( which also automatically provides an implementation for `.into()`, for constructing a UserMemoryRegion instance from a MemoryRegion one). Signed-off-by: Gabriel Bercaru <bercarug@amazon.com>
- Loading branch information