Skip to content

Commit

Permalink
update
Browse files Browse the repository at this point in the history
  • Loading branch information
hikalium committed Nov 13, 2024
1 parent 0c6e74d commit 3fc889a
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion os/src/allocator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ extern crate alloc;

use crate::efi::EfiMemoryDescriptor;
use crate::efi::EfiMemoryType;
use crate::error;
use crate::info;
use crate::memory_map_holder::MemoryMapHolder;
use crate::util::round_up_to_nearest_pow2;
Expand Down Expand Up @@ -109,7 +110,10 @@ impl Header {
}
}
fn verify_canary(&self) {
assert!(self.canary == CANARY_SIGNATURE)
if self.canary != CANARY_SIGNATURE {
error!("{self:?}");
panic!("CANARY_SIGNATURE is broken! Possibly OOB write has happened...")
}
}
}
impl Drop for Header {
Expand Down Expand Up @@ -146,6 +150,7 @@ unsafe impl GlobalAlloc for FirstFitAllocator {
}
unsafe fn dealloc(&self, ptr: *mut u8, _layout: Layout) {
let mut region = Header::from_allocated_region(ptr);
region.verify_canary();
region.is_allocated = false;
Box::leak(region);
// region is leaked here to avoid dropping the free info on the memory.
Expand Down

0 comments on commit 3fc889a

Please sign in to comment.