Kernel: Figure out why a program is misbehaving
This commit is contained in:
parent
c6ce7a5358
commit
5d94525c7a
4
kernel/include/utils/PageFaultReason.h
Normal file
4
kernel/include/utils/PageFaultReason.h
Normal file
@ -0,0 +1,4 @@
|
||||
#pragma once
|
||||
#include <stdint.h>
|
||||
|
||||
void determine_user_page_fault_reason(uintptr_t faulting_address);
|
@ -5,6 +5,7 @@
|
||||
#include "interrupts/Interrupts.h"
|
||||
#include "io/Serial.h"
|
||||
#include "log/Log.h"
|
||||
#include "memory/VMM.h"
|
||||
#include "misc/hang.h"
|
||||
#include "panic/Panic.h"
|
||||
#include "std/assert.h"
|
||||
@ -12,6 +13,7 @@
|
||||
#include "sys/Syscall.h"
|
||||
#include "thread/Scheduler.h"
|
||||
#include "trace/StackTracer.h"
|
||||
#include "utils/PageFaultReason.h"
|
||||
|
||||
extern "C" void common_handler(Context* context)
|
||||
{
|
||||
@ -28,6 +30,8 @@ extern "C" void common_handler(Context* context)
|
||||
if (context->cs == 0x8) { int_panic(context, "GPF in kernel task"); }
|
||||
else
|
||||
{
|
||||
VMM::enter_syscall_context();
|
||||
|
||||
kerrorln("General protection fault at RIP %lx, cs %ld, ss %ld, RSP %lx, error code %ld", context->rip,
|
||||
context->cs, context->ss, context->rsp, context->error_code);
|
||||
kinfoln("Stack trace:");
|
||||
@ -44,6 +48,8 @@ extern "C" void common_handler(Context* context)
|
||||
if (context->cs == 0x8) { int_panic(context, "Page fault in kernel task"); }
|
||||
else
|
||||
{
|
||||
VMM::enter_syscall_context();
|
||||
|
||||
kerrorln("Page fault in ring 3 (RIP %lx), while trying to access %lx, error code %ld", context->rip,
|
||||
context->cr2, context->error_code);
|
||||
kinfoln("Stack trace:");
|
||||
@ -51,6 +57,8 @@ extern "C" void common_handler(Context* context)
|
||||
StackTracer tracer(context->rbp);
|
||||
tracer.trace_with_ip(context->rip);
|
||||
|
||||
determine_user_page_fault_reason(context->cr2);
|
||||
|
||||
Scheduler::task_misbehave(context, -3);
|
||||
}
|
||||
}
|
||||
|
20
kernel/src/utils/PageFaultReason.cpp
Normal file
20
kernel/src/utils/PageFaultReason.cpp
Normal file
@ -0,0 +1,20 @@
|
||||
#define MODULE "mem"
|
||||
|
||||
#include "utils/PageFaultReason.h"
|
||||
#include "log/Log.h"
|
||||
|
||||
#define PROGRAM_STACK_BOTTOM 0x100000
|
||||
|
||||
void determine_user_page_fault_reason(uintptr_t faulting_address)
|
||||
{
|
||||
if (faulting_address < 0x1000)
|
||||
{
|
||||
kinfoln("Address 0x%lx looks like a nullptr dereference", faulting_address);
|
||||
return;
|
||||
}
|
||||
if (faulting_address < PROGRAM_STACK_BOTTOM && (PROGRAM_STACK_BOTTOM - faulting_address) < 0x1000)
|
||||
{
|
||||
kinfoln("Address 0x%lx looks like a stack overflow", faulting_address);
|
||||
return;
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user