refactor: extract init_pages
This commit is contained in:
@@ -14,10 +14,22 @@
|
||||
#define SWAP_FLAG_BIT 9
|
||||
#define ADDR_START_BIT 12
|
||||
|
||||
static unsigned page_hash (const struct hash_elem *e, void *aux UNUSED);
|
||||
static bool page_less (const struct hash_elem *a_, const struct hash_elem *b_,
|
||||
void *aux UNUSED);
|
||||
|
||||
/* Initialise a supplementary page table. */
|
||||
bool
|
||||
init_pages (struct hash *pages)
|
||||
{
|
||||
ASSERT (pages != NULL);
|
||||
return hash_init (pages, page_hash, page_less, NULL);
|
||||
}
|
||||
|
||||
/* Hashing function needed for the SPT table. Returns a hash for an entry,
|
||||
based on its upage. */
|
||||
unsigned
|
||||
page_hash (const struct hash_elem *e, UNUSED void *aux)
|
||||
static unsigned
|
||||
page_hash (const struct hash_elem *e, void *aux UNUSED)
|
||||
{
|
||||
struct page_entry *page = hash_entry (e, struct page_entry, elem);
|
||||
return hash_ptr (page->upage);
|
||||
@@ -25,7 +37,7 @@ page_hash (const struct hash_elem *e, UNUSED void *aux)
|
||||
|
||||
/* Comparator function for the SPT table. Compares two entries based on their
|
||||
upages. */
|
||||
bool
|
||||
static bool
|
||||
page_less (const struct hash_elem *a_, const struct hash_elem *b_,
|
||||
void *aux UNUSED)
|
||||
{
|
||||
@@ -116,7 +128,7 @@ page_get (void *upage)
|
||||
}
|
||||
|
||||
bool
|
||||
page_load_file (struct page_entry *page, bool writable)
|
||||
page_load_file (struct page_entry *page)
|
||||
{
|
||||
/* Allocate a frame for the page. If a frame allocation fails, then
|
||||
frame_alloc should try to evict a page. If it is still NULL, the OS
|
||||
@@ -128,7 +140,7 @@ page_load_file (struct page_entry *page, bool writable)
|
||||
PANIC ("Could not allocate a frame to load page into memory.");
|
||||
|
||||
/* Map the page to the frame. */
|
||||
if (!install_page (page->upage, frame, writable))
|
||||
if (!install_page (page->upage, frame, page->writable))
|
||||
{
|
||||
frame_free (frame);
|
||||
return false;
|
||||
|
||||
Reference in New Issue
Block a user