Skip to content

backport #513 #520

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 5 commits into from
Nov 30, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ name: Build
on:
push:
branches:
- "master"
- "x86_64-0.14.x"
tags:
- "*"
schedule:
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ name: Release
on:
push:
branches:
- "master"
- "x86_64-0.14.x"

permissions:
contents: read
Expand Down
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ license = "MIT/Apache-2.0"
name = "x86_64"
readme = "README.md"
repository = "https://github.com/rust-osdev/x86_64"
version = "0.14.12"
version = "0.14.13"
edition = "2018"
rust-version = "1.57" # Needed to support panic! in const fns

Expand Down
6 changes: 6 additions & 0 deletions Changelog.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
# Unreleased

# 0.14.13 – 2024-11-30

## Fixes

- [fix signature of Step::steps_between implementations](https://github.com/rust-osdev/x86_64/pull/520)

# 0.14.12 – 2023-02-09

## New Features
Expand Down
35 changes: 23 additions & 12 deletions src/addr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
use crate::structures::paging::{PageOffset, PageTableIndex};
use bit_field::BitField;

const ADDRESS_SPACE_SIZE: u64 = 0x1_0000_0000_0000;

Check warning on line 13 in src/addr.rs

View workflow job for this annotation

GitHub Actions / Test MSRV and Stable Features (nightly)

constant `ADDRESS_SPACE_SIZE` is never used

Check warning on line 13 in src/addr.rs

View workflow job for this annotation

GitHub Actions / Test MSRV and Stable Features (nightly)

constant `ADDRESS_SPACE_SIZE` is never used

Check warning on line 13 in src/addr.rs

View workflow job for this annotation

GitHub Actions / Test MSRV and Stable Features (1.57)

constant is never used: `ADDRESS_SPACE_SIZE`

Check warning on line 13 in src/addr.rs

View workflow job for this annotation

GitHub Actions / Test MSRV and Stable Features (1.57)

constant is never used: `ADDRESS_SPACE_SIZE`

Check warning on line 13 in src/addr.rs

View workflow job for this annotation

GitHub Actions / Test MSRV and Stable Features (1.59)

constant is never used: `ADDRESS_SPACE_SIZE`

Check warning on line 13 in src/addr.rs

View workflow job for this annotation

GitHub Actions / Test MSRV and Stable Features (1.59)

constant is never used: `ADDRESS_SPACE_SIZE`

/// A canonical 64-bit virtual memory address.
///
Expand Down Expand Up @@ -226,19 +226,24 @@
}

// FIXME: Move this into the `Step` impl, once `Step` is stabilized.
pub(crate) fn steps_between_impl(start: &Self, end: &Self) -> Option<usize> {
let mut steps = end.0.checked_sub(start.0)?;
pub(crate) fn steps_between_impl(start: &Self, end: &Self) -> (usize, Option<usize>) {

Check warning on line 229 in src/addr.rs

View workflow job for this annotation

GitHub Actions / Test MSRV and Stable Features (nightly)

associated functions `steps_between_impl` and `forward_checked_impl` are never used

Check warning on line 229 in src/addr.rs

View workflow job for this annotation

GitHub Actions / Test MSRV and Stable Features (nightly)

associated functions `steps_between_impl` and `forward_checked_impl` are never used

Check warning on line 229 in src/addr.rs

View workflow job for this annotation

GitHub Actions / Test MSRV and Stable Features (1.57)

associated function is never used: `steps_between_impl`

Check warning on line 229 in src/addr.rs

View workflow job for this annotation

GitHub Actions / Test MSRV and Stable Features (1.57)

associated function is never used: `steps_between_impl`

Check warning on line 229 in src/addr.rs

View workflow job for this annotation

GitHub Actions / Test MSRV and Stable Features (1.59)

associated function is never used: `steps_between_impl`

Check warning on line 229 in src/addr.rs

View workflow job for this annotation

GitHub Actions / Test MSRV and Stable Features (1.59)

associated function is never used: `steps_between_impl`
let mut steps = if let Some(steps) = end.0.checked_sub(start.0) {
steps
} else {
return (0, None);
};

// Check if we jumped the gap.
if end.0.get_bit(47) && !start.0.get_bit(47) {
steps = steps.checked_sub(0xffff_0000_0000_0000).unwrap();
}

usize::try_from(steps).ok()
let steps = usize::try_from(steps).ok();
(steps.unwrap_or(usize::MAX), steps)
}

// FIXME: Move this into the `Step` impl, once `Step` is stabilized.
pub(crate) fn forward_checked_impl(start: Self, count: usize) -> Option<Self> {

Check warning on line 246 in src/addr.rs

View workflow job for this annotation

GitHub Actions / Test MSRV and Stable Features (1.57)

associated function is never used: `forward_checked_impl`

Check warning on line 246 in src/addr.rs

View workflow job for this annotation

GitHub Actions / Test MSRV and Stable Features (1.57)

associated function is never used: `forward_checked_impl`

Check warning on line 246 in src/addr.rs

View workflow job for this annotation

GitHub Actions / Test MSRV and Stable Features (1.59)

associated function is never used: `forward_checked_impl`

Check warning on line 246 in src/addr.rs

View workflow job for this annotation

GitHub Actions / Test MSRV and Stable Features (1.59)

associated function is never used: `forward_checked_impl`
let offset = u64::try_from(count).ok()?;
if offset > ADDRESS_SPACE_SIZE {
return None;
Expand Down Expand Up @@ -379,7 +384,7 @@

#[cfg(feature = "step_trait")]
impl Step for VirtAddr {
fn steps_between(start: &Self, end: &Self) -> Option<usize> {
fn steps_between(start: &Self, end: &Self) -> (usize, Option<usize>) {
Self::steps_between_impl(start, end)
}

Expand Down Expand Up @@ -758,43 +763,49 @@
#[test]
#[cfg(feature = "step_trait")]
fn virtaddr_steps_between() {
assert_eq!(Step::steps_between(&VirtAddr(0), &VirtAddr(0)), Some(0));
assert_eq!(Step::steps_between(&VirtAddr(0), &VirtAddr(1)), Some(1));
assert_eq!(Step::steps_between(&VirtAddr(1), &VirtAddr(0)), None);
assert_eq!(
Step::steps_between(&VirtAddr(0), &VirtAddr(0)),
(0, Some(0))
);
assert_eq!(
Step::steps_between(&VirtAddr(0), &VirtAddr(1)),
(1, Some(1))
);
assert_eq!(Step::steps_between(&VirtAddr(1), &VirtAddr(0)), (0, None));
assert_eq!(
Step::steps_between(
&VirtAddr(0x7fff_ffff_ffff),
&VirtAddr(0xffff_8000_0000_0000)
),
Some(1)
(1, Some(1))
);
assert_eq!(
Step::steps_between(
&VirtAddr(0xffff_8000_0000_0000),
&VirtAddr(0x7fff_ffff_ffff)
),
None
(0, None)
);
assert_eq!(
Step::steps_between(
&VirtAddr(0xffff_8000_0000_0000),
&VirtAddr(0xffff_8000_0000_0000)
),
Some(0)
(0, Some(0))
);
assert_eq!(
Step::steps_between(
&VirtAddr(0xffff_8000_0000_0000),
&VirtAddr(0xffff_8000_0000_0001)
),
Some(1)
(1, Some(1))
);
assert_eq!(
Step::steps_between(
&VirtAddr(0xffff_8000_0000_0001),
&VirtAddr(0xffff_8000_0000_0000)
),
None
(0, None)
);
}

Expand Down
4 changes: 2 additions & 2 deletions src/instructions/segmentation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -75,10 +75,10 @@ impl Segment for CS {
unsafe {
asm!(
"push {sel}",
"lea {tmp}, [1f + rip]",
"lea {tmp}, [55f + rip]",
"push {tmp}",
"retfq",
"1:",
"55:",
sel = in(reg) u64::from(sel.0),
tmp = lateout(reg) _,
options(preserves_flags),
Expand Down
4 changes: 2 additions & 2 deletions src/instructions/tlb.rs
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@
assert_eq!(cs.rpl(), PrivilegeLevel::Ring0);

// Check if the `INVLPGB` and `TLBSYNC` instruction are supported.
let cpuid = unsafe { core::arch::x86_64::__cpuid(0x8000_0008) };

Check failure on line 146 in src/instructions/tlb.rs

View workflow job for this annotation

GitHub Actions / Test (macos-latest)

failed to resolve: could not find `x86_64` in `arch`
if !cpuid.ebx.get_bit(3) {
return None;
}
Expand All @@ -152,7 +152,7 @@
let invlpgb_count_max = cpuid.edx.get_bits(0..=15) as u16;

// Figure out the number of supported ASIDs.
let cpuid = unsafe { core::arch::x86_64::__cpuid(0x8000_000a) };

Check failure on line 155 in src/instructions/tlb.rs

View workflow job for this annotation

GitHub Actions / Test (macos-latest)

failed to resolve: could not find `x86_64` in `arch`
let nasid = cpuid.ebx;

Some(Self {
Expand Down Expand Up @@ -298,14 +298,14 @@
if let Some(mut pages) = self.page_range {
while !pages.is_empty() {
// Calculate out how many pages we still need to flush.
let count = Page::<S>::steps_between_impl(&pages.start, &pages.end).unwrap();
let count = Page::<S>::steps_between_impl(&pages.start, &pages.end).0;

// Make sure that we never jump the gap in the address space when flushing.
let second_half_start =
Page::<S>::containing_address(VirtAddr::new(0xffff_8000_0000_0000));
let count = if pages.start < second_half_start {
let count_to_second_half =
Page::steps_between_impl(&pages.start, &second_half_start).unwrap();
Page::steps_between_impl(&pages.start, &second_half_start).0;
cmp::min(count, count_to_second_half)
} else {
count
Expand Down
10 changes: 6 additions & 4 deletions src/structures/paging/page.rs
Original file line number Diff line number Diff line change
Expand Up @@ -150,13 +150,15 @@
}

// FIXME: Move this into the `Step` impl, once `Step` is stabilized.
pub(crate) fn steps_between_impl(start: &Self, end: &Self) -> Option<usize> {
VirtAddr::steps_between_impl(&start.start_address, &end.start_address)
.map(|steps| steps / S::SIZE as usize)
pub(crate) fn steps_between_impl(start: &Self, end: &Self) -> (usize, Option<usize>) {

Check warning on line 153 in src/structures/paging/page.rs

View workflow job for this annotation

GitHub Actions / Test MSRV and Stable Features (nightly)

associated functions `steps_between_impl` and `forward_checked_impl` are never used

Check warning on line 153 in src/structures/paging/page.rs

View workflow job for this annotation

GitHub Actions / Test MSRV and Stable Features (nightly)

associated functions `steps_between_impl` and `forward_checked_impl` are never used

Check warning on line 153 in src/structures/paging/page.rs

View workflow job for this annotation

GitHub Actions / Test MSRV and Stable Features (1.57)

associated function is never used: `steps_between_impl`

Check warning on line 153 in src/structures/paging/page.rs

View workflow job for this annotation

GitHub Actions / Test MSRV and Stable Features (1.57)

associated function is never used: `steps_between_impl`

Check warning on line 153 in src/structures/paging/page.rs

View workflow job for this annotation

GitHub Actions / Test MSRV and Stable Features (1.59)

associated function is never used: `steps_between_impl`

Check warning on line 153 in src/structures/paging/page.rs

View workflow job for this annotation

GitHub Actions / Test MSRV and Stable Features (1.59)

associated function is never used: `steps_between_impl`
let (lower, upper) = VirtAddr::steps_between_impl(&start.start_address, &end.start_address);
let lower = lower / S::SIZE as usize;
let upper = upper.map(|steps| steps / S::SIZE as usize);
(lower, upper)
}

// FIXME: Move this into the `Step` impl, once `Step` is stabilized.
pub(crate) fn forward_checked_impl(start: Self, count: usize) -> Option<Self> {

Check warning on line 161 in src/structures/paging/page.rs

View workflow job for this annotation

GitHub Actions / Test MSRV and Stable Features (1.57)

associated function is never used: `forward_checked_impl`

Check warning on line 161 in src/structures/paging/page.rs

View workflow job for this annotation

GitHub Actions / Test MSRV and Stable Features (1.57)

associated function is never used: `forward_checked_impl`

Check warning on line 161 in src/structures/paging/page.rs

View workflow job for this annotation

GitHub Actions / Test MSRV and Stable Features (1.59)

associated function is never used: `forward_checked_impl`

Check warning on line 161 in src/structures/paging/page.rs

View workflow job for this annotation

GitHub Actions / Test MSRV and Stable Features (1.59)

associated function is never used: `forward_checked_impl`
let count = count.checked_mul(S::SIZE as usize)?;
let start_address = VirtAddr::forward_checked_impl(start.start_address, count)?;
Some(Self {
Expand Down Expand Up @@ -279,7 +281,7 @@

#[cfg(feature = "step_trait")]
impl<S: PageSize> Step for Page<S> {
fn steps_between(start: &Self, end: &Self) -> Option<usize> {
fn steps_between(start: &Self, end: &Self) -> (usize, Option<usize>) {
Self::steps_between_impl(start, end)
}

Expand Down
Loading