mirror of
https://github.com/RGBCube/serenity
synced 2025-07-25 20:57:35 +00:00
Kernel: Make it possible to have kmalloc() dump call stacks.
This can be enabled at any time using a sysctl: sysctl kmalloc_stacks=1 The stacks will go to the debugger output only.
This commit is contained in:
parent
bc6ac1c2f2
commit
d384c7815f
4 changed files with 14 additions and 0 deletions
|
@ -1166,6 +1166,11 @@ ProcFS::ProcFS()
|
||||||
m_entries[FI_PID_exe] = { "exe", FI_PID_exe, procfs$pid_exe };
|
m_entries[FI_PID_exe] = { "exe", FI_PID_exe, procfs$pid_exe };
|
||||||
m_entries[FI_PID_cwd] = { "cwd", FI_PID_cwd, procfs$pid_cwd };
|
m_entries[FI_PID_cwd] = { "cwd", FI_PID_cwd, procfs$pid_cwd };
|
||||||
m_entries[FI_PID_fd] = { "fd", FI_PID_fd };
|
m_entries[FI_PID_fd] = { "fd", FI_PID_fd };
|
||||||
|
|
||||||
|
m_kmalloc_stack_helper.resource() = g_dump_kmalloc_stacks;
|
||||||
|
add_sys_bool("kmalloc_stacks", m_kmalloc_stack_helper, [this] {
|
||||||
|
g_dump_kmalloc_stacks = m_kmalloc_stack_helper.resource();
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
ProcFS::ProcFSDirectoryEntry* ProcFS::get_directory_entry(InodeIdentifier identifier) const
|
ProcFS::ProcFSDirectoryEntry* ProcFS::get_directory_entry(InodeIdentifier identifier) const
|
||||||
|
|
|
@ -59,6 +59,7 @@ private:
|
||||||
mutable Lock m_inodes_lock;
|
mutable Lock m_inodes_lock;
|
||||||
mutable HashMap<unsigned, ProcFSInode*> m_inodes;
|
mutable HashMap<unsigned, ProcFSInode*> m_inodes;
|
||||||
RetainPtr<ProcFSInode> m_root_inode;
|
RetainPtr<ProcFSInode> m_root_inode;
|
||||||
|
Lockable<bool> m_kmalloc_stack_helper;
|
||||||
};
|
};
|
||||||
|
|
||||||
struct ProcFSInodeCustomData {
|
struct ProcFSInodeCustomData {
|
||||||
|
|
|
@ -9,6 +9,7 @@
|
||||||
#include <Kernel/i386.h>
|
#include <Kernel/i386.h>
|
||||||
#include <Kernel/Process.h>
|
#include <Kernel/Process.h>
|
||||||
#include <Kernel/Scheduler.h>
|
#include <Kernel/Scheduler.h>
|
||||||
|
#include <Kernel/KSyms.h>
|
||||||
#include <AK/Assertions.h>
|
#include <AK/Assertions.h>
|
||||||
|
|
||||||
#define SANITIZE_KMALLOC
|
#define SANITIZE_KMALLOC
|
||||||
|
@ -35,6 +36,7 @@ volatile size_t kmalloc_sum_eternal = 0;
|
||||||
|
|
||||||
dword g_kmalloc_call_count;
|
dword g_kmalloc_call_count;
|
||||||
dword g_kfree_call_count;
|
dword g_kfree_call_count;
|
||||||
|
bool g_dump_kmalloc_stacks;
|
||||||
|
|
||||||
static byte* s_next_eternal_ptr;
|
static byte* s_next_eternal_ptr;
|
||||||
static byte* s_end_of_eternal_range;
|
static byte* s_end_of_eternal_range;
|
||||||
|
@ -95,6 +97,11 @@ void* kmalloc_impl(size_t size)
|
||||||
InterruptDisabler disabler;
|
InterruptDisabler disabler;
|
||||||
++g_kmalloc_call_count;
|
++g_kmalloc_call_count;
|
||||||
|
|
||||||
|
if (g_dump_kmalloc_stacks && ksyms_ready) {
|
||||||
|
dbgprintf("kmalloc(%u)\n", size);
|
||||||
|
dump_backtrace(true);
|
||||||
|
}
|
||||||
|
|
||||||
// We need space for the allocation_t structure at the head of the block.
|
// We need space for the allocation_t structure at the head of the block.
|
||||||
size_t real_size = size + sizeof(allocation_t);
|
size_t real_size = size + sizeof(allocation_t);
|
||||||
|
|
||||||
|
|
|
@ -20,6 +20,7 @@ extern volatile size_t kmalloc_sum_eternal;
|
||||||
extern volatile size_t kmalloc_sum_page_aligned;
|
extern volatile size_t kmalloc_sum_page_aligned;
|
||||||
extern dword g_kmalloc_call_count;
|
extern dword g_kmalloc_call_count;
|
||||||
extern dword g_kfree_call_count;
|
extern dword g_kfree_call_count;
|
||||||
|
extern bool g_dump_kmalloc_stacks;
|
||||||
|
|
||||||
inline void* operator new(size_t, void* p) { return p; }
|
inline void* operator new(size_t, void* p) { return p; }
|
||||||
inline void* operator new[](size_t, void* p) { return p; }
|
inline void* operator new[](size_t, void* p) { return p; }
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue