diff options
| author | manuel <manuel@mausz.at> | 2012-06-21 18:14:58 +0200 |
|---|---|---|
| committer | manuel <manuel@mausz.at> | 2012-06-21 18:14:58 +0200 |
| commit | e61e868b265efe2f6d51079373588d639fc54d59 (patch) | |
| tree | 035fa9afef57c88ed156909d73cd8c4a91fe4435 /userprog/syscall.c | |
| parent | e11b2ef0c606ab516a4344aeea1dbba22cb1fe5d (diff) | |
| download | progos-e61e868b265efe2f6d51079373588d639fc54d59.tar.gz progos-e61e868b265efe2f6d51079373588d639fc54d59.tar.bz2 progos-e61e868b265efe2f6d51079373588d639fc54d59.zip | |
full mmap implementation
Diffstat (limited to 'userprog/syscall.c')
| -rw-r--r-- | userprog/syscall.c | 11 |
1 files changed, 8 insertions, 3 deletions
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 | |||
| 576 | syscall_mmap (void *sp, bool *segfault) | 576 | syscall_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 | } |
