FORKgit add .git add .!

This commit is contained in:
2026-07-08 19:11:39 -05:00
parent e42ee8eb85
commit ec3cbb4794
10 changed files with 146 additions and 105 deletions

View File

@@ -2,6 +2,8 @@
#include <lib/print.h>
#include <memory/mm.h>
#include "kbd.h"
#include "syscall.h"
#include "common.h"
@@ -11,6 +13,7 @@
#include <drivers/pic/pic.h>
#include <drivers/ps2/ps2.h>
#include <lib/memory.h>
#define IDT_MAX_DESCRIPTORS 256
#define ATTR_KERN_32 0x8E // active(1), ring 0 (00), interrupt gate(0), 32 bit (1110)
@@ -135,10 +138,34 @@ void common_interrupt_handler(intr_regs_t *args) {
break;
}
case 14:{
disable_interrupts();
uint32_t faulting_address;
process_t* task = current_task();
asm volatile("mov %%cr2, %0" : "=r"(faulting_address));
if (is_cow(faulting_address)) {
uint32_t pde_entry = faulting_address >> 22;
uint32_t pte_entry = (faulting_address >> 12) & 0x3FF;
uint32_t* tablev = (uint32_t*)(CUR_PAGE_TABLES + (pde_entry * PAGE_SIZE));
uint32_t p_dst = (uint32_t)p_alloc_frame();
uint32_t p_src = (uint32_t)tablev[pte_entry] & 0xFFFFF000;
map_page(TEMP_PT_SRC, p_src, PAGE_WRITABLE | PAGE_PRESENT);
map_page(TEMP_PT_DST, p_dst, PAGE_WRITABLE | PAGE_PRESENT);
memcpy((void*)TEMP_PT_SRC, (void*)TEMP_PT_DST, PAGE_SIZE);
unmap_page(TEMP_PT_SRC);
unmap_page(TEMP_PT_DST);
uint32_t flags = tablev[pte_entry] & 0xFFF;
flags &= ~PAGE_COW;
tablev[pte_entry] = p_dst | flags | PAGE_WRITABLE;
flush_tlb();
break;
}
process_t* task = current_task();
kprintf("\n--- PAGE FAULT ---\n");
kprintf("Current Task PID: %d\n", task->pid);
kprintf("Faulted Virtual Address: 0x%x\n", faulting_address);