From 36c8661fe043c5a469b54a80fdc456d28566fbe6 Mon Sep 17 00:00:00 2001 From: Gerd Zellweger Date: Fri, 15 Jul 2022 15:53:26 -0700 Subject: Implement Step for address types. --- CHANGELOG.md | 8 +++++++- Cargo.toml | 3 ++- src/bits64/paging.rs | 41 +++++++++++++++++++++++++++++++++++++++++ src/lib.rs | 1 + 4 files changed, 51 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 52cda70..7e5f69f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,7 +7,13 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ## [unreleased] -## [0.50.0] - 2022-07-29 +## [0.51.0] - 2022-07-15 + +- Implement `core::iter::Step` for PAddr, VAddr, IOAddr types. This currently + requires nightly so added a `unstable` Cargo feature to enable it + conditionally. + +## [0.50.0] - 2022-06-29 - `rdtscp` now returns a tuple in the form of `(cycles: u64, aux: u32)`, where `cycles` is the cycle count (as returned by this function in previous diff --git a/Cargo.toml b/Cargo.toml index af2eae8..fa1dcb0 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "x86" -version = "0.50.0" +version = "0.51.0" authors = [ "Gerd Zellweger ", "Eric Kidd ", @@ -43,6 +43,7 @@ performance-counter = ["phf", "phf_codegen", "csv", "serde_json"] utest = [] # Run VM tests, i.e., the #[x86test] ones vmtest = [] +unstable = [] [[test]] name = "kvm" diff --git a/src/bits64/paging.rs b/src/bits64/paging.rs index 799fd43..71e6325 100644 --- a/src/bits64/paging.rs +++ b/src/bits64/paging.rs @@ -5,6 +5,8 @@ use bitflags::*; use core::convert::{From, Into}; use core::fmt; use core::hash::{Hash, Hasher}; +#[cfg(feature = "unstable")] +use core::iter::Step; use core::ops; macro_rules! check_flag { @@ -160,6 +162,19 @@ impl PAddr { } } +#[cfg(feature = "unstable")] +impl Step for PAddr { + fn steps_between(start: &Self, end: &Self) -> Option { + ::steps_between(&start.0, &end.0) + } + fn forward_checked(start: Self, count: usize) -> Option { + ::forward_checked(start.0, count).map(|v| PAddr(v)) + } + fn backward_checked(start: Self, count: usize) -> Option { + ::backward_checked(start.0, count).map(|v| PAddr(v)) + } +} + impl From for PAddr { fn from(num: u64) -> Self { PAddr(num) @@ -487,6 +502,19 @@ impl IOAddr { } } +#[cfg(feature = "unstable")] +impl Step for IOAddr { + fn steps_between(start: &Self, end: &Self) -> Option { + ::steps_between(&start.0, &end.0) + } + fn forward_checked(start: Self, count: usize) -> Option { + ::forward_checked(start.0, count).map(|v| IOAddr(v)) + } + fn backward_checked(start: Self, count: usize) -> Option { + ::backward_checked(start.0, count).map(|v| IOAddr(v)) + } +} + impl From for IOAddr { fn from(num: u64) -> Self { IOAddr(num) @@ -829,6 +857,19 @@ impl VAddr { } } +#[cfg(feature = "unstable")] +impl Step for VAddr { + fn steps_between(start: &Self, end: &Self) -> Option { + ::steps_between(&start.0, &end.0) + } + fn forward_checked(start: Self, count: usize) -> Option { + ::forward_checked(start.0, count).map(|v| VAddr(v)) + } + fn backward_checked(start: Self, count: usize) -> Option { + ::backward_checked(start.0, count).map(|v| VAddr(v)) + } +} + impl From for VAddr { fn from(num: u64) -> Self { VAddr(num) diff --git a/src/lib.rs b/src/lib.rs index 0c35999..42d22bc 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -3,6 +3,7 @@ #![cfg_attr(test, allow(unused_features))] #![cfg_attr(all(test, feature = "vmtest"), feature(custom_test_frameworks))] #![cfg_attr(all(test, feature = "vmtest"), test_runner(x86test::runner::runner))] +#![cfg_attr(feature = "unstable", feature(step_trait))] use core::arch::asm; #[cfg(target_arch = "x86")] -- cgit v1.2.3