Update to modern Rust syntax

This commit is contained in:
Bruce Leidl 2019-08-29 19:43:26 -04:00
parent 7fa1bdadb9
commit 74317be64b
30 changed files with 93 additions and 90 deletions

20
rust/Cargo.lock generated
View File

@ -1,12 +1,5 @@
[root]
name = "pH"
version = "0.1.0"
dependencies = [
"byteorder 1.1.0 (registry+https://github.com/rust-lang/crates.io-index)",
"libc 0.2.32 (registry+https://github.com/rust-lang/crates.io-index)",
"termios 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)",
]
# This file is automatically @generated by Cargo.
# It is not intended for manual editing.
[[package]]
name = "byteorder"
version = "1.1.0"
@ -17,6 +10,15 @@ name = "libc"
version = "0.2.32"
source = "registry+https://github.com/rust-lang/crates.io-index"
[[package]]
name = "pH"
version = "0.1.0"
dependencies = [
"byteorder 1.1.0 (registry+https://github.com/rust-lang/crates.io-index)",
"libc 0.2.32 (registry+https://github.com/rust-lang/crates.io-index)",
"termios 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
name = "termios"
version = "0.2.2"

View File

@ -2,6 +2,7 @@
name = "pH"
version = "0.1.0"
authors = ["Bruce Leidl <bruce@subgraph.com>"]
edition = "2018"
[[bin]]
name="pH"

View File

@ -2,7 +2,7 @@ use std::sync::{Arc,RwLock};
use std::mem;
use libc;
use vm::io::{IoDispatcher,IoPortOps};
use crate::vm::io::{IoDispatcher,IoPortOps};
const RTC_SECONDS: u8 = 0x00;
const RTC_MINUTES: u8 = 0x02;

View File

@ -1,8 +1,8 @@
use std::sync::{Arc, RwLock};
use std::io::{self, Write};
use vm::io::{IoPortOps,IoDispatcher};
use kvm::Kvm;
use crate::vm::io::{IoPortOps,IoDispatcher};
use crate::kvm::Kvm;
const UART_TX: u16 = 0;
const UART_RX: u16 = 0;

View File

@ -6,7 +6,7 @@ use std::fs;
use libc;
use memory::GuestRam;
use crate::memory::GuestRam;
use super::pdu::{PduParser,P9Attr};
use super::fid::FidCache;
use super::filesystem::{FileSystem,FsTouch,FileSystemOps};

View File

@ -3,9 +3,9 @@ use std::thread;
use std::path::{Path,PathBuf};
use memory::GuestRam;
use virtio::{self,VirtioBus,VirtioDeviceOps, VirtQueue};
use vm::Result;
use crate::memory::GuestRam;
use crate::virtio::{self,VirtioBus,VirtioDeviceOps, VirtQueue};
use crate::vm::Result;
mod fid;
mod pdu;

View File

@ -5,8 +5,8 @@ use std::io::{self,Read,Write};
use std::os::linux::fs::MetadataExt;
use std::os::unix::ffi::OsStrExt;
use std::ffi::OsStr;
use memory::GuestRam;
use virtio::Chain;
use crate::memory::GuestRam;
use crate::virtio::Chain;
use super::filesystem::StatFs;

View File

@ -3,9 +3,9 @@ use std::sync::{Arc,RwLock};
use std::thread;
use std::fs::File;
use virtio::{VirtioDeviceOps,VirtioBus,VirtQueue};
use memory::GuestRam;
use vm::Result;
use crate::virtio::{VirtioDeviceOps,VirtioBus,VirtQueue};
use crate::memory::GuestRam;
use crate::vm::Result;
const VIRTIO_ID_RANDOM: u16 = 4;

View File

@ -3,9 +3,9 @@ use std::io::{self,Write,Read};
use std::thread::spawn;
use termios::*;
use virtio::{VirtioDeviceOps,VirtioBus, VirtQueue};
use memory::GuestRam;
use vm::Result;
use crate::virtio::{VirtioDeviceOps,VirtioBus, VirtQueue};
use crate::memory::GuestRam;
use crate::vm::Result;
const VIRTIO_ID_CONSOLE: u16 = 3;
@ -57,7 +57,7 @@ impl VirtioSerial {
}
}
use system::ioctl;
use crate::system::ioctl;
#[repr(C)]
#[derive(Default)]

View File

@ -3,9 +3,9 @@ use std::os::unix::io::RawFd;
use std::ffi::CString;
use std::fmt;
use system::ioctl::{ioctl_with_val,ioctl_with_ref,ioctl_with_mut_ref};
use crate::system::ioctl::{ioctl_with_val,ioctl_with_ref,ioctl_with_mut_ref};
use vm::{Result,Error,ErrorKind};
use crate::vm::{Result,Error,ErrorKind};
const KVMIO: u64 = 0xAE;

View File

@ -3,7 +3,7 @@ use std::sync::Arc;
mod ioctl;
use vm::{Result,Error,ErrorKind};
use crate::vm::{Result,Error,ErrorKind};
pub use self::ioctl::{KvmCpuIdEntry,KvmLapicState, KvmSRegs, KvmRegs, KvmFpu, KvmMsrs, KvmSegment};
pub const KVM_CAP_IRQCHIP: u32 = 0;

View File

@ -5,7 +5,7 @@ use std::mem;
use std::io::Write;
use std::os::unix::io::RawFd;
use vm::{Result,Error,ErrorKind};
use crate::vm::{Result,Error,ErrorKind};
pub struct Mapping {
ptr: *mut u8,

View File

@ -2,12 +2,12 @@ use std::sync::Arc;
use std::cmp;
use std::mem;
use memory::Mapping;
use memory::mmap::Serializable;
use memory::AddressRange;
use crate::memory::Mapping;
use crate::memory::mmap::Serializable;
use crate::memory::AddressRange;
use kvm::Kvm;
use vm::{Result,Error,ErrorKind};
use crate::kvm::Kvm;
use crate::vm::{Result,Error,ErrorKind};
pub const HIMEM_BASE: u64 = (1 << 32);
pub const PCI_MMIO_RESERVED_SIZE: usize = (512 << 20);

View File

@ -1,6 +1,6 @@
use libc::{self, c_ulong, c_void};
use std::os::unix::io::RawFd;
use vm::{Error,Result};
use crate::vm::{Error,Result};
pub const IOC_SIZEBITS: u64 = 14;
pub const IOC_DIRBITS: u64 = 2;

View File

@ -1,11 +1,11 @@
use std::sync::{Arc,RwLock};
use vm::io::IoDispatcher;
use kvm::Kvm;
use memory::{GuestRam,AddressRange};
use crate::vm::io::IoDispatcher;
use crate::kvm::Kvm;
use crate::memory::{GuestRam,AddressRange};
use super::{VirtioDevice,VirtioDeviceOps,PciIrq};
use super::consts::*;
use super::pci::PciBus;
use vm::Result;
use crate::vm::Result;
pub struct VirtioBus {
@ -27,7 +27,7 @@ impl VirtioBus {
}
}
pub fn new_virtio_device(&mut self, device_type: u16, ops: Arc<RwLock<VirtioDeviceOps>>) -> VirtioDeviceConfig {
pub fn new_virtio_device(&mut self, device_type: u16, ops: Arc<RwLock<dyn VirtioDeviceOps>>) -> VirtioDeviceConfig {
VirtioDeviceConfig::new(self, device_type, ops)
}
@ -41,7 +41,7 @@ pub struct VirtioDeviceConfig<'a> {
device_type: u16,
irq: u8,
kvm: Kvm,
ops: Arc<RwLock<VirtioDeviceOps>>,
ops: Arc<RwLock<dyn VirtioDeviceOps>>,
mmio: AddressRange,
num_queues: usize,
config_size: usize,
@ -51,7 +51,7 @@ pub struct VirtioDeviceConfig<'a> {
}
impl <'a> VirtioDeviceConfig<'a> {
fn new(virtio_bus: &mut VirtioBus, device_type: u16, ops: Arc<RwLock<VirtioDeviceOps>>) -> VirtioDeviceConfig {
fn new(virtio_bus: &mut VirtioBus, device_type: u16, ops: Arc<RwLock<dyn VirtioDeviceOps>>) -> VirtioDeviceConfig {
let kvm = virtio_bus.kvm.clone();
let mmio = virtio_bus.pci_bus.write().unwrap().allocate_mmio_space(VIRTIO_MMIO_AREA_SIZE);
VirtioDeviceConfig {
@ -70,7 +70,7 @@ impl <'a> VirtioDeviceConfig<'a> {
pub fn kvm(&self) -> &Kvm { &self.kvm }
pub fn ops(&self) -> Arc<RwLock<VirtioDeviceOps>> {
pub fn ops(&self) -> Arc<RwLock<dyn VirtioDeviceOps>> {
self.ops.clone()
}
pub fn irq(&self) -> u8 { self.irq }

View File

@ -1,7 +1,7 @@
use std::io::{self,Read,Write};
use memory::GuestRam;
use crate::memory::GuestRam;
use super::VirtQueue;
use super::vring::Descriptor;

View File

@ -1,7 +1,7 @@
use memory::GuestRam;
use crate::memory::GuestRam;
use std::sync::Arc;
use vm::Result;
use crate::vm::Result;
use super::VirtQueue;
use super::eventfd::IoEventFd;

View File

@ -1,13 +1,13 @@
use std::sync::{Arc,RwLock};
use std::ops::DerefMut;
use memory::{GuestRam,AddressRange};
use crate::memory::{GuestRam,AddressRange};
use super::bus::VirtioDeviceConfig;
use super::VirtQueue;
use super::config::VirtQueueConfig;
use super::consts::*;
use vm::io::MmioOps;
use vm::Result;
use crate::vm::io::MmioOps;
use crate::vm::Result;
pub trait VirtioDeviceOps: Send+Sync {
fn reset(&mut self) {}
@ -24,7 +24,7 @@ pub struct VirtioDevice {
isr_mmio: AddressRange,
notify_mmio: AddressRange,
device_cfg_mmio: Option<AddressRange>,
device_ops: Arc<RwLock<VirtioDeviceOps>>,
device_ops: Arc<RwLock<dyn VirtioDeviceOps>>,
dfselect: u32,
gfselect: u32,
device_features: u64,
@ -182,7 +182,7 @@ impl VirtioDevice {
}
fn with_ops<U,F>(&self, f: F) -> U
where F: FnOnce(&mut VirtioDeviceOps) -> U {
where F: FnOnce(&mut dyn VirtioDeviceOps) -> U {
let mut ops = self.device_ops.write().unwrap();
f(ops.deref_mut())
}

View File

@ -3,8 +3,8 @@ use std::os::unix::io::RawFd;
use libc;
use vm::{Result,Error,ErrorKind};
use kvm::Kvm;
use crate::vm::{Result,Error,ErrorKind};
use crate::kvm::Kvm;
pub struct EventFd(RawFd);
@ -43,7 +43,7 @@ impl EventFd {
}
return Err(Error::new(ErrorKind::EventFdError, "read failed"));
}
Ok((v))
Ok(v)
}
}

View File

@ -1,9 +1,9 @@
use std::sync::{Arc,RwLock};
use byteorder::{ByteOrder,LittleEndian};
use vm::io::{IoDispatcher,IoPortOps};
use memory::PCI_MMIO_RESERVED_BASE;
use memory::AddressRange;
use crate::vm::io::{IoDispatcher,IoPortOps};
use crate::memory::PCI_MMIO_RESERVED_BASE;
use crate::memory::AddressRange;
use super::consts::*;
struct PciConfigAddress(u32);

View File

@ -1,9 +1,9 @@
use std::sync::atomic::{Ordering, AtomicUsize, AtomicBool};
use std::sync::Arc;
use memory::GuestRam;
use kvm::Kvm;
use vm::Result;
use crate::memory::GuestRam;
use crate::kvm::Kvm;
use crate::vm::Result;
use super::eventfd::{EventFd,IoEventFd};
use super::consts::*;

View File

@ -4,10 +4,10 @@ use std::fmt;
use std::cmp;
use std::io::{self, Read};
use memory::GuestRam;
use crate::memory::GuestRam;
use super::consts::*;
use vm::{Result,Error,ErrorKind};
use crate::vm::{Result,Error,ErrorKind};
///
/// A convenience wrapper around `AtomicUsize`

View File

@ -68,7 +68,7 @@ enum Repr {
#[derive(Debug)]
struct General {
kind: ErrorKind,
error: Box<error::Error+Send+Sync>,
error: Box<dyn error::Error+Send+Sync>,
}
#[derive(Debug)]
@ -78,11 +78,11 @@ pub struct Error {
impl Error {
pub fn new<E>(kind: ErrorKind, error: E) -> Error
where E: Into<Box<error::Error+Send+Sync>> {
where E: Into<Box<dyn error::Error+Send+Sync>> {
Self::_new(kind, error.into())
}
fn _new(kind: ErrorKind, error: Box<error::Error+Send+Sync>) -> Error {
fn _new(kind: ErrorKind, error: Box<dyn error::Error+Send+Sync>) -> Error {
Error {
repr: Repr::General(Box::new(General{
kind, error
@ -159,7 +159,7 @@ impl error::Error for Error {
}
}
fn cause(&self) -> Option<&error::Error> {
fn cause(&self) -> Option<&dyn error::Error> {
match self.repr {
Repr::Errno(..) => None,
Repr::Simple(..) => None,

View File

@ -1,5 +1,5 @@
use std::sync::{Arc,RwLock,RwLockWriteGuard};
use memory::AddressRange;
use crate::memory::AddressRange;
pub trait IoPortOps: Send+Sync {
fn io_in(&mut self, port: u16, size: usize) -> u32 {
@ -55,11 +55,11 @@ impl IoPortOps for IoPortFakeI8042 {
struct IoPortEntry {
port: u16,
count: usize,
device: Arc<RwLock<IoPortOps>>,
device: Arc<RwLock<dyn IoPortOps>>,
}
impl IoPortEntry {
fn new(port: u16, count: usize, device: Arc<RwLock<IoPortOps>>) -> IoPortEntry {
fn new(port: u16, count: usize, device: Arc<RwLock<dyn IoPortOps>>) -> IoPortEntry {
IoPortEntry{ port: port, count: count, device: device }
}
@ -80,11 +80,11 @@ impl IoPortEntry {
struct MmioEntry {
range: AddressRange,
device: Arc<RwLock<MmioOps>>,
device: Arc<RwLock<dyn MmioOps>>,
}
impl MmioEntry {
fn new(range: AddressRange, device: Arc<RwLock<MmioOps>>) -> MmioEntry {
fn new(range: AddressRange, device: Arc<RwLock<dyn MmioOps>>) -> MmioEntry {
MmioEntry{ range, device }
}
@ -117,11 +117,11 @@ impl IoDispatcher {
self.state.write().unwrap()
}
pub fn register_ioports(&self, port: u16, count: usize, dev: Arc<RwLock<IoPortOps>>) {
pub fn register_ioports(&self, port: u16, count: usize, dev: Arc<RwLock<dyn IoPortOps>>) {
self.state_mut().register_ioports(port, count, dev)
}
pub fn register_mmio(&self, range: AddressRange, device: Arc<RwLock<MmioOps>>) {
pub fn register_mmio(&self, range: AddressRange, device: Arc<RwLock<dyn MmioOps>>) {
self.state_mut().register_mmio(range, device);
}
@ -159,11 +159,11 @@ impl IoDispatcherState {
st
}
fn register_ioports(&mut self, port: u16, count: usize, dev: Arc<RwLock<IoPortOps>>) {
fn register_ioports(&mut self, port: u16, count: usize, dev: Arc<RwLock<dyn IoPortOps>>) {
self.ioport_entries.push(IoPortEntry::new(port, count, dev));
}
fn register_mmio(&mut self, range: AddressRange, device: Arc<RwLock<MmioOps>>) {
fn register_mmio(&mut self, range: AddressRange, device: Arc<RwLock<dyn MmioOps>>) {
self.mmio_entries.push(MmioEntry::new(range, device));
}

View File

@ -1,7 +1,7 @@
use std::ffi::OsString;
use std::os::unix::ffi::OsStrExt;
use memory::{GuestRam,KERNEL_CMDLINE_ADDRESS};
use crate::memory::{GuestRam,KERNEL_CMDLINE_ADDRESS};
use super::Result;

View File

@ -5,11 +5,11 @@ use std::env;
use self::io::IoDispatcher;
use virtio::VirtioBus;
use devices;
use crate::virtio::VirtioBus;
use crate::devices;
use memory::{GuestRam,KVM_KERNEL_LOAD_ADDRESS};
use kvm::*;
use crate::memory::{GuestRam,KVM_KERNEL_LOAD_ADDRESS};
use crate::kvm::*;
mod run;

View File

@ -1,7 +1,7 @@
use std::sync::Arc;
use kvm::KvmVcpu;
use memory::Mapping;
use crate::kvm::KvmVcpu;
use crate::memory::Mapping;
use super::Result;
use super::io::IoDispatcher;

View File

@ -1,7 +1,7 @@
use vm::Result;
use crate::vm::Result;
use kvm::{KvmVcpu,KvmRegs,KvmFpu, KvmMsrs, KvmSegment};
use memory::{GuestRam,KERNEL_ZERO_PAGE};
use crate::kvm::{KvmVcpu,KvmRegs,KvmFpu, KvmMsrs, KvmSegment};
use crate::memory::{GuestRam,KERNEL_ZERO_PAGE};
const MSR_IA32_SYSENTER_CS: u32 = 0x00000174;

View File

@ -4,8 +4,8 @@ use std::fs::{File};
use std::io::{self, Read,SeekFrom,Seek};
use byteorder::{LittleEndian,ReadBytesExt};
use memory::{self,GuestRam,KERNEL_ZERO_PAGE};
use vm::{Result,Error,ErrorKind};
use crate::memory::{self,GuestRam,KERNEL_ZERO_PAGE};
use crate::vm::{Result,Error,ErrorKind};
// Documentation/x86/boot.txt

View File

@ -2,9 +2,9 @@ use byteorder::{LittleEndian, WriteBytesExt};
use std::io::Write;
use std::iter;
use memory::GuestRam;
use virtio::PciIrq;
use vm::Result;
use crate::memory::GuestRam;
use crate::virtio::PciIrq;
use crate::vm::Result;
const APIC_DEFAULT_PHYS_BASE: u32 = 0xfee00000;
const IO_APIC_DEFAULT_PHYS_BASE: u32 = 0xfec00000;