Skip to content

Commit 512470b

Browse files
committed
fix(hal): offset addrs by isize instead of i32 (#509)
This changes the `VAddr::offset` and `PAddr::offset` methods to takee an `isize` offset instead of an `i32` offset. I don't know why I used `i32` here, that was stupid. Fixes #507
1 parent 37e0eb9 commit 512470b

File tree

4 files changed

+10
-10
lines changed

4 files changed

+10
-10
lines changed

hal-core/src/addr.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -76,10 +76,10 @@ pub trait Address:
7676
self.align_down(core::mem::align_of::<T>())
7777
}
7878

79-
/// Offsets this address by `offset`.
79+
/// Offsets this address by `offset` bytes.
8080
///
8181
/// If the specified offset would overflow, this function saturates instead.
82-
fn offset(self, offset: i32) -> Self {
82+
fn offset(self, offset: isize) -> Self {
8383
if offset > 0 {
8484
self + offset as usize
8585
} else {
@@ -333,11 +333,11 @@ macro_rules! impl_addrs {
333333
Address::align_down(self, align)
334334
}
335335

336-
/// Offsets this address by `offset`.
336+
/// Offsets this address by `offset` bytes.
337337
///
338338
/// If the specified offset would overflow, this function saturates instead.
339339
#[inline]
340-
pub fn offset(self, offset: i32) -> Self {
340+
pub fn offset(self, offset: isize) -> Self {
341341
Address::offset(self, offset)
342342
}
343343

hal-core/src/mem.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -84,13 +84,13 @@ impl<A: Address> Region<A> {
8484
}
8585

8686
pub fn split_front(&mut self, size: usize) -> Option<Self> {
87-
assert!(size <= core::i32::MAX as usize);
87+
assert!(size <= isize::MAX as usize);
8888
if size > self.size {
8989
return None;
9090
}
9191
let base = self.base;
9292
tracing::trace!(size, self.size, "splitting down by");
93-
self.base = self.base.offset(size as i32);
93+
self.base = self.base.offset(size as isize);
9494
self.size -= size;
9595
Some(Self {
9696
base,
@@ -100,12 +100,12 @@ impl<A: Address> Region<A> {
100100
}
101101

102102
pub fn split_back(&mut self, size: usize) -> Option<Self> {
103-
assert!(size <= core::i32::MAX as usize);
103+
assert!(size <= isize::MAX as usize);
104104
if size >= self.size {
105105
return None;
106106
}
107107
let rem_size = self.size - size;
108-
let base = self.base.offset(size as i32);
108+
let base = self.base.offset(size as isize);
109109
tracing::trace!(
110110
size,
111111
self.size,

hal-x86_64/src/task.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ impl StateSegment {
3737
/// Returns the virtual address of the I/O permission bitmap.
3838
#[inline]
3939
pub fn iomap_addr(&self) -> VAddr {
40-
VAddr::of(self).offset(self.iomap_offset as i32)
40+
VAddr::of(self).offset(self.iomap_offset as isize)
4141
}
4242

4343
/// Loads the provided [`selector`](segment::Selector) into the current task

src/arch/x86_64/interrupt.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ static TSS: sync::Lazy<task::StateSegment> = sync::Lazy::new(|| {
4848
tss.interrupt_stacks[Idt::DOUBLE_FAULT_IST_OFFSET] = unsafe {
4949
// safety: asdf
5050
VAddr::from_usize_unchecked(core::ptr::addr_of!(DOUBLE_FAULT_STACK) as usize)
51-
.offset(DOUBLE_FAULT_STACK_SIZE as i32)
51+
.offset(DOUBLE_FAULT_STACK_SIZE as isize)
5252
};
5353
tracing::debug!(?tss, "TSS initialized");
5454
tss

0 commit comments

Comments
 (0)