1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-25 04:17:35 +00:00

Kernel: Allow preventing kmalloc and kfree

For "destructive" disallowance of allocations throughout the system,
Thread gains a member that controls whether allocations are currently
allowed or not. kmalloc checks this member on both allocations and
deallocations (with the exception of early boot) and panics the kernel
if allocations are disabled. This will allow for critical sections that
can't be allowed to allocate to fail-fast, making for easier debugging.

PS: My first proper Kernel commit :^)
This commit is contained in:
kleines Filmröllchen 2022-01-08 23:36:13 +01:00 committed by Linus Groh
parent b8d640c3f9
commit e2c9578390
2 changed files with 12 additions and 2 deletions

View file

@ -362,8 +362,12 @@ void* kmalloc(size_t size)
Thread* current_thread = Thread::current();
if (!current_thread)
current_thread = Processor::idle_thread();
if (current_thread)
if (current_thread) {
// FIXME: By the time we check this, we have already allocated above.
// This means that in the case of an infinite recursion, we can't catch it this way.
VERIFY(current_thread->is_allocation_enabled());
PerformanceManager::add_kmalloc_perf_event(*current_thread, size, (FlatPtr)ptr);
}
return ptr;
}
@ -384,8 +388,10 @@ void kfree_sized(void* ptr, size_t size)
Thread* current_thread = Thread::current();
if (!current_thread)
current_thread = Processor::idle_thread();
if (current_thread)
if (current_thread) {
VERIFY(current_thread->is_allocation_enabled());
PerformanceManager::add_kfree_perf_event(*current_thread, 0, (FlatPtr)ptr);
}
}
g_kmalloc_global->deallocate(ptr, size);