aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGravatar Gerd Zellweger <mail@gerdzellweger.com> 2022-07-15 15:53:26 -0700
committerGravatar Gerd Zellweger <mail@gerdzellweger.com> 2022-07-15 15:53:26 -0700
commit36c8661fe043c5a469b54a80fdc456d28566fbe6 (patch)
tree07eb70107756946da827db1b3c7472c6c3348aee
parentf8700919aebf709e18879e1229690be7c5aa64d1 (diff)
downloadrust-x86-36c8661fe043c5a469b54a80fdc456d28566fbe6.tar.gz
rust-x86-36c8661fe043c5a469b54a80fdc456d28566fbe6.tar.zst
rust-x86-36c8661fe043c5a469b54a80fdc456d28566fbe6.zip
Implement Step for address types.
-rw-r--r--CHANGELOG.md8
-rw-r--r--Cargo.toml3
-rw-r--r--src/bits64/paging.rs41
-rw-r--r--src/lib.rs1
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 <mail@gerdzellweger.com>",
"Eric Kidd <git@randomhacks.net>",
@@ -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<usize> {
+ <u64 as Step>::steps_between(&start.0, &end.0)
+ }
+ fn forward_checked(start: Self, count: usize) -> Option<Self> {
+ <u64 as Step>::forward_checked(start.0, count).map(|v| PAddr(v))
+ }
+ fn backward_checked(start: Self, count: usize) -> Option<Self> {
+ <u64 as Step>::backward_checked(start.0, count).map(|v| PAddr(v))
+ }
+}
+
impl From<u64> 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<usize> {
+ <u64 as Step>::steps_between(&start.0, &end.0)
+ }
+ fn forward_checked(start: Self, count: usize) -> Option<Self> {
+ <u64 as Step>::forward_checked(start.0, count).map(|v| IOAddr(v))
+ }
+ fn backward_checked(start: Self, count: usize) -> Option<Self> {
+ <u64 as Step>::backward_checked(start.0, count).map(|v| IOAddr(v))
+ }
+}
+
impl From<u64> 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<usize> {
+ <u64 as Step>::steps_between(&start.0, &end.0)
+ }
+ fn forward_checked(start: Self, count: usize) -> Option<Self> {
+ <u64 as Step>::forward_checked(start.0, count).map(|v| VAddr(v))
+ }
+ fn backward_checked(start: Self, count: usize) -> Option<Self> {
+ <u64 as Step>::backward_checked(start.0, count).map(|v| VAddr(v))
+ }
+}
+
impl From<u64> 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")]