From 22f3b0950f37a72427c474770d15eba28a2b0bea Mon Sep 17 00:00:00 2001 From: sBubshait Date: Fri, 6 Dec 2024 15:54:46 +0000 Subject: [PATCH] Fix: Insert pages in mmap as PAGE_MMAP instead of PAGE_FILE --- src/userprog/syscall.c | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/src/userprog/syscall.c b/src/userprog/syscall.c index 8275d51..20e66fc 100644 --- a/src/userprog/syscall.c +++ b/src/userprog/syscall.c @@ -461,10 +461,9 @@ syscall_mmap (int fd, void *addr) /* Check and ensure that there is enough space in the user virtual memory to hold the entire file. */ for (off_t ofs = 0; ofs < file_size; ofs += PGSIZE) - { if (page_get (thread_current (), addr + ofs) != NULL) return MMAP_FAILURE; - } + /* Map the file data into the user virtual memory starting from addr. */ for (off_t ofs = 0; ofs < file_size; ofs += PGSIZE) @@ -473,7 +472,7 @@ syscall_mmap (int fd, void *addr) off_t zero_bytes = PGSIZE - read_bytes; if (page_insert_file (file, ofs, addr + ofs, read_bytes, zero_bytes, true, - PAGE_FILE) == NULL) + PAGE_MMAP) == NULL) return MMAP_FAILURE; } @@ -482,7 +481,6 @@ syscall_mmap (int fd, void *addr) if (mmap == NULL) return MMAP_FAILURE; - return mmap->mapping; }