From d1245509b2a5f9494fd2dcf62876dc82ec8d00f9 Mon Sep 17 00:00:00 2001 From: Daniel Verkamp Date: Mon, 19 Aug 2019 13:19:38 -0700 Subject: x86_64: replace byteorder with {to,from}_le_bytes() BUG=None TEST=./build_test Change-Id: Ic7873c6b70d9a0e9f34b7a2977845552144934ea Signed-off-by: Daniel Verkamp Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/1761152 Tested-by: kokoro Reviewed-by: Zach Reizner --- Cargo.lock | 1 - x86_64/Cargo.toml | 1 - x86_64/src/interrupts.rs | 21 ++++++++------------- 3 files changed, 8 insertions(+), 15 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 0a4f1aa..6939007 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -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", diff --git a/x86_64/Cargo.toml b/x86_64/Cargo.toml index 58d688b..e5d5e14 100644 --- a/x86_64/Cargo.toml +++ b/x86_64/Cargo.toml @@ -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" } diff --git a/x86_64/src/interrupts.rs b/x86_64/src/interrupts.rs index 6c2ebfd..a2b0f1c 100644 --- a/x86_64/src/interrupts.rs +++ b/x86_64/src/interrupts.rs @@ -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::().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::(value).unwrap() + sliceu8.copy_from_slice(&value.to_le_bytes()); } fn set_apic_delivery_mode(reg: u32, mode: u32) -> u32 { -- cgit 1.4.1