aboutsummaryrefslogtreecommitdiff
path: root/src/mem
diff options
context:
space:
mode:
authorChristian Cunningham <cc@localhost>2022-08-20 22:45:29 -0700
committerChristian Cunningham <cc@localhost>2022-08-20 22:45:29 -0700
commitb34903977707ad344c53f3e1367063b0bb944176 (patch)
treef9085db18b83d5979776f7c71317eb6530e5a322 /src/mem
parent2c859ced8adb5a9876d39b34471400a43516b036 (diff)
Fix index offset
Diffstat (limited to 'src/mem')
-rw-r--r--src/mem/alloc.rs32
1 files changed, 16 insertions, 16 deletions
diff --git a/src/mem/alloc.rs b/src/mem/alloc.rs
index f4ba935..1a4ad77 100644
--- a/src/mem/alloc.rs
+++ b/src/mem/alloc.rs
@@ -60,7 +60,7 @@ impl<T: Debug> Debug for QueueItem<'_,T> {
///
/// Output the encapsulated data
fn fmt(&self, f: &mut Formatter<'_>) -> fmt::Result {
- write!(f, "{:?}", self.data)
+ write!(f, "{:?} {:x} {:?}", self.data, self as *const QueueItem<'_,T> as usize, self.next)
}
}
@@ -85,15 +85,15 @@ impl<'a, T: Sized,const COUNT: usize> QueueAllocator<'a, T, COUNT> {
/// one and the final element points to `None`
pub fn init(&self) {
self.inner.lock(|queue| {
- for idx in 2..queue.len() {
- if idx != queue.len()-1 {
- queue[idx].next = Some(&mut queue[idx+1] as *mut QueueItem<'_, T>);
+ for idx in 2..COUNT {
+ if idx != COUNT-1 {
+ queue[idx].next = Some(&mut queue[idx+1] as *mut QueueItem<'a, T>);
} else {
queue[idx].next = None;
}
}
- queue[0].next = Some(&mut queue[2] as *mut QueueItem<'_, T>);
- queue[1].next = Some(&mut queue[queue.len()-1] as *mut QueueItem<'_, T>);
+ queue[0].next = Some(&mut queue[2] as *mut QueueItem<'a, T>);
+ queue[1].next = Some(&mut queue[COUNT-1] as *mut QueueItem<'a, T>);
});
}
@@ -375,7 +375,7 @@ unsafe impl GlobalAlloc for GrandAllocator {
let index: usize = diff/spacing;
assert!(index < GRAND_ALLOC_SIZE, "{} is out of the allocation bounds ({})", index, GRAND_ALLOC_SIZE);
assert_eq!(diff % spacing, 0, "{} is not aligned with the spacings and so it must not have been allocated by the Grand Allocator", diff % spacing);
- U8_GRAND_ALLOC.free(&mut pool[index]);
+ U8_GRAND_ALLOC.free(&mut pool[index+2]);
});
}
2 => {
@@ -385,7 +385,7 @@ unsafe impl GlobalAlloc for GrandAllocator {
let index: usize = diff/spacing;
assert!(index < GRAND_ALLOC_SIZE, "{} is out of the allocation bounds ({})", index, GRAND_ALLOC_SIZE);
assert_eq!(diff % spacing, 0, "{} is not aligned with the spacings and so it must not have been allocated by the Grand Allocator", diff % spacing);
- U16_GRAND_ALLOC.free(&mut pool[index]);
+ U16_GRAND_ALLOC.free(&mut pool[index+2]);
});
}
3..=4 => {
@@ -395,7 +395,7 @@ unsafe impl GlobalAlloc for GrandAllocator {
let index: usize = diff/spacing;
assert!(index < GRAND_ALLOC_SIZE, "{} is out of the allocation bounds ({})", index, GRAND_ALLOC_SIZE);
assert_eq!(diff % spacing, 0, "{} is not aligned with the spacings and so it must not have been allocated by the Grand Allocator", diff % spacing);
- U32_GRAND_ALLOC.free(&mut pool[index]);
+ U32_GRAND_ALLOC.free(&mut pool[index+2]);
});
}
5..=8 => {
@@ -405,7 +405,7 @@ unsafe impl GlobalAlloc for GrandAllocator {
let index: usize = diff/spacing;
assert!(index < GRAND_ALLOC_SIZE, "{} is out of the allocation bounds ({})", index, GRAND_ALLOC_SIZE);
assert_eq!(diff % spacing, 0, "{} is not aligned with the spacings and so it must not have been allocated by the Grand Allocator", diff % spacing);
- U64_GRAND_ALLOC.free(&mut pool[index]);
+ U64_GRAND_ALLOC.free(&mut pool[index+2]);
});
}
9..=16 => {
@@ -415,7 +415,7 @@ unsafe impl GlobalAlloc for GrandAllocator {
let index: usize = diff/spacing;
assert!(index < GRAND_ALLOC_SIZE, "{} is out of the allocation bounds ({})", index, GRAND_ALLOC_SIZE);
assert_eq!(diff % spacing, 0, "{} is not aligned with the spacings and so it must not have been allocated by the Grand Allocator", diff % spacing);
- U128_GRAND_ALLOC.free(&mut pool[index]);
+ U128_GRAND_ALLOC.free(&mut pool[index+2]);
});
}
17..=32 => {
@@ -425,7 +425,7 @@ unsafe impl GlobalAlloc for GrandAllocator {
let index: usize = diff/spacing;
assert!(index < GRAND_ALLOC_SIZE, "{} is out of the allocation bounds ({})", index, GRAND_ALLOC_SIZE);
assert_eq!(diff % spacing, 0, "{} is not aligned with the spacings and so it must not have been allocated by the Grand Allocator", diff % spacing);
- U256_GRAND_ALLOC.free(&mut pool[index]);
+ U256_GRAND_ALLOC.free(&mut pool[index+2]);
});
}
33..=64 => {
@@ -435,7 +435,7 @@ unsafe impl GlobalAlloc for GrandAllocator {
let index: usize = diff/spacing;
assert!(index < GRAND_ALLOC_SIZE, "{} is out of the allocation bounds ({})", index, GRAND_ALLOC_SIZE);
assert_eq!(diff % spacing, 0, "{} is not aligned with the spacings and so it must not have been allocated by the Grand Allocator", diff % spacing);
- U512_GRAND_ALLOC.free(&mut pool[index]);
+ U512_GRAND_ALLOC.free(&mut pool[index+2]);
});
}
65..=128 => {
@@ -445,7 +445,7 @@ unsafe impl GlobalAlloc for GrandAllocator {
let index: usize = diff/spacing;
assert!(index < GRAND_ALLOC_SIZE, "{} is out of the allocation bounds ({})", index, GRAND_ALLOC_SIZE);
assert_eq!(diff % spacing, 0, "{} is not aligned with the spacings and so it must not have been allocated by the Grand Allocator", diff % spacing);
- U1024_GRAND_ALLOC.free(&mut pool[index]);
+ U1024_GRAND_ALLOC.free(&mut pool[index+2]);
});
}
129..=256 => {
@@ -455,7 +455,7 @@ unsafe impl GlobalAlloc for GrandAllocator {
let index: usize = diff/spacing;
assert!(index < GRAND_ALLOC_SIZE, "{} is out of the allocation bounds ({})", index, GRAND_ALLOC_SIZE);
assert_eq!(diff % spacing, 0, "{} is not aligned with the spacings and so it must not have been allocated by the Grand Allocator", diff % spacing);
- U2048_GRAND_ALLOC.free(&mut pool[index]);
+ U2048_GRAND_ALLOC.free(&mut pool[index+2]);
});
}
257..=512 => {
@@ -465,7 +465,7 @@ unsafe impl GlobalAlloc for GrandAllocator {
let index: usize = diff/spacing;
assert!(index < GRAND_ALLOC_SIZE, "{} is out of the allocation bounds ({})", index, GRAND_ALLOC_SIZE);
assert_eq!(diff % spacing, 0, "{} is not aligned with the spacings and so it must not have been allocated by the Grand Allocator", diff % spacing);
- U4096_GRAND_ALLOC.free(&mut pool[index]);
+ U4096_GRAND_ALLOC.free(&mut pool[index+2]);
});
}
_ => {