OnDemand paging for heap
This commit is contained in:
parent
535290cf40
commit
edcac85b35
@ -4,7 +4,10 @@
|
|||||||
#include "interrupt.h"
|
#include "interrupt.h"
|
||||||
#include "irq.h"
|
#include "irq.h"
|
||||||
#include "klibc.h"
|
#include "klibc.h"
|
||||||
|
#include "process.h"
|
||||||
#include "thread.h"
|
#include "thread.h"
|
||||||
|
#include "types.h"
|
||||||
|
#include "uaddrspace.h"
|
||||||
#include "vga.h"
|
#include "vga.h"
|
||||||
|
|
||||||
exception_handler exception_handler_array[EXCEPTION_NUM] = {
|
exception_handler exception_handler_array[EXCEPTION_NUM] = {
|
||||||
@ -53,8 +56,15 @@ void pagefault_handler(struct cpu_state *frame, ulong intr)
|
|||||||
{
|
{
|
||||||
|
|
||||||
struct thread *current = getCurrentThread();
|
struct thread *current = getCurrentThread();
|
||||||
printf("page fault while in thread %s code at 0x%x when trying to access 0x%x err_code 0x%x\n", current->name,
|
struct uAddrSpace *as = processGetAddrSpace(current->process);
|
||||||
cpu_context_get_PC(frame), cpu_context_get_EX_faulting_vaddr(frame), cpu_context_get_EX_err(frame));
|
vaddr_t faultAddr = cpu_context_get_EX_faulting_vaddr(frame);
|
||||||
|
|
||||||
|
if(!uAddrSpaceCheckNAlloc(as, faultAddr))
|
||||||
|
return;
|
||||||
|
|
||||||
|
|
||||||
|
printf("page fault while in thread [%s] at 0x%x when trying to access 0x%x err_code 0x%x\n", current->name,
|
||||||
|
cpu_context_get_PC(frame), faultAddr, cpu_context_get_EX_err(frame));
|
||||||
if (cpu_context_is_in_user_mode(frame)) {
|
if (cpu_context_is_in_user_mode(frame)) {
|
||||||
printf("Killing User Thread\n");
|
printf("Killing User Thread\n");
|
||||||
threadExit();
|
threadExit();
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
#include "uaddrspace.h"
|
#include "uaddrspace.h"
|
||||||
#include "alloc.h"
|
#include "alloc.h"
|
||||||
#include "kernel.h"
|
#include "kernel.h"
|
||||||
|
#include "klibc.h"
|
||||||
#include "mem.h"
|
#include "mem.h"
|
||||||
#include "mmuContext.h"
|
#include "mmuContext.h"
|
||||||
#include "process.h"
|
#include "process.h"
|
||||||
@ -105,15 +106,26 @@ uaddr_t sysBrk(struct uAddrSpace *as, uaddr_t newHeapTop)
|
|||||||
return as->heapStart + as->heapSize;
|
return as->heapStart + as->heapSize;
|
||||||
}
|
}
|
||||||
|
|
||||||
//WIP do it manually
|
as->heapSize += incSize;
|
||||||
for (uaddr_t begin = ALIGN(as->heapStart + as->heapSize, PAGE_SIZE); begin < newHeapTop; begin += PAGE_SIZE) {
|
|
||||||
paddr_t ppage = allocPhyPage(1);
|
return 0;
|
||||||
if (0 != pageMap(begin, ppage,
|
}
|
||||||
PAGING_MEM_USER | PAGING_MEM_WRITE | PAGING_MEM_READ))
|
|
||||||
return (uaddr_t)NULL;
|
int uAddrSpaceCheckNAlloc(struct uAddrSpace *as, vaddr_t addr)
|
||||||
|
{
|
||||||
unrefPhyPage(ppage);
|
pr_devel("Checking %p inside %p and %p", addr, as->heapStart, as->heapStart +as->heapSize);
|
||||||
}
|
if (addr < as->heapStart || addr >= as->heapStart + as->heapSize) {
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
vaddr_t addrAlign = ALIGN_DOWN(addr, PAGE_SIZE);
|
||||||
|
paddr_t ppage = allocPhyPage(1);
|
||||||
|
|
||||||
|
if (0 != pageMap(addrAlign, ppage, PAGING_MEM_USER | PAGING_MEM_WRITE | PAGING_MEM_READ)) {
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
unrefPhyPage(ppage);
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
@ -11,4 +11,5 @@ struct uAddrSpace * uAddrSpaceCreate(struct process *proc);
|
|||||||
int uAddrSpaceDelete(struct uAddrSpace *addr);
|
int uAddrSpaceDelete(struct uAddrSpace *addr);
|
||||||
struct mmu_context * uAddrSpaceGetMMUContext(struct uAddrSpace *addr);
|
struct mmu_context * uAddrSpaceGetMMUContext(struct uAddrSpace *addr);
|
||||||
int uAddrSpaceSetHeap(struct uAddrSpace *as, uaddr_t addr, size_t size);
|
int uAddrSpaceSetHeap(struct uAddrSpace *as, uaddr_t addr, size_t size);
|
||||||
|
int uAddrSpaceCheckNAlloc(struct uAddrSpace *as, vaddr_t addr);
|
||||||
uaddr_t sysBrk(struct uAddrSpace *as, uaddr_t newHeapTop);
|
uaddr_t sysBrk(struct uAddrSpace *as, uaddr_t newHeapTop);
|
||||||
|
Loading…
Reference in New Issue
Block a user