CONFIG_MEMORY_UNION_ALL
This commit is contained in:
parent
884e9aa3cf
commit
e81525d349
3 changed files with 21 additions and 0 deletions
|
@ -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_BUILD_GRUB, values("true", "false", none()))"#);
|
||||||
|
|
||||||
|
println!(r#"cargo:rustc-check-cfg=cfg(CONFIG_MEMORY_UNION_ALL, values("true", "false", none()))"#);
|
||||||
// End checks
|
// End checks
|
||||||
|
|
||||||
// Configuration name used when a config is required but should always evaluate to true
|
// Configuration name used when a config is required but should always evaluate to true
|
||||||
|
|
|
@ -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
|
# 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.
|
# when trying to find a allocatable region.
|
||||||
CONFIG_ALLOC_PRECISION=4
|
CONFIG_ALLOC_PRECISION=4
|
||||||
|
CONFIG_MEMORY_UNION_ALL=false
|
||||||
# End configs
|
# End configs
|
|
@ -322,6 +322,9 @@ impl<'a> MemoryMapAlloc<'a> {
|
||||||
|
|
||||||
/// Check to see if any allocations contain the given address. Returns true if so.
|
/// Check to see if any allocations contain the given address. Returns true if so.
|
||||||
fn check_addr(&self, addr: u64) -> bool {
|
fn check_addr(&self, addr: u64) -> bool {
|
||||||
|
if cfg!(CONFIG_MEMORY_UNION_ALL = "true") {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
if addr >= (self.allocationheader as u64)
|
if addr >= (self.allocationheader as u64)
|
||||||
&& addr < (self.allocationheader as u64 + unsafe { *self.allocationheader }.len)
|
&& 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.
|
/// Check to see if a range of addresses have any allocations within. Returns true if so.
|
||||||
fn check_range(&self, addr: Range<u64>) -> bool {
|
fn check_range(&self, addr: Range<u64>) -> bool {
|
||||||
|
if cfg!(CONFIG_MEMORY_UNION_ALL = "true") {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
for addr in addr {
|
for addr in addr {
|
||||||
// REALLY inefficient, but I don't think there's a better way.
|
// REALLY inefficient, but I don't think there's a better way.
|
||||||
if self.check_addr(addr) {
|
if self.check_addr(addr) {
|
||||||
|
@ -519,6 +525,7 @@ unsafe impl<'a> Allocator for MemoryMapAlloc<'a> {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if addr == 0 {
|
if addr == 0 {
|
||||||
unsafe {
|
unsafe {
|
||||||
LAST_MEMMAP_ERR = Err(crate::Error::new(
|
LAST_MEMMAP_ERR = Err(crate::Error::new(
|
||||||
|
@ -528,6 +535,14 @@ unsafe impl<'a> Allocator for MemoryMapAlloc<'a> {
|
||||||
}
|
}
|
||||||
return Err(core::alloc::AllocError {});
|
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 {
|
if let Err(err) = self.add_allocation(Allocation {
|
||||||
used: true,
|
used: true,
|
||||||
addr,
|
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 fn deallocate(&self, ptr: core::ptr::NonNull<u8>, _layout: core::alloc::Layout) {
|
||||||
unsafe { LAST_MEMMAP_ERR = Ok(()) }
|
unsafe { LAST_MEMMAP_ERR = Ok(()) }
|
||||||
|
if cfg!(CONFIG_MEMORY_UNION_ALL = "true") {
|
||||||
|
return;
|
||||||
|
}
|
||||||
let addr = ptr.addr().get() as u64;
|
let addr = ptr.addr().get() as u64;
|
||||||
if self.allocations == core::ptr::null_mut() {
|
if self.allocations == core::ptr::null_mut() {
|
||||||
unsafe {
|
unsafe {
|
||||||
|
|
Loading…
Add table
Reference in a new issue