mirror of
https://github.com/RGBCube/serenity
synced 2025-05-31 13:28:11 +00:00
Kernel: Serialize debug output
This commit is contained in:
parent
1da7fea602
commit
3ac6d31b45
5 changed files with 177 additions and 20 deletions
|
@ -38,6 +38,7 @@
|
|||
#include <Kernel/KSyms.h>
|
||||
#include <Kernel/Process.h>
|
||||
#include <Kernel/Scheduler.h>
|
||||
#include <Kernel/SpinLock.h>
|
||||
#include <Kernel/StdLib.h>
|
||||
|
||||
#define SANITIZE_KMALLOC
|
||||
|
@ -66,10 +67,13 @@ bool g_dump_kmalloc_stacks;
|
|||
static u8* s_next_eternal_ptr;
|
||||
static u8* s_end_of_eternal_range;
|
||||
|
||||
static SpinLock s_lock;
|
||||
|
||||
void kmalloc_init()
|
||||
{
|
||||
memset(&alloc_map, 0, sizeof(alloc_map));
|
||||
memset((void*)BASE_PHYSICAL, 0, POOL_SIZE);
|
||||
s_lock.initialize();
|
||||
|
||||
g_kmalloc_bytes_eternal = 0;
|
||||
g_kmalloc_bytes_allocated = 0;
|
||||
|
@ -81,6 +85,7 @@ void kmalloc_init()
|
|||
|
||||
void* kmalloc_eternal(size_t size)
|
||||
{
|
||||
ScopedSpinLock lock(s_lock);
|
||||
void* ptr = s_next_eternal_ptr;
|
||||
s_next_eternal_ptr += size;
|
||||
ASSERT(s_next_eternal_ptr < s_end_of_eternal_range);
|
||||
|
@ -129,7 +134,7 @@ inline void* kmalloc_allocate(size_t first_chunk, size_t chunks_needed)
|
|||
|
||||
void* kmalloc_impl(size_t size)
|
||||
{
|
||||
Kernel::InterruptDisabler disabler;
|
||||
ScopedSpinLock lock(s_lock);
|
||||
++g_kmalloc_call_count;
|
||||
|
||||
if (g_dump_kmalloc_stacks && Kernel::g_kernel_symbols_available) {
|
||||
|
@ -168,12 +173,8 @@ void* kmalloc_impl(size_t size)
|
|||
return kmalloc_allocate(first_chunk.value(), chunks_needed);
|
||||
}
|
||||
|
||||
void kfree(void* ptr)
|
||||
static inline void kfree_impl(void* ptr)
|
||||
{
|
||||
if (!ptr)
|
||||
return;
|
||||
|
||||
Kernel::InterruptDisabler disabler;
|
||||
++g_kfree_call_count;
|
||||
|
||||
auto* a = (AllocationHeader*)((((u8*)ptr) - sizeof(AllocationHeader)));
|
||||
|
@ -190,12 +191,21 @@ void kfree(void* ptr)
|
|||
#endif
|
||||
}
|
||||
|
||||
void kfree(void* ptr)
|
||||
{
|
||||
if (!ptr)
|
||||
return;
|
||||
|
||||
ScopedSpinLock lock(s_lock);
|
||||
kfree_impl(ptr);
|
||||
}
|
||||
|
||||
void* krealloc(void* ptr, size_t new_size)
|
||||
{
|
||||
if (!ptr)
|
||||
return kmalloc(new_size);
|
||||
|
||||
Kernel::InterruptDisabler disabler;
|
||||
ScopedSpinLock lock(s_lock);
|
||||
|
||||
auto* a = (AllocationHeader*)((((u8*)ptr) - sizeof(AllocationHeader)));
|
||||
size_t old_size = a->allocation_size_in_chunks * CHUNK_SIZE;
|
||||
|
@ -205,7 +215,7 @@ void* krealloc(void* ptr, size_t new_size)
|
|||
|
||||
auto* new_ptr = kmalloc(new_size);
|
||||
memcpy(new_ptr, ptr, min(old_size, new_size));
|
||||
kfree(ptr);
|
||||
kfree_impl(ptr);
|
||||
return new_ptr;
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue