diff options
Diffstat (limited to 'src')
| -rw-r--r-- | src/mem/alloc.rs | 139 | 
1 files changed, 138 insertions, 1 deletions
| diff --git a/src/mem/alloc.rs b/src/mem/alloc.rs index 66a8778..4d02ddd 100644 --- a/src/mem/alloc.rs +++ b/src/mem/alloc.rs @@ -165,6 +165,55 @@ impl<T: Debug,const COUNT: usize> Debug for QueueAllocator<'_,T,COUNT> {  /// 256 bit size field  #[derive(Copy,Clone)]  pub struct U256(u128,u128); +impl U256 { +	pub const fn new() -> Self { +		U256(0,0) +	} +} + +/// # u512 struct +/// +/// 512 bit size field +#[derive(Copy,Clone)] +pub struct U512(U256,U256); +impl U512 { +	pub const fn new() -> Self { +		U512(U256::new(), U256::new()) +	} +} + +/// # u1024 struct +/// +/// 1024 bit size field +#[derive(Copy,Clone)] +pub struct U1024(U512,U512); +impl U1024 { +	pub const fn new() -> Self { +		U1024(U512::new(), U512::new()) +	} +} + +/// # u2048 struct +/// +/// 2048 bit size field +#[derive(Copy,Clone)] +pub struct U2048(U1024,U1024); +impl U2048 { +	pub const fn new() -> Self { +		U2048(U1024::new(), U1024::new()) +	} +} + +/// # u4096 struct +/// +/// 4096 bit size field +#[derive(Copy,Clone)] +pub struct U4096(U2048,U2048); +impl U4096 { +	pub const fn new() -> Self { +		U4096(U2048::new(), U2048::new()) +	} +}  /// # Grand Allocator  /// @@ -179,7 +228,11 @@ init_queue!(U16_GRAND_ALLOC, GRAND_ALLOC_SIZE, 0, u16);  init_queue!(U32_GRAND_ALLOC, GRAND_ALLOC_SIZE, 0, u32);  init_queue!(U64_GRAND_ALLOC, GRAND_ALLOC_SIZE, 0, u64);  init_queue!(U128_GRAND_ALLOC, GRAND_ALLOC_SIZE, 0, u128); -init_queue!(U256_GRAND_ALLOC, GRAND_ALLOC_SIZE, {U256(0,0)}, U256); +init_queue!(U256_GRAND_ALLOC, GRAND_ALLOC_SIZE, {U256::new()}, U256); +init_queue!(U512_GRAND_ALLOC, GRAND_ALLOC_SIZE, {U512::new()}, U512); +init_queue!(U1024_GRAND_ALLOC, GRAND_ALLOC_SIZE, {U1024::new()}, U1024); +init_queue!(U2048_GRAND_ALLOC, GRAND_ALLOC_SIZE, {U2048::new()}, U2048); +init_queue!(U4096_GRAND_ALLOC, GRAND_ALLOC_SIZE, {U4096::new()}, U4096);  impl GrandAllocator {  	pub fn init(&self) { @@ -189,6 +242,10 @@ impl GrandAllocator {  		U64_GRAND_ALLOC.init();  		U128_GRAND_ALLOC.init();  		U256_GRAND_ALLOC.init(); +		U512_GRAND_ALLOC.init(); +		U1024_GRAND_ALLOC.init(); +		U2048_GRAND_ALLOC.init(); +		U4096_GRAND_ALLOC.init();  	}  } @@ -258,6 +315,46 @@ unsafe impl GlobalAlloc for GrandAllocator {  					}  				}  			} +			33..=64 => { +				match U512_GRAND_ALLOC.alloc() { +					None => { +						panic!("No cells to allocate!"); +					} +					Some(elem) => { +						return (*elem).ptr(); +					} +				} +			} +			65..=128 => { +				match U1024_GRAND_ALLOC.alloc() { +					None => { +						panic!("No cells to allocate!"); +					} +					Some(elem) => { +						return (*elem).ptr(); +					} +				} +			} +			129..=256 => { +				match U2048_GRAND_ALLOC.alloc() { +					None => { +						panic!("No cells to allocate!"); +					} +					Some(elem) => { +						return (*elem).ptr(); +					} +				} +			} +			257..=512 => { +				match U4096_GRAND_ALLOC.alloc() { +					None => { +						panic!("No cells to allocate!"); +					} +					Some(elem) => { +						return (*elem).ptr(); +					} +				} +			}  			_ => {  				panic!("No allocators for size {}!", layout.size());  			} @@ -329,6 +426,46 @@ unsafe impl GlobalAlloc for GrandAllocator {  					U256_GRAND_ALLOC.free(&mut pool[index]);  				});  			} +			33..=64 => { +				U512_GRAND_ALLOC.inner.lock(|pool| { +					let spacing: usize = (pool[3].ptr() as usize) - (pool[2].ptr() as usize); +					let diff: usize = (ptr as usize) - (pool[2].ptr() as usize); +					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]); +				}); +			} +			65..=128 => { +				U1024_GRAND_ALLOC.inner.lock(|pool| { +					let spacing: usize = (pool[3].ptr() as usize) - (pool[2].ptr() as usize); +					let diff: usize = (ptr as usize) - (pool[2].ptr() as usize); +					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]); +				}); +			} +			129..=256 => { +				U2048_GRAND_ALLOC.inner.lock(|pool| { +					let spacing: usize = (pool[3].ptr() as usize) - (pool[2].ptr() as usize); +					let diff: usize = (ptr as usize) - (pool[2].ptr() as usize); +					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]); +				}); +			} +			257..=512 => { +				U4096_GRAND_ALLOC.inner.lock(|pool| { +					let spacing: usize = (pool[3].ptr() as usize) - (pool[2].ptr() as usize); +					let diff: usize = (ptr as usize) - (pool[2].ptr() as usize); +					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]); +				}); +			}  			_ => {  				panic!("No deallocators for size {}!", layout.size());  			} | 
