Commit 97fe004e authored by An N Tran's avatar An N Tran :speech_balloon:
Browse files

Task 3

parent 85e72c3e
No related merge requests found
Pipeline #73455 failed with stage
in 14 seconds
Showing with 10 additions and 14 deletions
+10 -14
......@@ -157,17 +157,16 @@ void process_setup(pid_t pid, const char* program_name) {
for (uintptr_t a = round_down(seg.va(), PAGESIZE);
a < seg.va() + seg.size();
a += PAGESIZE) {
// (NB this is physical page allocation!)
assert(!pages[a / PAGESIZE].used());
++pages[a / PAGESIZE].refcount;
map_to_user_space(process_pagetable, a);
uintptr_t pa = (uintptr_t) kalloc(PAGESIZE);
memory_map(process_pagetable, a, pa, PTE_PWU);
}
}
// initialize data in loadable segments
for (auto seg = pgm.begin(); seg != pgm.end(); ++seg) {
memset((void*) seg.va(), 0, seg.size());
memcpy((void*) seg.va(), seg.data(), seg.data_size());
void *pa = memory_virtual_to_physical(process_pagetable, seg.va());
memset(pa, 0, seg.size());
memcpy(pa, seg.data(), seg.data_size());
}
// mark entry point
......@@ -175,10 +174,8 @@ void process_setup(pid_t pid, const char* program_name) {
// allocate and map stack segment
uintptr_t stack_addr = PROC_START_ADDR + PROC_SIZE * pid - PAGESIZE;
// (NB this is physical page allocation!)
assert(!pages[stack_addr / PAGESIZE].used());
++pages[stack_addr / PAGESIZE].refcount;
map_to_user_space(process_pagetable, stack_addr);
uintptr_t pa = (uintptr_t) kalloc(PAGESIZE);
memory_map(process_pagetable, stack_addr, pa, PTE_PWU);
ptable[pid].regs.reg_rsp = stack_addr + PAGESIZE;
// mark process as runnable
......@@ -327,10 +324,9 @@ uintptr_t syscall(regstate* regs) {
// in `u-lib.hh` (but in the handout code, it does not).
int syscall_page_alloc(uintptr_t addr) {
assert(!pages[addr / PAGESIZE].used());
pages[addr / PAGESIZE].refcount = 1;
memset((void*) addr, 0, PAGESIZE);
map_to_user_space(current->pagetable, addr);
uintptr_t pa = (uintptr_t) kalloc(PAGESIZE);
memory_map(current->pagetable, addr, pa, PTE_PWU);
memset(memory_virtual_to_physical(current->pagetable, addr), 0, PAGESIZE);
return 0;
}
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment