CONFIG_MEMORY_UNION_ALL

This commit is contained in:
Arthur Beck 2025-02-16 21:04:55 -06:00
parent 884e9aa3cf
commit e81525d349
Signed by: ArthurB
GPG key ID: ACE3D14F5CEF14BF
3 changed files with 21 additions and 0 deletions

View file

@ -39,6 +39,8 @@ fn main() {
);
println!(r#"cargo:rustc-check-cfg=cfg(CONFIG_BUILD_GRUB, values("true", "false", none()))"#);
println!(r#"cargo:rustc-check-cfg=cfg(CONFIG_MEMORY_UNION_ALL, values("true", "false", none()))"#);
// End checks
// Configuration name used when a config is required but should always evaluate to true

View file

@ -35,4 +35,5 @@ CONFIG_BUILD_GRUB=true
# The precision of the allocator. The size of the allocated region is divided by this to get how much to change it by each loop iteration
# when trying to find a allocatable region.
CONFIG_ALLOC_PRECISION=4
CONFIG_MEMORY_UNION_ALL=false
# End configs

View file

@ -322,6 +322,9 @@ impl<'a> MemoryMapAlloc<'a> {
/// Check to see if any allocations contain the given address. Returns true if so.
fn check_addr(&self, addr: u64) -> bool {
if cfg!(CONFIG_MEMORY_UNION_ALL = "true") {
return false;
}
if addr >= (self.allocationheader as u64)
&& addr < (self.allocationheader as u64 + unsafe { *self.allocationheader }.len)
{
@ -338,6 +341,9 @@ impl<'a> MemoryMapAlloc<'a> {
/// Check to see if a range of addresses have any allocations within. Returns true if so.
fn check_range(&self, addr: Range<u64>) -> bool {
if cfg!(CONFIG_MEMORY_UNION_ALL = "true") {
return false;
}
for addr in addr {
// REALLY inefficient, but I don't think there's a better way.
if self.check_addr(addr) {
@ -519,6 +525,7 @@ unsafe impl<'a> Allocator for MemoryMapAlloc<'a> {
continue;
}
}
if addr == 0 {
unsafe {
LAST_MEMMAP_ERR = Err(crate::Error::new(
@ -528,6 +535,14 @@ unsafe impl<'a> Allocator for MemoryMapAlloc<'a> {
}
return Err(core::alloc::AllocError {});
}
if cfg!(CONFIG_MEMORY_UNION_ALL = "true") {
return Ok(NonNull::from_raw_parts(
NonNull::<u8>::without_provenance(NonZero::new(addr as usize).unwrap()),
layout.size(),
));
}
if let Err(err) = self.add_allocation(Allocation {
used: true,
addr,
@ -545,6 +560,9 @@ unsafe impl<'a> Allocator for MemoryMapAlloc<'a> {
unsafe fn deallocate(&self, ptr: core::ptr::NonNull<u8>, _layout: core::alloc::Layout) {
unsafe { LAST_MEMMAP_ERR = Ok(()) }
if cfg!(CONFIG_MEMORY_UNION_ALL = "true") {
return;
}
let addr = ptr.addr().get() as u64;
if self.allocations == core::ptr::null_mut() {
unsafe {