Fix: Avoid closing the file after loading segments to be able to lazily load from file without opening, w/ G
This commit is contained in:
@@ -13,8 +13,7 @@ static long long page_fault_cnt;
|
||||
|
||||
static void kill (struct intr_frame *);
|
||||
static void page_fault (struct intr_frame *);
|
||||
static bool try_fetch_page (void *upage, bool not_present, bool write,
|
||||
bool user);
|
||||
static bool try_fetch_page (void *upage, bool write);
|
||||
|
||||
/* Registers handlers for interrupts that can be caused by user
|
||||
programs.
|
||||
@@ -150,9 +149,15 @@ page_fault (struct intr_frame *f)
|
||||
write = (f->error_code & PF_W) != 0;
|
||||
user = (f->error_code & PF_U) != 0;
|
||||
|
||||
/* 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. */
|
||||
void *upage = pg_round_down (fault_addr);
|
||||
if (try_fetch_page (upage, not_present, write, user))
|
||||
return;
|
||||
if (not_present && is_user_vaddr (upage) && upage != NULL)
|
||||
{
|
||||
if (try_fetch_page (upage, write))
|
||||
return;
|
||||
}
|
||||
|
||||
/* To implement virtual memory, delete the rest of the function
|
||||
body, and replace it with code that brings in the page to
|
||||
@@ -166,11 +171,10 @@ page_fault (struct intr_frame *f)
|
||||
}
|
||||
|
||||
static bool
|
||||
try_fetch_page (void *upage, bool not_present, bool write, bool user)
|
||||
try_fetch_page (void *upage, bool write)
|
||||
{
|
||||
if (!not_present || !is_user_vaddr (upage) || upage == NULL)
|
||||
return false;
|
||||
|
||||
/* Check if the page is in the supplemental page table. That is, it is a page
|
||||
that is expected to be in memory. */
|
||||
struct page_entry *page = page_get (upage);
|
||||
if (page == NULL)
|
||||
return false;
|
||||
@@ -182,6 +186,7 @@ try_fetch_page (void *upage, bool not_present, bool write, bool user)
|
||||
return true;
|
||||
}
|
||||
|
||||
/* Load the page into memory based on the type of data it is expecting. */
|
||||
switch (page->type) {
|
||||
case PAGE_EXECUTABLE:
|
||||
return page_load (page, write);
|
||||
|
||||
Reference in New Issue
Block a user