Better error handling for dealloc

This commit is contained in:
August 2025-09-30 15:22:15 -04:00
parent 9646f7de8b
commit eef96dfc87
Signed by: shibedrill
GPG Key ID: 5FE0CB25945EFAA2

View File

@ -27,16 +27,23 @@ lazy_static! {
pub fn deallocate_usable() -> Result<(), AllocError> { pub fn deallocate_usable() -> Result<(), AllocError> {
init_statics(); init_statics();
let mut any_error: Option<AllocError> = None;
let mut bytes_deallocated: u64 = 0; let mut bytes_deallocated: u64 = 0;
for entry in MEMMAP_RESPONSE.entries() { for entry in MEMMAP_RESPONSE.entries() {
if (entry.entry_type == EntryType::USABLE) | (entry.entry_type == EntryType::BOOTLOADER_RECLAIMABLE) { if (entry.entry_type == EntryType::USABLE) | (entry.entry_type == EntryType::BOOTLOADER_RECLAIMABLE) {
deallocate(**entry)?; if let Err(error) = deallocate(**entry) {
any_error = Some(error);
}
bytes_deallocated += entry.length; bytes_deallocated += entry.length;
} }
} }
log_trace!("Deallocated 0x{:x} bytes", bytes_deallocated); log_trace!("Deallocated 0x{:x} bytes", bytes_deallocated);
if let Some(error) = any_error {
Err(error)
} else {
Ok(()) Ok(())
} }
}
pub fn deallocate(entry: limine::memory_map::Entry) -> Result<(), AllocError> { pub fn deallocate(entry: limine::memory_map::Entry) -> Result<(), AllocError> {
@ -129,6 +136,7 @@ pub fn log_address() {
); );
} }
// Have to initialize all of these before reclaiming bootloader memory
fn init_statics() { fn init_statics() {
let _ = EXECUTABLE_FILE_RESPONSE; let _ = EXECUTABLE_FILE_RESPONSE;
let _ = HHDM_RESPONSE; let _ = HHDM_RESPONSE;