summaryrefslogtreecommitdiffstats
path: root/userprog
diff options
context:
space:
mode:
authormanuel <manuel@mausz.at>2012-06-21 18:14:58 +0200
committermanuel <manuel@mausz.at>2012-06-21 18:14:58 +0200
commite61e868b265efe2f6d51079373588d639fc54d59 (patch)
tree035fa9afef57c88ed156909d73cd8c4a91fe4435 /userprog
parente11b2ef0c606ab516a4344aeea1dbba22cb1fe5d (diff)
downloadprogos-e61e868b265efe2f6d51079373588d639fc54d59.tar.gz
progos-e61e868b265efe2f6d51079373588d639fc54d59.tar.bz2
progos-e61e868b265efe2f6d51079373588d639fc54d59.zip
full mmap implementation
Diffstat (limited to 'userprog')
-rw-r--r--userprog/process.c6
-rw-r--r--userprog/syscall.c11
2 files changed, 10 insertions, 7 deletions
diff --git a/userprog/process.c b/userprog/process.c
index f399038..80e327d 100644
--- a/userprog/process.c
+++ b/userprog/process.c
@@ -151,13 +151,11 @@ start_process (void *aux)
151 /* If process startup failed, quit. */ 151 /* If process startup failed, quit. */
152 if (thread->process == NULL) { 152 if (thread->process == NULL) {
153 if (process != NULL) { 153 if (process != NULL) {
154 //TODO: free mmap table + page table?
155
156 /* close/free memory mapped files */ 154 /* close/free memory mapped files */
157 //mmap_table_free (&process->mmap_table); 155 mmap_table_free (&process->mmap_table);
158 156
159 /* free page table */ 157 /* free page table */
160 //page_table_free (&thread->page_table); 158 page_table_free (&thread->page_table);
161 159
162 if (process->fd_table.fds != NULL) 160 if (process->fd_table.fds != NULL)
163 palloc_free_page (process->fd_table.fds); 161 palloc_free_page (process->fd_table.fds);
diff --git a/userprog/syscall.c b/userprog/syscall.c
index 14cbaab..9da3044 100644
--- a/userprog/syscall.c
+++ b/userprog/syscall.c
@@ -576,9 +576,10 @@ static int
576syscall_mmap (void *sp, bool *segfault) 576syscall_mmap (void *sp, bool *segfault)
577{ 577{
578 int fd; 578 int fd;
579 void *addr, *offset; 579 uint8_t *addr, *offset;
580 struct file *file, *file2; 580 struct file *file, *file2;
581 off_t len; 581 off_t len;
582 struct thread *thread = thread_current ();
582 583
583 /* get arguments */ 584 /* get arguments */
584 if (! copy_from_user (&fd, STACK_ADDR (sp,1)) || 585 if (! copy_from_user (&fd, STACK_ADDR (sp,1)) ||
@@ -605,11 +606,15 @@ syscall_mmap (void *sp, bool *segfault)
605 if (len <= 0) 606 if (len <= 0)
606 return -1; 607 return -1;
607 608
608 /* check if the pages don't overlap any existing pages */ 609 /* check if the pages don't overlap any existing pages AND mapped pages */
609 offset = addr; 610 offset = addr;
610 while(offset < addr + len) 611 while(offset < addr + len)
611 { 612 {
612 if (page_table_fetch (&thread_current ()->page_table, offset)) 613 /* check for pages either loaded or not */
614 if (page_table_fetch (&thread->page_table, offset))
615 return -1;
616 /* check for already loaded pages not in page table (e.g. stack) */
617 if (pagedir_get_page (thread->pagedir, offset))
613 return -1; 618 return -1;
614 offset += PGSIZE; 619 offset += PGSIZE;
615 } 620 }