Skip to content

Commit

Permalink
Fixup for ddac7f5: Added usize arithmetics for riscv64::VirtAddr
Browse files Browse the repository at this point in the history
  • Loading branch information
jounathaen committed Nov 15, 2024
1 parent e526923 commit 45de247
Showing 1 changed file with 35 additions and 0 deletions.
35 changes: 35 additions & 0 deletions src/arch/riscv64.rs
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,41 @@ impl From<usize> for VirtAddr {
}
}

#[cfg(target_pointer_width = "64")]
// if the target_pointer_width is 64, usize = u64 so we can safely add
impl core::ops::Add<usize> for VirtAddr {
type Output = Self;
#[inline]
fn add(self, rhs: usize) -> Self::Output {
VirtAddr::new(self.0 + rhs as u64)
}
}
#[cfg(target_pointer_width = "64")]
// if the target_pointer_width is 64, usize = u64 so we can safely add
impl core::ops::AddAssign<usize> for VirtAddr {
#[inline]
fn add_assign(&mut self, rhs: usize) {
*self = *self + rhs;
}
}
#[cfg(target_pointer_width = "64")]
// if the target_pointer_width is 64, usize = u64 so we can safely sub
impl core::ops::Sub<usize> for VirtAddr {
type Output = Self;
#[inline]
fn sub(self, rhs: usize) -> Self::Output {
VirtAddr::new(self.0.checked_sub(rhs as u64).unwrap())
}
}
#[cfg(target_pointer_width = "64")]
// if the target_pointer_width is 64, usize = u64 so we can safely sub
impl core::ops::SubAssign<usize> for VirtAddr {
#[inline]
fn sub_assign(&mut self, rhs: usize) {
*self = *self - rhs;
}
}

#[cfg(target_pointer_width = "64")]
// if the target_pointer_width is 64, usize = u64 so we can safely transform.
impl From<usize> for PhysAddr {
Expand Down

0 comments on commit 45de247

Please sign in to comment.