Skip to content

Commit

Permalink
Rename AddressValue to GuestUsize
Browse files Browse the repository at this point in the history
An unsigned integer type is needed to represent an address in guest's
physical address space, so rename AddressValue to GuestUsize.

Signed-off-by: Liu Jiang <[email protected]>
  • Loading branch information
jiangliu committed Mar 26, 2019
1 parent cb34745 commit 0ae13fa
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 13 deletions.
18 changes: 9 additions & 9 deletions src/address.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,17 +11,17 @@
//! Traits to represent an address within an address space.
//!
//! Two traits are defined to present an address within an address space:
//! - [AddressValue](trait.AddressValue.html): stores the raw value of an address. Typically u32,
//! - [GuestUsize](trait.GuestUsize.html): stores the raw value of an address. Typically u32,
//! u64 or usize is used to store the raw value. But pointers, such as *u8, can't be used because
//! it doesn't implement the Add and Sub traits.
//! - [Address](trait.Address.html): encapsulates an AddressValue object and defines methods to
//! - [Address](trait.Address.html): encapsulates an GuestUsize object and defines methods to
//! access and manipulate it.
use std::cmp::{Eq, Ord, PartialEq, PartialOrd};
use std::ops::{Add, BitAnd, BitOr, Sub};

/// Simple helper trait used to store a raw address value.
pub trait AddressValue {
pub trait GuestUsize {
/// Type of the address raw value.
type V: Copy
+ PartialEq
Expand All @@ -36,26 +36,26 @@ pub trait AddressValue {

/// Trait to represent an address within an address space.
///
/// To simplify the design and implementation, assume the same raw data type (AddressValue::V)
/// To simplify the design and implementation, assume the same raw data type (GuestUsize::V)
/// could be used to store address, size and offset for the address space. Thus the Address trait
/// could be used to manage address, size and offset. On the other hand, type aliases may be
/// defined to improve code readability.
///
/// One design rule is applied to the Address trait that operators (+, -, &, | etc) are not
/// supported and it forces clients to explicitly invoke corresponding methods. But there are
/// always exceptions:
/// Address (BitAnd|BitOr) AddressValue are supported.
/// Address (BitAnd|BitOr) GuestUsize are supported.
pub trait Address:
AddressValue
GuestUsize
+ Sized
+ Default
+ Copy
+ Eq
+ PartialEq
+ Ord
+ PartialOrd
+ BitAnd<<Self as AddressValue>::V, Output = Self>
+ BitOr<<Self as AddressValue>::V, Output = Self>
+ BitAnd<<Self as GuestUsize>::V, Output = Self>
+ BitOr<<Self as GuestUsize>::V, Output = Self>
{
/// Create an address from a raw address value.
fn new(addr: Self::V) -> Self;
Expand Down Expand Up @@ -101,7 +101,7 @@ pub trait Address:

macro_rules! impl_address_ops {
($T:ident, $V:ty) => {
impl AddressValue for $T {
impl GuestUsize for $T {
type V = $V;
}

Expand Down
6 changes: 3 additions & 3 deletions src/guest_memory.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ use std::fmt::{self, Display};
use std::io::{self, Read, Write};
use std::ops::{BitAnd, BitOr};

use address::{Address, AddressValue};
use address::{Address, GuestUsize};
use bytes::Bytes;
use volatile_memory;

Expand Down Expand Up @@ -114,10 +114,10 @@ pub struct MemoryRegionAddress(pub u64);
impl_address_ops!(MemoryRegionAddress, u64);

/// Type of the raw value stored in a GuestAddress object.
pub type GuestAddressValue = <GuestAddress as AddressValue>::V;
pub type GuestAddressValue = <GuestAddress as GuestUsize>::V;

/// Type to encode offset in the guest physical address space.
pub type GuestAddressOffset = <GuestAddress as AddressValue>::V;
pub type GuestAddressOffset = <GuestAddress as GuestUsize>::V;

/// Represents a continuous region of guest physical memory.
#[allow(clippy::len_without_is_empty)]
Expand Down
2 changes: 1 addition & 1 deletion src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ extern crate matches;

#[macro_use]
pub mod address;
pub use address::{Address, AddressValue};
pub use address::{Address, GuestUsize};

pub mod bytes;
pub use bytes::{ByteValued, Bytes};
Expand Down

0 comments on commit 0ae13fa

Please sign in to comment.