refactor: supplemental page table helper functions follow code style

This commit is contained in:
Themis Demetriades
2024-12-01 23:30:50 +00:00
parent 8e278b349a
commit bb16abdc0d

View File

@@ -12,17 +12,16 @@ void
page_set_swap (struct thread *owner, void *upage, size_t swap_slot)
{
uint32_t *pte = lookup_page (owner->pagedir, upage, false);
*pte &= ~PTE_P; //clears the first bit (present bit) to be 0
//ASSERT (swap_slot < (1 << 20)); //not sure if this is needed
//shifts the swap slot addr to take up bits 31 to 12
//uses bitwise & to make sure it does not affect flags
//then applies it to pte
*pte |= (1 << SWAP_FLAG_BIT); // sets the 9th bit
/* Store the provided swap slot in the address bits of the page table
entry, truncating excess bits. */
*pte |= (1 << SWAP_FLAG_BIT);
uint32_t swap_slot_bits = (swap_slot << ADDR_START_BIT) & PTE_ADDR;
*pte = (*pte & PTE_FLAGS) | swap_slot_bits;
/* Mark page as 'not present' and flag the page directory as having
been modified. */
pagedir_clear_page (owner->pagedir, upage);
}
/* Given that the page with user address 'upage' owned by 'owner' is flagged
@@ -33,11 +32,10 @@ page_get_swap (struct thread *owner, void *upage)
{
uint32_t *pte = lookup_page (owner->pagedir, upage, false);
//these should always be checked and true before using this func
ASSERT ((*pte & PTE_P) == 0);
ASSERT ((*pte & (1 << 9)) == 1);
ASSERT ((*pte & (1 << SWAP_FLAG_BIT)) != 0);
//masks address bits and returns truncated value
return ((*pte & PTE_ADDR) >> 12);
/* Masks the address bits and returns truncated value. */
return ((*pte & PTE_ADDR) >> ADDR_START_BIT);
}