diff --git a/rust/Cargo.lock b/rust/Cargo.lock index adab3f4..bbe4311 100644 --- a/rust/Cargo.lock +++ b/rust/Cargo.lock @@ -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" diff --git a/rust/Cargo.toml b/rust/Cargo.toml index b39cd6a..6d2f645 100644 --- a/rust/Cargo.toml +++ b/rust/Cargo.toml @@ -2,6 +2,7 @@ name = "pH" version = "0.1.0" authors = ["Bruce Leidl "] +edition = "2018" [[bin]] name="pH" diff --git a/rust/src/devices/rtc.rs b/rust/src/devices/rtc.rs index 6aa57e0..892128e 100644 --- a/rust/src/devices/rtc.rs +++ b/rust/src/devices/rtc.rs @@ -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; diff --git a/rust/src/devices/serial.rs b/rust/src/devices/serial.rs index 989cc8b..2716bf7 100644 --- a/rust/src/devices/serial.rs +++ b/rust/src/devices/serial.rs @@ -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; diff --git a/rust/src/devices/virtio_9p/commands.rs b/rust/src/devices/virtio_9p/commands.rs index c20c26e..3036fb8 100644 --- a/rust/src/devices/virtio_9p/commands.rs +++ b/rust/src/devices/virtio_9p/commands.rs @@ -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}; diff --git a/rust/src/devices/virtio_9p/mod.rs b/rust/src/devices/virtio_9p/mod.rs index 2c92f0e..f10b135 100644 --- a/rust/src/devices/virtio_9p/mod.rs +++ b/rust/src/devices/virtio_9p/mod.rs @@ -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; diff --git a/rust/src/devices/virtio_9p/pdu.rs b/rust/src/devices/virtio_9p/pdu.rs index 0c59d19..f20db60 100644 --- a/rust/src/devices/virtio_9p/pdu.rs +++ b/rust/src/devices/virtio_9p/pdu.rs @@ -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; diff --git a/rust/src/devices/virtio_rng.rs b/rust/src/devices/virtio_rng.rs index bf4089a..c9776c8 100644 --- a/rust/src/devices/virtio_rng.rs +++ b/rust/src/devices/virtio_rng.rs @@ -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; diff --git a/rust/src/devices/virtio_serial.rs b/rust/src/devices/virtio_serial.rs index 056a0a1..a2eb3c3 100644 --- a/rust/src/devices/virtio_serial.rs +++ b/rust/src/devices/virtio_serial.rs @@ -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)] diff --git a/rust/src/kvm/ioctl.rs b/rust/src/kvm/ioctl.rs index bfd9fd4..9c7ba05 100644 --- a/rust/src/kvm/ioctl.rs +++ b/rust/src/kvm/ioctl.rs @@ -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; diff --git a/rust/src/kvm/mod.rs b/rust/src/kvm/mod.rs index db5a9bd..fa63f10 100644 --- a/rust/src/kvm/mod.rs +++ b/rust/src/kvm/mod.rs @@ -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; diff --git a/rust/src/memory/mmap.rs b/rust/src/memory/mmap.rs index e758a26..6223fc8 100644 --- a/rust/src/memory/mmap.rs +++ b/rust/src/memory/mmap.rs @@ -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, diff --git a/rust/src/memory/ram.rs b/rust/src/memory/ram.rs index 517d99f..752e8b9 100644 --- a/rust/src/memory/ram.rs +++ b/rust/src/memory/ram.rs @@ -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); diff --git a/rust/src/system/ioctl.rs b/rust/src/system/ioctl.rs index eb3624e..a12ca92 100644 --- a/rust/src/system/ioctl.rs +++ b/rust/src/system/ioctl.rs @@ -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; diff --git a/rust/src/virtio/bus.rs b/rust/src/virtio/bus.rs index f664488..aadc62f 100644 --- a/rust/src/virtio/bus.rs +++ b/rust/src/virtio/bus.rs @@ -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>) -> VirtioDeviceConfig { + pub fn new_virtio_device(&mut self, device_type: u16, ops: Arc>) -> VirtioDeviceConfig { VirtioDeviceConfig::new(self, device_type, ops) } @@ -41,7 +41,7 @@ pub struct VirtioDeviceConfig<'a> { device_type: u16, irq: u8, kvm: Kvm, - ops: Arc>, + ops: Arc>, 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>) -> VirtioDeviceConfig { + fn new(virtio_bus: &mut VirtioBus, device_type: u16, ops: Arc>) -> 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> { + pub fn ops(&self) -> Arc> { self.ops.clone() } pub fn irq(&self) -> u8 { self.irq } diff --git a/rust/src/virtio/chain.rs b/rust/src/virtio/chain.rs index 769c5e9..6bb62ad 100644 --- a/rust/src/virtio/chain.rs +++ b/rust/src/virtio/chain.rs @@ -1,7 +1,7 @@ use std::io::{self,Read,Write}; -use memory::GuestRam; +use crate::memory::GuestRam; use super::VirtQueue; use super::vring::Descriptor; diff --git a/rust/src/virtio/config.rs b/rust/src/virtio/config.rs index e789091..ab780f6 100644 --- a/rust/src/virtio/config.rs +++ b/rust/src/virtio/config.rs @@ -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; diff --git a/rust/src/virtio/device.rs b/rust/src/virtio/device.rs index 5bccbbf..0692579 100644 --- a/rust/src/virtio/device.rs +++ b/rust/src/virtio/device.rs @@ -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, - device_ops: Arc>, + device_ops: Arc>, dfselect: u32, gfselect: u32, device_features: u64, @@ -182,7 +182,7 @@ impl VirtioDevice { } fn with_ops(&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()) } diff --git a/rust/src/virtio/eventfd.rs b/rust/src/virtio/eventfd.rs index 6fa3bab..ff32f60 100644 --- a/rust/src/virtio/eventfd.rs +++ b/rust/src/virtio/eventfd.rs @@ -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) } } diff --git a/rust/src/virtio/pci.rs b/rust/src/virtio/pci.rs index 79b4cfb..5156b02 100644 --- a/rust/src/virtio/pci.rs +++ b/rust/src/virtio/pci.rs @@ -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); diff --git a/rust/src/virtio/virtqueue.rs b/rust/src/virtio/virtqueue.rs index eede2af..9544b42 100644 --- a/rust/src/virtio/virtqueue.rs +++ b/rust/src/virtio/virtqueue.rs @@ -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::*; diff --git a/rust/src/virtio/vring.rs b/rust/src/virtio/vring.rs index a55c6eb..428ddf4 100644 --- a/rust/src/virtio/vring.rs +++ b/rust/src/virtio/vring.rs @@ -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` diff --git a/rust/src/vm/error.rs b/rust/src/vm/error.rs index 1c16368..daf61af 100644 --- a/rust/src/vm/error.rs +++ b/rust/src/vm/error.rs @@ -68,7 +68,7 @@ enum Repr { #[derive(Debug)] struct General { kind: ErrorKind, - error: Box, + error: Box, } #[derive(Debug)] @@ -78,11 +78,11 @@ pub struct Error { impl Error { pub fn new(kind: ErrorKind, error: E) -> Error - where E: Into> { + where E: Into> { Self::_new(kind, error.into()) } - fn _new(kind: ErrorKind, error: Box) -> Error { + fn _new(kind: ErrorKind, error: Box) -> 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, diff --git a/rust/src/vm/io.rs b/rust/src/vm/io.rs index 7b3c90b..bb1398d 100644 --- a/rust/src/vm/io.rs +++ b/rust/src/vm/io.rs @@ -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>, + device: Arc>, } impl IoPortEntry { - fn new(port: u16, count: usize, device: Arc>) -> IoPortEntry { + fn new(port: u16, count: usize, device: Arc>) -> IoPortEntry { IoPortEntry{ port: port, count: count, device: device } } @@ -80,11 +80,11 @@ impl IoPortEntry { struct MmioEntry { range: AddressRange, - device: Arc>, + device: Arc>, } impl MmioEntry { - fn new(range: AddressRange, device: Arc>) -> MmioEntry { + fn new(range: AddressRange, device: Arc>) -> 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>) { + pub fn register_ioports(&self, port: u16, count: usize, dev: Arc>) { self.state_mut().register_ioports(port, count, dev) } - pub fn register_mmio(&self, range: AddressRange, device: Arc>) { + pub fn register_mmio(&self, range: AddressRange, device: Arc>) { 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>) { + fn register_ioports(&mut self, port: u16, count: usize, dev: Arc>) { self.ioport_entries.push(IoPortEntry::new(port, count, dev)); } - fn register_mmio(&mut self, range: AddressRange, device: Arc>) { + fn register_mmio(&mut self, range: AddressRange, device: Arc>) { self.mmio_entries.push(MmioEntry::new(range, device)); } diff --git a/rust/src/vm/kernel_cmdline.rs b/rust/src/vm/kernel_cmdline.rs index 828c076..4286718 100644 --- a/rust/src/vm/kernel_cmdline.rs +++ b/rust/src/vm/kernel_cmdline.rs @@ -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; diff --git a/rust/src/vm/mod.rs b/rust/src/vm/mod.rs index 3ae8991..f1d68f3 100644 --- a/rust/src/vm/mod.rs +++ b/rust/src/vm/mod.rs @@ -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; diff --git a/rust/src/vm/run.rs b/rust/src/vm/run.rs index 240e12f..765afef 100644 --- a/rust/src/vm/run.rs +++ b/rust/src/vm/run.rs @@ -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; diff --git a/rust/src/vm/setup/cpu.rs b/rust/src/vm/setup/cpu.rs index 1d75ac3..ff7bba7 100644 --- a/rust/src/vm/setup/cpu.rs +++ b/rust/src/vm/setup/cpu.rs @@ -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; diff --git a/rust/src/vm/setup/kernel.rs b/rust/src/vm/setup/kernel.rs index d4e79ce..d5b66c5 100644 --- a/rust/src/vm/setup/kernel.rs +++ b/rust/src/vm/setup/kernel.rs @@ -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 diff --git a/rust/src/vm/setup/mptable.rs b/rust/src/vm/setup/mptable.rs index 7a81c24..d2c6e78 100644 --- a/rust/src/vm/setup/mptable.rs +++ b/rust/src/vm/setup/mptable.rs @@ -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;