summary refs log tree commit diff
diff options
context:
space:
mode:
authorDaniel Verkamp <dverkamp@chromium.org>2019-08-19 13:19:38 -0700
committerCommit Bot <commit-bot@chromium.org>2019-08-26 23:41:51 +0000
commitd1245509b2a5f9494fd2dcf62876dc82ec8d00f9 (patch)
tree7716a1456ed855bbd92559d53fab6addea8556d0
parentf8fc71a760be8a15e06de1cf71ee558c948b599d (diff)
downloadcrosvm-d1245509b2a5f9494fd2dcf62876dc82ec8d00f9.tar
crosvm-d1245509b2a5f9494fd2dcf62876dc82ec8d00f9.tar.gz
crosvm-d1245509b2a5f9494fd2dcf62876dc82ec8d00f9.tar.bz2
crosvm-d1245509b2a5f9494fd2dcf62876dc82ec8d00f9.tar.lz
crosvm-d1245509b2a5f9494fd2dcf62876dc82ec8d00f9.tar.xz
crosvm-d1245509b2a5f9494fd2dcf62876dc82ec8d00f9.tar.zst
crosvm-d1245509b2a5f9494fd2dcf62876dc82ec8d00f9.zip
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>
-rw-r--r--Cargo.lock1
-rw-r--r--x86_64/Cargo.toml1
-rw-r--r--x86_64/src/interrupts.rs21
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::<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 {