kern
diff src/vm.c @ 72:3941e82b07f2
- implemented syscalls: exit, waitpid, getppid
- moved sys_whatever functions out of syscall.c into more reasonable files
- putting all the definitions that must be synced with userland to include/kdef.h
author | John Tsiombikas <nuclear@member.fsf.org> |
---|---|
date | Sat, 15 Oct 2011 07:45:56 +0300 |
parents | 219974492c7d |
children | d3601789d638 |
line diff
1.1 --- a/src/vm.c Thu Oct 13 05:22:35 2011 +0300 1.2 +++ b/src/vm.c Sat Oct 15 07:45:56 2011 +0300 1.3 @@ -803,6 +803,28 @@ 1.4 pdest->ctx.pgtbl_paddr = paddr; 1.5 } 1.6 1.7 +/* cleanup_vm called by exit to clean up any memory used by the process */ 1.8 +void cleanup_vm(struct process *p) 1.9 +{ 1.10 + struct rbnode *vmnode; 1.11 + 1.12 + /* go through the vm map and reduce refcounts all around 1.13 + * when a ref goes to 0, free the physical page 1.14 + */ 1.15 + rb_begin(&p->vmmap); 1.16 + while((vmnode = rb_next(&p->vmmap))) { 1.17 + struct vm_page *page = vmnode->data; 1.18 + if(--page->nref <= 0) { 1.19 + /* free the physical page if nref goes to 0 */ 1.20 + free_phys_page(PAGE_TO_ADDR(page->ppage)); 1.21 + } 1.22 + } 1.23 + 1.24 + /* destroying the tree will free the nodes */ 1.25 + rb_destroy(&p->vmmap); 1.26 +} 1.27 + 1.28 + 1.29 int get_page_bit(int pgnum, uint32_t bit, int wholepath) 1.30 { 1.31 int tidx = PAGE_TO_PGTBL(pgnum);