Skip to content

Commit 1eb275b

Browse files
authored
Merge pull request #520 from rust-osdev/backport/pr-513
backport #513
2 parents af70710 + 7e4534b commit 1eb275b

File tree

8 files changed

+42
-23
lines changed

8 files changed

+42
-23
lines changed

.github/workflows/build.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ name: Build
33
on:
44
push:
55
branches:
6-
- "master"
6+
- "x86_64-0.14.x"
77
tags:
88
- "*"
99
schedule:

.github/workflows/release.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ name: Release
33
on:
44
push:
55
branches:
6-
- "master"
6+
- "x86_64-0.14.x"
77

88
permissions:
99
contents: read

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ license = "MIT/Apache-2.0"
1515
name = "x86_64"
1616
readme = "README.md"
1717
repository = "https://github.com/rust-osdev/x86_64"
18-
version = "0.14.12"
18+
version = "0.14.13"
1919
edition = "2018"
2020
rust-version = "1.57" # Needed to support panic! in const fns
2121

Changelog.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,11 @@
11
# Unreleased
22

3+
# 0.14.13 – 2024-11-30
4+
5+
## Fixes
6+
7+
- [fix signature of Step::steps_between implementations](https://github.com/rust-osdev/x86_64/pull/520)
8+
39
# 0.14.12 – 2023-02-09
410

511
## New Features

src/addr.rs

Lines changed: 23 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -226,15 +226,20 @@ impl VirtAddr {
226226
}
227227

228228
// FIXME: Move this into the `Step` impl, once `Step` is stabilized.
229-
pub(crate) fn steps_between_impl(start: &Self, end: &Self) -> Option<usize> {
230-
let mut steps = end.0.checked_sub(start.0)?;
229+
pub(crate) fn steps_between_impl(start: &Self, end: &Self) -> (usize, Option<usize>) {
230+
let mut steps = if let Some(steps) = end.0.checked_sub(start.0) {
231+
steps
232+
} else {
233+
return (0, None);
234+
};
231235

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

237-
usize::try_from(steps).ok()
241+
let steps = usize::try_from(steps).ok();
242+
(steps.unwrap_or(usize::MAX), steps)
238243
}
239244

240245
// FIXME: Move this into the `Step` impl, once `Step` is stabilized.
@@ -379,7 +384,7 @@ impl Sub<VirtAddr> for VirtAddr {
379384

380385
#[cfg(feature = "step_trait")]
381386
impl Step for VirtAddr {
382-
fn steps_between(start: &Self, end: &Self) -> Option<usize> {
387+
fn steps_between(start: &Self, end: &Self) -> (usize, Option<usize>) {
383388
Self::steps_between_impl(start, end)
384389
}
385390

@@ -758,43 +763,49 @@ mod tests {
758763
#[test]
759764
#[cfg(feature = "step_trait")]
760765
fn virtaddr_steps_between() {
761-
assert_eq!(Step::steps_between(&VirtAddr(0), &VirtAddr(0)), Some(0));
762-
assert_eq!(Step::steps_between(&VirtAddr(0), &VirtAddr(1)), Some(1));
763-
assert_eq!(Step::steps_between(&VirtAddr(1), &VirtAddr(0)), None);
766+
assert_eq!(
767+
Step::steps_between(&VirtAddr(0), &VirtAddr(0)),
768+
(0, Some(0))
769+
);
770+
assert_eq!(
771+
Step::steps_between(&VirtAddr(0), &VirtAddr(1)),
772+
(1, Some(1))
773+
);
774+
assert_eq!(Step::steps_between(&VirtAddr(1), &VirtAddr(0)), (0, None));
764775
assert_eq!(
765776
Step::steps_between(
766777
&VirtAddr(0x7fff_ffff_ffff),
767778
&VirtAddr(0xffff_8000_0000_0000)
768779
),
769-
Some(1)
780+
(1, Some(1))
770781
);
771782
assert_eq!(
772783
Step::steps_between(
773784
&VirtAddr(0xffff_8000_0000_0000),
774785
&VirtAddr(0x7fff_ffff_ffff)
775786
),
776-
None
787+
(0, None)
777788
);
778789
assert_eq!(
779790
Step::steps_between(
780791
&VirtAddr(0xffff_8000_0000_0000),
781792
&VirtAddr(0xffff_8000_0000_0000)
782793
),
783-
Some(0)
794+
(0, Some(0))
784795
);
785796
assert_eq!(
786797
Step::steps_between(
787798
&VirtAddr(0xffff_8000_0000_0000),
788799
&VirtAddr(0xffff_8000_0000_0001)
789800
),
790-
Some(1)
801+
(1, Some(1))
791802
);
792803
assert_eq!(
793804
Step::steps_between(
794805
&VirtAddr(0xffff_8000_0000_0001),
795806
&VirtAddr(0xffff_8000_0000_0000)
796807
),
797-
None
808+
(0, None)
798809
);
799810
}
800811

src/instructions/segmentation.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -75,10 +75,10 @@ impl Segment for CS {
7575
unsafe {
7676
asm!(
7777
"push {sel}",
78-
"lea {tmp}, [1f + rip]",
78+
"lea {tmp}, [55f + rip]",
7979
"push {tmp}",
8080
"retfq",
81-
"1:",
81+
"55:",
8282
sel = in(reg) u64::from(sel.0),
8383
tmp = lateout(reg) _,
8484
options(preserves_flags),

src/instructions/tlb.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -298,14 +298,14 @@ where
298298
if let Some(mut pages) = self.page_range {
299299
while !pages.is_empty() {
300300
// Calculate out how many pages we still need to flush.
301-
let count = Page::<S>::steps_between_impl(&pages.start, &pages.end).unwrap();
301+
let count = Page::<S>::steps_between_impl(&pages.start, &pages.end).0;
302302

303303
// Make sure that we never jump the gap in the address space when flushing.
304304
let second_half_start =
305305
Page::<S>::containing_address(VirtAddr::new(0xffff_8000_0000_0000));
306306
let count = if pages.start < second_half_start {
307307
let count_to_second_half =
308-
Page::steps_between_impl(&pages.start, &second_half_start).unwrap();
308+
Page::steps_between_impl(&pages.start, &second_half_start).0;
309309
cmp::min(count, count_to_second_half)
310310
} else {
311311
count

src/structures/paging/page.rs

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -150,9 +150,11 @@ impl<S: PageSize> Page<S> {
150150
}
151151

152152
// FIXME: Move this into the `Step` impl, once `Step` is stabilized.
153-
pub(crate) fn steps_between_impl(start: &Self, end: &Self) -> Option<usize> {
154-
VirtAddr::steps_between_impl(&start.start_address, &end.start_address)
155-
.map(|steps| steps / S::SIZE as usize)
153+
pub(crate) fn steps_between_impl(start: &Self, end: &Self) -> (usize, Option<usize>) {
154+
let (lower, upper) = VirtAddr::steps_between_impl(&start.start_address, &end.start_address);
155+
let lower = lower / S::SIZE as usize;
156+
let upper = upper.map(|steps| steps / S::SIZE as usize);
157+
(lower, upper)
156158
}
157159

158160
// FIXME: Move this into the `Step` impl, once `Step` is stabilized.
@@ -279,7 +281,7 @@ impl<S: PageSize> Sub<Self> for Page<S> {
279281

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

0 commit comments

Comments
 (0)