1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-05-31 11:48:10 +00:00

Add a very hackish /proc/PID/stack.

It walks the stack and identifies anything that looks like a kernel symbol.
This could be a lot more sophisticated.
This commit is contained in:
Andreas Kling 2018-10-26 22:32:35 +02:00
parent 81627cf7d5
commit c928b06218
14 changed files with 130 additions and 13 deletions

View file

@ -28,6 +28,7 @@
#include "RTC.h"
#define TEST_VFS
#define KERNEL_MAP
//#define STRESS_TEST_SPAWNING
//#define TEST_ELF_LOADER
//#define TEST_CRASHY_USER_PROCESSES
@ -49,6 +50,43 @@ void banner()
kprintf("\n");
}
static byte parseHexDigit(char nibble)
{
if (nibble >= '0' && nibble <= '9')
return nibble - '0';
ASSERT(nibble >= 'a' && nibble <= 'f');
return 10 + (nibble - 'a');
}
static Vector<KSym>* s_ksyms;
Vector<KSym>& ksyms()
{
return *s_ksyms;
}
static void loadKernelMap(const ByteBuffer& buffer)
{
s_ksyms = new Vector<KSym>;
auto* bufptr = (const char*)buffer.pointer();
auto* startOfName = bufptr;
dword address = 0;
while (bufptr < buffer.endPointer()) {
for (unsigned i = 0; i < 8; ++i)
address = (address << 4) | parseHexDigit(*(bufptr++));
bufptr += 3;
startOfName = bufptr;
while (*(++bufptr)) {
if (*bufptr == '\n') {
break;
}
}
ksyms().append({ address, String(startOfName, bufptr - startOfName) });
++bufptr;
}
}
#ifdef TEST_CRASHY_USER_PROCESSES
static void user_main() NORETURN;
static void user_main()
@ -108,6 +146,19 @@ static void init_stage2()
vfs->mountRoot(e2fs.copyRef());
#ifdef KERNEL_MAP
{
auto handle = vfs->open("/kernel.map");
if (!handle) {
kprintf("Failed to open /kernel.map\n");
} else {
auto buffer = handle->readEntireFile();
ASSERT(buffer);
loadKernelMap(buffer);
}
}
#endif
vfs->mount(ProcFileSystem::the(), "/proc");
#endif