Skip to content

merge master into next #546

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 37 commits into from
Apr 29, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
37 commits
Select commit Hold shift + click to select a range
8e030f8
fix(idt): panic in `impl fmt::Debug for EntryOptions`
mkroening Dec 7, 2024
00f897c
Merge pull request #522 from mkroening/idt-fmt
Freax13 Dec 7, 2024
50dff1f
Add MapperFlush method to get page
adavis628 Dec 23, 2024
a1ffaad
Merge pull request #525 from adavis628/master
Freax13 Dec 24, 2024
61cd811
docs(xcontrol): add missing period
mkroening Dec 24, 2024
87a7aff
feat: add `update()` to `Cr3`, `Dr7`, `SFMask`, `UCet`, `SCet`, `mxcs…
mkroening Dec 24, 2024
59ac07c
Merge pull request #527 from mkroening/xcr0-update
Freax13 Dec 24, 2024
7c82b6c
Add page attribute table support
adavis628 Jan 19, 2025
e396fef
Formatting
adavis628 Jan 19, 2025
8aaff74
fix clippy warnings
Freax13 Jan 19, 2025
1d1bcc2
remove macos-12 from test matrix
Freax13 Jan 19, 2025
a675195
Merge pull request #530 from Freax13/fix/warnings-2025-01-19
phil-opp Jan 19, 2025
447c56d
Merge branch 'rust-osdev:master' into master
adavis628 Jan 19, 2025
0ba90da
Apply suggestions
adavis628 Jan 19, 2025
2486164
Fixes
adavis628 Jan 27, 2025
ffe34b0
Merge pull request #529 from adavis628/master
Freax13 Jan 27, 2025
32327c0
feat(msr): add IA32_APIC_BASE support
hannahfluch Jan 27, 2025
0609af0
use default python again
Freax13 Jan 27, 2025
6286c51
feat(msr): add X2APIC enable functionality
hannahfluch Jan 28, 2025
7a97e48
refactor(msr): handle apic base as seperate value
hannahfluch Jan 28, 2025
753388d
fix(msr): properly mask APIC_BASE
hannahfluch Jan 28, 2025
564bcc3
Merge pull request #533 from rust-osdev/fix/ci-release
phil-opp Jan 28, 2025
9e38b08
style(msr): address cosmetic changes
hannahfluch Jan 28, 2025
dc43e5a
Merge pull request #532 from hannahfluch/master
Freax13 Jan 29, 2025
01ffca1
Ensure that addition and subtraction of addresses panics on overflow/…
farnz Feb 11, 2025
c36cfb4
Fix test for overflowing physaddr - forgot to commit before pushing
farnz Feb 11, 2025
be15a1e
Merge pull request #535 from farnz/checked_add_addrs
Freax13 Feb 11, 2025
c47d970
don't pass -Crelocation-model=static to host targets
Freax13 Feb 11, 2025
f01a291
Merge pull request #536 from Freax13/fix/ci-static-relocation
phil-opp Feb 12, 2025
35643d2
improve panic messages for arithmetic operations
Freax13 Apr 26, 2025
0de6929
improve docs for Add/Sub ops for VirtAddr
Freax13 Apr 26, 2025
9923b27
fix kani build job
Freax13 Apr 26, 2025
f97b845
Merge pull request #544 from rust-osdev/fix/kani
phil-opp Apr 26, 2025
7e8a6b0
Merge pull request #543 from rust-osdev/enhancement/address-gap-panics
Freax13 Apr 26, 2025
cf725db
Revert "Merge pull request #529 from adavis628/master"
Freax13 Apr 26, 2025
bc8c991
fix warning
Freax13 Apr 26, 2025
284bdca
Merge pull request #545 from rust-osdev/revert/529
Freax13 Apr 26, 2025
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
11 changes: 5 additions & 6 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ jobs:
strategy:
fail-fast: false
matrix:
platform: [ubuntu-latest, macos-12, macos-latest, windows-latest]
platform: [ubuntu-latest, macos-latest, windows-latest]

runs-on: ${{ matrix.platform }}
timeout-minutes: 15
Expand Down Expand Up @@ -89,9 +89,6 @@ jobs:
runs-on: ${{ matrix.platform }}
timeout-minutes: 15

env:
RUSTFLAGS: -Crelocation-model=static -Dwarnings

steps:
- name: "Checkout Repository"
uses: actions/checkout@v4
Expand Down Expand Up @@ -137,9 +134,11 @@ jobs:
run: qemu-system-x86_64 --version

- name: "Run Test Framework"
run: cargo test
run: cargo test --target x86_64-unknown-none
shell: bash
working-directory: "testing"
env:
RUSTFLAGS: -Crelocation-model=static -Dwarnings

check_formatting:
name: "Check Formatting"
Expand Down Expand Up @@ -177,7 +176,7 @@ jobs:
run: cargo +stable semver-checks check-release

kani:
runs-on: ubuntu-20.04
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: Swatinem/rust-cache@v2
Expand Down
6 changes: 1 addition & 5 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,8 @@ jobs:
- name: "Checkout Repository"
uses: actions/checkout@v4

# TODO: Remove when Python 3.11 is the default on the Gihtub Actions image
- name: "Install Python 3.11"
run: sudo apt-get -y install python3.11

- name: "Run release script"
run: "python3.11 scripts/ci-release.py"
run: "python scripts/ci-release.py"
env:
CARGO_REGISTRY_TOKEN: ${{ secrets.CARGO_REGISTRY_TOKEN }}
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
96 changes: 92 additions & 4 deletions src/addr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -364,13 +364,41 @@ impl fmt::Pointer for VirtAddr {

impl Add<u64> for VirtAddr {
type Output = Self;

#[cfg_attr(not(feature = "step_trait"), allow(rustdoc::broken_intra_doc_links))]
/// Add an offset to a virtual address.
///
/// This function performs normal arithmetic addition and doesn't jump the
/// address gap. If you're looking for a successor operation that jumps the
/// address gap, use [`Step::forward`].
///
/// # Panics
///
/// This function will panic on overflow or if the result is not a
/// canonical address.
#[inline]
fn add(self, rhs: u64) -> Self::Output {
VirtAddr::new(self.0 + rhs)
VirtAddr::try_new(
self.0
.checked_add(rhs)
.expect("attempt to add with overflow"),
)
.expect("attempt to add resulted in non-canonical virtual address")
}
}

impl AddAssign<u64> for VirtAddr {
#[cfg_attr(not(feature = "step_trait"), allow(rustdoc::broken_intra_doc_links))]
/// Add an offset to a virtual address.
///
/// This function performs normal arithmetic addition and doesn't jump the
/// address gap. If you're looking for a successor operation that jumps the
/// address gap, use [`Step::forward`].
///
/// # Panics
///
/// This function will panic on overflow or if the result is not a
/// canonical address.
#[inline]
fn add_assign(&mut self, rhs: u64) {
*self = *self + rhs;
Expand All @@ -379,13 +407,41 @@ impl AddAssign<u64> for VirtAddr {

impl Sub<u64> for VirtAddr {
type Output = Self;

#[cfg_attr(not(feature = "step_trait"), allow(rustdoc::broken_intra_doc_links))]
/// Subtract an offset from a virtual address.
///
/// This function performs normal arithmetic subtraction and doesn't jump
/// the address gap. If you're looking for a predecessor operation that
/// jumps the address gap, use [`Step::backward`].
///
/// # Panics
///
/// This function will panic on overflow or if the result is not a
/// canonical address.
#[inline]
fn sub(self, rhs: u64) -> Self::Output {
VirtAddr::new(self.0.checked_sub(rhs).unwrap())
VirtAddr::try_new(
self.0
.checked_sub(rhs)
.expect("attempt to subtract with overflow"),
)
.expect("attempt to subtract resulted in non-canonical virtual address")
}
}

impl SubAssign<u64> for VirtAddr {
#[cfg_attr(not(feature = "step_trait"), allow(rustdoc::broken_intra_doc_links))]
/// Subtract an offset from a virtual address.
///
/// This function performs normal arithmetic subtraction and doesn't jump
/// the address gap. If you're looking for a predecessor operation that
/// jumps the address gap, use [`Step::backward`].
///
/// # Panics
///
/// This function will panic on overflow or if the result is not a
/// canonical address.
#[inline]
fn sub_assign(&mut self, rhs: u64) {
*self = *self - rhs;
Expand All @@ -394,9 +450,17 @@ impl SubAssign<u64> for VirtAddr {

impl Sub<VirtAddr> for VirtAddr {
type Output = u64;

/// Returns the difference between two addresses.
///
/// # Panics
///
/// This function will panic on overflow.
#[inline]
fn sub(self, rhs: VirtAddr) -> Self::Output {
self.as_u64().checked_sub(rhs.as_u64()).unwrap()
self.as_u64()
.checked_sub(rhs.as_u64())
.expect("attempt to subtract with overflow")
}
}

Expand Down Expand Up @@ -593,7 +657,7 @@ impl Add<u64> for PhysAddr {
type Output = Self;
#[inline]
fn add(self, rhs: u64) -> Self::Output {
PhysAddr::new(self.0 + rhs)
PhysAddr::new(self.0.checked_add(rhs).unwrap())
}
}

Expand Down Expand Up @@ -663,6 +727,30 @@ pub const fn align_up(addr: u64, align: u64) -> u64 {
mod tests {
use super::*;

#[test]
#[should_panic]
pub fn add_overflow_virtaddr() {
let _ = VirtAddr::new(0xffff_ffff_ffff_ffff) + 1;
}

#[test]
#[should_panic]
pub fn add_overflow_physaddr() {
let _ = PhysAddr::new(0x000f_ffff_ffff_ffff) + 0xffff_0000_0000_0000;
}

#[test]
#[should_panic]
pub fn sub_underflow_virtaddr() {
let _ = VirtAddr::new(0) - 1;
}

#[test]
#[should_panic]
pub fn sub_overflow_physaddr() {
let _ = PhysAddr::new(0) - 1;
}

#[test]
pub fn virtaddr_new_truncate() {
assert_eq!(VirtAddr::new_truncate(0), VirtAddr(0));
Expand Down
57 changes: 57 additions & 0 deletions src/registers/control.rs
Original file line number Diff line number Diff line change
Expand Up @@ -361,6 +361,63 @@ mod x86_64 {
asm!("mov cr3, {}", in(reg) value, options(nostack, preserves_flags));
}
}

/// Update the P4 table address in the CR3 register.
///
/// ## Safety
///
/// Changing the level 4 page table is unsafe, because it's possible to violate memory safety by
/// changing the page mapping.
#[inline]
pub unsafe fn update<F>(f: F)
where
F: FnOnce(&mut PhysFrame, &mut Cr3Flags),
{
let (mut frame, mut flags) = Self::read();
f(&mut frame, &mut flags);
unsafe {
Self::write(frame, flags);
}
}

/// Updates the P4 table address in the CR3 register.
///
/// ## Safety
///
/// Changing the level 4 page table is unsafe, because it's possible to violate memory safety by
/// changing the page mapping.
/// [`Cr4Flags::PCID`] must be set before calling this method.
#[inline]
pub unsafe fn update_pcid<F>(f: F)
where
F: FnOnce(&mut PhysFrame, &mut Pcid),
{
let (mut frame, mut pcid) = Self::read_pcid();
f(&mut frame, &mut pcid);
unsafe {
Self::write_pcid(frame, pcid);
}
}

/// Updates the P4 table address in the CR3 register without flushing existing TLB entries for
/// the PCID.
///
/// ## Safety
///
/// Changing the level 4 page table is unsafe, because it's possible to violate memory safety by
/// changing the page mapping.
/// [`Cr4Flags::PCID`] must be set before calling this method.
#[inline]
pub unsafe fn update_pcid_no_flush<F>(f: F)
where
F: FnOnce(&mut PhysFrame, &mut Pcid),
{
let (mut frame, mut pcid) = Self::read_pcid();
f(&mut frame, &mut pcid);
unsafe {
Self::write_pcid_no_flush(frame, pcid);
}
}
}

impl Cr4 {
Expand Down
13 changes: 13 additions & 0 deletions src/registers/debug.rs
Original file line number Diff line number Diff line change
Expand Up @@ -499,5 +499,18 @@ mod x86_64 {
asm!("mov dr7, {}", in(reg) value, options(nomem, nostack, preserves_flags));
}
}

/// Update the DR7 value.
///
/// Preserves the value of reserved fields.
#[inline]
pub fn update<F>(f: F)
where
F: FnOnce(&mut Dr7Value),
{
let mut value = Self::read();
f(&mut value);
Self::write(value);
}
}
}
Loading
Loading