kernel/slab: Change checks in FreeRawOrReturnCache to panic instead.

The function is largely useless if we cannot lock kernel space,
and the consumers may not expect it to silently "fail." Hence,
we now put the invocation of deferred_free in free_etc directly.
This commit is contained in:
Augustin Cavalier
2022-02-08 18:33:20 -05:00
parent fc38a41393
commit e12a5fe215
2 changed files with 11 additions and 14 deletions
+6 -14
View File
@@ -697,6 +697,11 @@ MemoryManager::FreeRawOrReturnCache(void* pages, uint32 flags)
T(FreeRawOrReturnCache(pages, flags));
if ((flags & CACHE_DONT_LOCK_KERNEL_SPACE) != 0) {
panic("cannot proceed without locking kernel space!");
return NULL;
}
// get the area
addr_t areaBase = _AreaBaseAddressForAddress((addr_t)pages);
@@ -705,14 +710,7 @@ MemoryManager::FreeRawOrReturnCache(void* pages, uint32 flags)
readLocker.Unlock();
if (area == NULL) {
// Probably a large allocation.
if ((flags & CACHE_DONT_LOCK_KERNEL_SPACE) != 0) {
// We cannot delete areas without locking the kernel address space,
// so defer the free until we can do that.
deferred_free(pages);
return NULL;
}
// Probably a large allocation. Look up the VM area.
VMAddressSpace* addressSpace = VMAddressSpace::Kernel();
addressSpace->ReadLock();
VMArea* area = addressSpace->LookupArea((addr_t)pages);
@@ -746,12 +744,6 @@ MemoryManager::FreeRawOrReturnCache(void* pages, uint32 flags)
size_t size = reference - (addr_t)pages + 1;
ASSERT((size % SLAB_CHUNK_SIZE_SMALL) == 0);
// Verify we can actually lock the kernel space before going further.
if ((flags & CACHE_DONT_LOCK_KERNEL_SPACE) != 0) {
deferred_free(pages);
return NULL;
}
// unmap the chunks
_UnmapChunk(area->vmArea, (addr_t)pages, size, flags);
+5
View File
@@ -242,6 +242,11 @@ aligned_alloc(size_t alignment, size_t size)
void
free_etc(void *address, uint32 flags)
{
if ((flags & CACHE_DONT_LOCK_KERNEL_SPACE) != 0) {
deferred_free(address);
return;
}
block_free(address, flags & CACHE_ALLOC_FLAGS);
}