x86_64: replace byteorder with {to,from}_le_bytes()

BUG=None
TEST=./build_test

Change-Id: Ic7873c6b70d9a0e9f34b7a2977845552144934ea
Signed-off-by: Daniel Verkamp <dverkamp@chromium.org>
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/1761152
Tested-by: kokoro <noreply+kokoro@google.com>
Reviewed-by: Zach Reizner <zachr@chromium.org>
This commit is contained in:
Daniel Verkamp 2019-08-19 13:19:38 -07:00 committed by Commit Bot
parent f8fc71a760
commit d1245509b2
3 changed files with 8 additions and 15 deletions

1
Cargo.lock generated
View file

@ -567,7 +567,6 @@ version = "0.1.0"
dependencies = [
"arch 0.1.0",
"assertions 0.1.0",
"byteorder 1.1.0 (registry+https://github.com/rust-lang/crates.io-index)",
"cc 1.0.25 (registry+https://github.com/rust-lang/crates.io-index)",
"data_model 0.1.0",
"devices 0.1.0",

View file

@ -8,7 +8,6 @@ build = "build.rs"
[dependencies]
arch = { path = "../arch" }
assertions = { path = "../assertions" }
byteorder = "*"
data_model = { path = "../data_model" }
devices = { path = "../devices" }
io_jail = { path = "../io_jail" }

View file

@ -2,13 +2,11 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
use std::convert::TryInto;
use std::fmt::{self, Display};
use std::io::Cursor;
use std::mem;
use std::result;
use byteorder::{LittleEndian, ReadBytesExt, WriteBytesExt};
use kvm;
use kvm_sys::kvm_lapic_state;
use sys_util;
@ -42,23 +40,20 @@ const APIC_MODE_EXTINT: u32 = 0x7;
fn get_klapic_reg(klapic: &kvm_lapic_state, reg_offset: usize) -> u32 {
let sliceu8 = unsafe {
// This array is only accessed as parts of a u32 word, so interpret it as a u8 array.
// Cursors are only readable on arrays of u8, not i8(c_char).
mem::transmute::<&[i8], &[u8]>(&klapic.regs[reg_offset..])
// from_le_bytes() only works on arrays of u8, not i8(c_char).
mem::transmute::<&[i8], &[u8]>(&klapic.regs[reg_offset..reg_offset + 4])
};
let mut reader = Cursor::new(sliceu8);
// read_u32 can't fail if the offsets defined above are correct.
reader.read_u32::<LittleEndian>().unwrap()
// Slice conversion to array can't fail if the offsets defined above are correct.
u32::from_le_bytes(sliceu8.try_into().unwrap())
}
fn set_klapic_reg(klapic: &mut kvm_lapic_state, reg_offset: usize, value: u32) {
let sliceu8 = unsafe {
// This array is only accessed as parts of a u32 word, so interpret it as a u8 array.
// Cursors are only readable on arrays of u8, not i8(c_char).
mem::transmute::<&mut [i8], &mut [u8]>(&mut klapic.regs[reg_offset..])
// to_le_bytes() produces an array of u8, not i8(c_char).
mem::transmute::<&mut [i8], &mut [u8]>(&mut klapic.regs[reg_offset..reg_offset + 4])
};
let mut writer = Cursor::new(sliceu8);
// read_u32 can't fail if the offsets defined above are correct.
writer.write_u32::<LittleEndian>(value).unwrap()
sliceu8.copy_from_slice(&value.to_le_bytes());
}
fn set_apic_delivery_mode(reg: u32, mode: u32) -> u32 {