<commit_before>#include <X86/Idt.hh>
#include <X86/Processor.hh>
#include <X86/ThreadContext.hh>

#include <Memory.hh>
#include <Interrupt.hh>
#include <Power.hh>
#include <Debug.hh>
#include <StackTrace.hh>
#include <Kernel/Scheduler.hh>
#include <Kernel/Thread.hh>
#include <Kernel/Process.hh>
#include <Kernel/ProcessContext.hh>

using namespace Kernel;

extern IdtPointer idtPointer;

// Idt descriptors
static IdtEntry idtEntries[NUMIDT];
IdtPointer idtPointer;

extern "C" InterruptFrame* x86_isr_dispatcher(InterruptFrame* frame);
extern "C" void x86_isr_init(int n, void (*handler)());

#include "InterruptVectorsInit.icc"

// XXX this should be refactored to be MI
//
static void
x86_isr_page_fault(InterruptFrame* frame)
{
   static int nestingFlag;

   // protect the kernel from trying to handle nested page faults
   //
   if (nestingFlag > 0)
   {
      Debug::panic("Nested page fault");
      Power::reboot();
   }

   nestingFlag++;

   uint32_t cr2 = get_cr2();

   if ((frame->error & 0x1) == 0 && Memory::handlePageFault(cr2, frame))
   {
#ifdef DEBUG
      printf("Page fault handled: %p\n", (void* )cr2);
#endif
      nestingFlag--;
      return;
   }

   printf("\n");
   frame->print();

   printf("\nPage fault: %s\n", (frame->error & (1 << 0)) ? "protection violation" : "page not present");
   printf("%s 0x%x from 0x%x in %s mode\nError Code: 0x%x\n",
	  (frame->error & (1 << 1)) ? "Writing" : "Reading",
	  cr2, frame->eip,
	  (frame->error & (1 << 2)) ? "user" : "supervisor",
	  frame->error);

   StackTrace::printStackTrace(reinterpret_cast<void*>(frame->ebp));

   x86_cli();
   Power::halt();
}

static void
x86_isr_general_protection_fault(InterruptFrame* frame)
{
   printf("\n");
   frame->print();
<commit_msg>User processes should be killed on UH PF.<commit_after>#include <X86/Idt.hh>
#include <X86/Processor.hh>
#include <X86/ThreadContext.hh>

#include <Memory.hh>
#include <Interrupt.hh>
#include <Power.hh>
#include <Debug.hh>
#include <StackTrace.hh>
#include <Kernel/Scheduler.hh>
#include <Kernel/Thread.hh>
#include <Kernel/Process.hh>
#include <Kernel/ProcessContext.hh>

using namespace Kernel;

extern IdtPointer idtPointer;

// Idt descriptors
static IdtEntry idtEntries[NUMIDT];
IdtPointer idtPointer;

extern "C" InterruptFrame* x86_isr_dispatcher(InterruptFrame* frame);
extern "C" void x86_isr_init(int n, void (*handler)());

#include "InterruptVectorsInit.icc"

// XXX this should be refactored to be MI
//
static void
x86_isr_page_fault(InterruptFrame* frame)
{
   static int nestingFlag;

   // protect the kernel from trying to handle nested page faults
   //
   if (nestingFlag > 0)
   {
      Debug::panic("Nested page fault");
      Power::reboot();
   }

   nestingFlag++;

   uint32_t cr2 = get_cr2();

   if ((frame->error & 0x1) == 0 && Memory::handlePageFault(cr2, frame))
   {
#ifdef DEBUG
      printf("Page fault handled: %p\n", (void* )cr2);
#endif
      nestingFlag--;
      return;
   }

   bool isUser = frame->error & (1 << 2);
   if (isUser)
   {
      // XXX Kill process/thread here
//      nestingFlag--;
//      return;
   }

   printf("\n");
   frame->print();

   printf("\nPage fault: %s\n", (frame->error & (1 << 0)) ? "protection violation" : "page not present");
   printf("%s 0x%x from 0x%x in %s mode\nError Code: 0x%x\n",
	  (frame->error & (1 << 1)) ? "Writing" : "Reading",
	  cr2, frame->eip,
	  (frame->error & (1 << 2)) ? "user" : "supervisor",
	  frame->error);

   StackTrace::printStackTrace(reinterpret_cast<void*>(frame->ebp));

   x86_cli();
   Power::halt();
}

static void
x86_isr_general_protection_fault(InterruptFrame* frame)
{
   printf("\n");
   frame->print();

{'fraction_non_alphanumeric': 0.16199292131772394, 'fraction_numerical': 0.020147018785733734, 'mean_word_length': 3.866225165562914, 'pattern_counts': {'":': 0, '<': 43, '<?xml version=': 0, '>': 50, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7429525', 'n_tokens_mistral': 1387, 'n_tokens_neox': 1295, 'n_words': 316}