From e61e868b265efe2f6d51079373588d639fc54d59 Mon Sep 17 00:00:00 2001 From: manuel Date: Thu, 21 Jun 2012 18:14:58 +0200 Subject: full mmap implementation --- userprog/syscall.c | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) (limited to 'userprog/syscall.c') 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 syscall_mmap (void *sp, bool *segfault) { int fd; - void *addr, *offset; + uint8_t *addr, *offset; struct file *file, *file2; off_t len; + struct thread *thread = thread_current (); /* get arguments */ if (! copy_from_user (&fd, STACK_ADDR (sp,1)) || @@ -605,11 +606,15 @@ syscall_mmap (void *sp, bool *segfault) if (len <= 0) return -1; - /* check if the pages don't overlap any existing pages */ + /* check if the pages don't overlap any existing pages AND mapped pages */ offset = addr; while(offset < addr + len) { - if (page_table_fetch (&thread_current ()->page_table, offset)) + /* check for pages either loaded or not */ + if (page_table_fetch (&thread->page_table, offset)) + return -1; + /* check for already loaded pages not in page table (e.g. stack) */ + if (pagedir_get_page (thread->pagedir, offset)) return -1; offset += PGSIZE; } -- cgit v1.2.3