PKUOS - Pintos
Pintos source browser for PKU Operating System course
|
#include "userprog/pagedir.h"
#include <stdbool.h>
#include <stddef.h>
#include <string.h>
#include "threads/init.h"
#include "threads/pte.h"
#include "threads/palloc.h"
Go to the source code of this file.
Functions | |
static uint32_t * | active_pd (void) |
Returns the currently active page directory. More... | |
static void | invalidate_pagedir (uint32_t *pd) |
Seom page table changes can cause the CPU's translation lookaside buffer (TLB) to become out-of-sync with the page table. More... | |
uint32_t * | pagedir_create (void) |
Creates a new page directory that has mappings for kernel virtual addresses, but none for user virtual addresses. More... | |
void | pagedir_destroy (uint32_t *pd) |
Destroys page directory PD, freeing all the pages it references. More... | |
static uint32_t * | lookup_page (uint32_t *pd, const void *vaddr, bool create) |
Returns the address of the page table entry for virtual address VADDR in page directory PD. More... | |
bool | pagedir_set_page (uint32_t *pd, void *upage, void *kpage, bool writable) |
Adds a mapping in page directory PD from user virtual page UPAGE to the physical frame identified by kernel virtual address KPAGE. More... | |
void * | pagedir_get_page (uint32_t *pd, const void *uaddr) |
Looks up the physical address that corresponds to user virtual address UADDR in PD. More... | |
void | pagedir_clear_page (uint32_t *pd, void *upage) |
Marks user virtual page UPAGE "not present" in page directory PD. More... | |
bool | pagedir_is_dirty (uint32_t *pd, const void *vpage) |
Returns true if the PTE for virtual page VPAGE in PD is dirty, that is, if the page has been modified since the PTE was installed. More... | |
void | pagedir_set_dirty (uint32_t *pd, const void *vpage, bool dirty) |
Set the dirty bit to DIRTY in the PTE for virtual page VPAGE in PD. More... | |
bool | pagedir_is_accessed (uint32_t *pd, const void *vpage) |
Returns true if the PTE for virtual page VPAGE in PD has been accessed recently, that is, between the time the PTE was installed and the last time it was cleared. More... | |
void | pagedir_set_accessed (uint32_t *pd, const void *vpage, bool accessed) |
Sets the accessed bit to ACCESSED in the PTE for virtual page VPAGE in PD. More... | |
void | pagedir_activate (uint32_t *pd) |
Loads page directory PD into the CPU's page directory base register. More... | |
|
static |
Returns the currently active page directory.
Definition at line 235 of file pagedir.c.
References ptov().
Referenced by invalidate_pagedir().
|
static |
Seom page table changes can cause the CPU's translation lookaside buffer (TLB) to become out-of-sync with the page table.
When this happens, we have to "invalidate" the TLB by re-activating it.
This function invalidates the TLB if PD is the active page directory. (If PD is not active then its entries are not in the TLB, so there is no need to invalidate anything.)
Definition at line 255 of file pagedir.c.
References active_pd(), and pagedir_activate().
Referenced by pagedir_clear_page(), pagedir_set_accessed(), and pagedir_set_dirty().
Returns the address of the page table entry for virtual address VADDR in page directory PD.
If PD does not have a page table for VADDR, behavior depends on CREATE. If CREATE is true, then a new page table is created and a pointer into it is returned. Otherwise, a null pointer is returned.
Definition at line 57 of file pagedir.c.
References ASSERT, create(), is_user_vaddr(), NULL, PAL_ZERO, palloc_get_page(), pd_no(), pde_create(), pde_get_pt(), and pt_no().
Referenced by pagedir_clear_page(), pagedir_get_page(), pagedir_is_accessed(), pagedir_is_dirty(), pagedir_set_accessed(), pagedir_set_dirty(), and pagedir_set_page().
void pagedir_activate | ( | uint32_t * | pd | ) |
Loads page directory PD into the CPU's page directory base register.
Definition at line 220 of file pagedir.c.
References init_page_dir, NULL, and vtop().
Referenced by invalidate_pagedir(), process_activate(), and process_exit().
void pagedir_clear_page | ( | uint32_t * | pd, |
void * | upage | ||
) |
Marks user virtual page UPAGE "not present" in page directory PD.
Later accesses to the page will fault. Other bits in the page table entry are preserved. UPAGE need not be mapped.
Definition at line 144 of file pagedir.c.
References ASSERT, invalidate_pagedir(), is_user_vaddr(), lookup_page(), NULL, pg_ofs(), and PTE_P.
uint32_t * pagedir_create | ( | void | ) |
Creates a new page directory that has mappings for kernel virtual addresses, but none for user virtual addresses.
Returns the new page directory, or a null pointer if memory allocation fails.
Definition at line 17 of file pagedir.c.
References init_page_dir, memcpy(), NULL, palloc_get_page(), and PGSIZE.
Referenced by load().
void pagedir_destroy | ( | uint32_t * | pd | ) |
Destroys page directory PD, freeing all the pages it references.
Definition at line 28 of file pagedir.c.
References ASSERT, init_page_dir, NULL, palloc_free_page(), pd_no(), pde_get_pt(), PGSIZE, PHYS_BASE, pte_get_page(), and PTE_P.
Referenced by process_exit().
void * pagedir_get_page | ( | uint32_t * | pd, |
const void * | uaddr | ||
) |
Looks up the physical address that corresponds to user virtual address UADDR in PD.
Returns the kernel virtual address corresponding to that physical address, or a null pointer if UADDR is unmapped.
Definition at line 126 of file pagedir.c.
References ASSERT, is_user_vaddr(), lookup_page(), NULL, pg_ofs(), pte_get_page(), and PTE_P.
Referenced by install_page().
Returns true if the PTE for virtual page VPAGE in PD has been accessed recently, that is, between the time the PTE was installed and the last time it was cleared.
Returns false if PD contains no PTE for VPAGE.
Definition at line 193 of file pagedir.c.
References lookup_page(), NULL, and PTE_A.
Returns true if the PTE for virtual page VPAGE in PD is dirty, that is, if the page has been modified since the PTE was installed.
Returns false if PD contains no PTE for VPAGE.
Definition at line 164 of file pagedir.c.
References lookup_page(), NULL, and PTE_D.
Sets the accessed bit to ACCESSED in the PTE for virtual page VPAGE in PD.
Definition at line 202 of file pagedir.c.
References invalidate_pagedir(), lookup_page(), NULL, and PTE_A.
Set the dirty bit to DIRTY in the PTE for virtual page VPAGE in PD.
Definition at line 173 of file pagedir.c.
References invalidate_pagedir(), lookup_page(), NULL, and PTE_D.
Adds a mapping in page directory PD from user virtual page UPAGE to the physical frame identified by kernel virtual address KPAGE.
UPAGE must not already be mapped. KPAGE should probably be a page obtained from the user pool with palloc_get_page(). If WRITABLE is true, the new page is read/write; otherwise it is read-only. Returns true if successful, false if memory allocation failed.
Definition at line 99 of file pagedir.c.
References ASSERT, init_page_dir, init_ram_pages, is_user_vaddr(), lookup_page(), NULL, pg_ofs(), pte_create_user(), PTE_P, PTSHIFT, and vtop().
Referenced by install_page().