mirror of
https://chromium.googlesource.com/crosvm/crosvm
synced 2024-11-25 05:03:05 +00:00
ca0aed3daa
The conversion code for KVM <-> hypervisor representation of the Local APIC state used the unsafe mem::transmute() function to view an array of i8 as u8 instead for use with the Rust endian conversion functions. Casting between integer types of the same size with `as` is defined in Rust as a "no-op" (the bitwise representation is preserved), just like in C, so transmuting at the slice level is not needed. These can instead be written as simple loops to avoid the unsafe code. To ensure this does not regress code quality, I have compared the code generated for the x86-64 release build. The kvm_lapic_state to LapicState conversion compiles to identical code, and the reverse compiles to slightly different code (the compiler decides to emit a loop instead of unrolling the 64-element copy), but the conversion of each element still compiles down to a pair of MOV instructions. The corresponding unit test has also been updated to avoid transmute, as it was unnecessary there - the individual array element can be cast with the `as` operator rather than transmuting the whole array. BUG=None TEST=cargo test -p hypervisor Change-Id: I7e792b5507235e5234afe114a1ca744931e047d5 Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/2947934 Reviewed-by: Chirantan Ekbote <chirantan@chromium.org> Tested-by: kokoro <noreply+kokoro@google.com> Commit-Queue: Daniel Verkamp <dverkamp@chromium.org> |
||
---|---|---|
.. | ||
clippy | ||
crate_coverage | ||
fmt | ||
preupload-clippy |