From 60faf995ea664d9d76bb8c919564f5383642271d Mon Sep 17 00:00:00 2001 From: Themis Demetriades Date: Wed, 4 Dec 2024 22:21:31 +0000 Subject: [PATCH] fix: lazy load executable files of user processes even when accessed in a kernel context --- src/userprog/exception.c | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-) diff --git a/src/userprog/exception.c b/src/userprog/exception.c index 4e104d5..39a8173 100644 --- a/src/userprog/exception.c +++ b/src/userprog/exception.c @@ -158,6 +158,16 @@ page_fault (struct intr_frame *f) #ifdef VM struct thread *t = thread_current (); void *upage = pg_round_down (fault_addr); + + /* If the fault address is in a user page that is not present, then it might + be an executable file page that needs to be lazily loaded. So, we check the + SPT to determine if this is the case, and if so load the page from disk. */ + if (not_present && is_user_vaddr (upage)) + { + if (try_fetch_page (upage, write)) + return; + } + if (user) { if (not_present) @@ -193,15 +203,6 @@ page_fault (struct intr_frame *f) f->eax = 0xffffffff; return; } - - /* If the fault address is in a user page that is not present, then it might - just need to be lazily loaded. So, we check our SPT to see if the page - is expected to have data loaded in memory. */ - if (not_present && is_user_vaddr (upage) && upage != NULL) - { - if (try_fetch_page (upage, write)) - return; - } #endif /* To implement virtual memory, delete the rest of the function