|
|
|
|
@@ -133,7 +133,8 @@ page_insert_file (struct file *file, off_t ofs, void *upage,
|
|
|
|
|
enum page_type type)
|
|
|
|
|
{
|
|
|
|
|
/* If page exists, just update it. */
|
|
|
|
|
struct page_entry *existing = page_get (thread_current (), upage);
|
|
|
|
|
struct thread *t = thread_current ();
|
|
|
|
|
struct page_entry *existing = page_get (t, upage);
|
|
|
|
|
if (existing != NULL)
|
|
|
|
|
{
|
|
|
|
|
ASSERT (existing->read_bytes == read_bytes);
|
|
|
|
|
@@ -141,7 +142,7 @@ page_insert_file (struct file *file, off_t ofs, void *upage,
|
|
|
|
|
existing->writable = existing->writable || writable;
|
|
|
|
|
return existing;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
struct page_entry *page = malloc(sizeof (struct page_entry));
|
|
|
|
|
if (page == NULL)
|
|
|
|
|
return NULL;
|
|
|
|
|
@@ -164,11 +165,13 @@ page_insert_file (struct file *file, off_t ofs, void *upage,
|
|
|
|
|
struct page_entry *
|
|
|
|
|
page_get (struct thread *thread, void *upage)
|
|
|
|
|
{
|
|
|
|
|
lock_acquire (&thread->spt_lock);
|
|
|
|
|
struct page_entry fake_page_entry;
|
|
|
|
|
fake_page_entry.upage = upage;
|
|
|
|
|
|
|
|
|
|
struct hash_elem *e
|
|
|
|
|
= hash_find (&thread->pages, &fake_page_entry.elem);
|
|
|
|
|
lock_release (&thread->spt_lock);
|
|
|
|
|
if (e == NULL)
|
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
|
|
@@ -290,6 +293,7 @@ page_load_file (struct page_entry *page)
|
|
|
|
|
void
|
|
|
|
|
page_cleanup (struct hash_elem *e, void *aux UNUSED)
|
|
|
|
|
{
|
|
|
|
|
lock_acquire (&thread_current ()->spt_lock);
|
|
|
|
|
struct page_entry *page = hash_entry (e, struct page_entry, elem);
|
|
|
|
|
if (page->type == PAGE_SHARED)
|
|
|
|
|
{
|
|
|
|
|
@@ -312,6 +316,7 @@ page_cleanup (struct hash_elem *e, void *aux UNUSED)
|
|
|
|
|
lock_release (&shared_file_pages_lock);
|
|
|
|
|
}
|
|
|
|
|
free (page);
|
|
|
|
|
lock_release (&thread_current ()->spt_lock);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* Flags the provided page table entry as representing a swapped out page. */
|
|
|
|
|
@@ -343,7 +348,9 @@ page_set_swap (struct thread *owner, uint32_t *pte, size_t swap_slot)
|
|
|
|
|
bool
|
|
|
|
|
page_in_swap (struct thread *owner, void *upage)
|
|
|
|
|
{
|
|
|
|
|
lock_acquire (&owner->spt_lock);
|
|
|
|
|
uint32_t *pte = lookup_page (owner->pagedir, upage, false);
|
|
|
|
|
lock_release (&owner->spt_lock);
|
|
|
|
|
return page_in_swap_pte (pte);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@@ -360,6 +367,7 @@ page_in_swap_pte (uint32_t *pte)
|
|
|
|
|
size_t
|
|
|
|
|
page_get_swap (struct thread *owner, void *upage)
|
|
|
|
|
{
|
|
|
|
|
lock_acquire (&owner->spt_lock);
|
|
|
|
|
uint32_t *pte = lookup_page (owner->pagedir, upage, false);
|
|
|
|
|
|
|
|
|
|
ASSERT (pte != NULL);
|
|
|
|
|
@@ -367,6 +375,7 @@ page_get_swap (struct thread *owner, void *upage)
|
|
|
|
|
|
|
|
|
|
/* Masks the address bits and returns truncated value. */
|
|
|
|
|
page_flag_swap (pte, false);
|
|
|
|
|
lock_release (&owner->spt_lock);
|
|
|
|
|
return ((*pte & PTE_ADDR) >> ADDR_START_BIT);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|