Skip to content

Commit

Permalink
mem: get page table entries for vaddr
Browse files Browse the repository at this point in the history
Add APIs to return the virtual addresses of
page table entries that map a given virtual address.

Signed-off-by: Daniele Ahmed <ahmeddan amazon c;0m >
  • Loading branch information
82marbag committed Jul 30, 2021
1 parent 5d29781 commit 0575b4f
Showing 1 changed file with 27 additions and 0 deletions.
27 changes: 27 additions & 0 deletions include/arch/x86/pagetable.h
Original file line number Diff line number Diff line change
Expand Up @@ -237,6 +237,33 @@ static inline pte_t *get_l1_table(const void *va) {
return INVALID_PGENTRY(l1e) ? NULL : mfn_to_virt_kern(l1e->mfn);
}

/* Return the virtual address of the PT entry mapping this virtual address.
* The entry is assumed to be mapped
*/
static inline pgentry_t *get_pte(const void *va) {
pte_t *l1t = get_l1_table(va);
pte_t *l1e = l1_table_entry(l1t, va);
return &(l1e->entry);
}

/* Return the virtual address of the PD entry mapping this virtual address.
* The entry is assumed to be mapped
*/
static inline pgentry_t *get_pde(const void *va) {
pde_t *l2t = get_l2_table(va);
pde_t *l2e = l2_table_entry(l2t, va);
return &(l2e->entry);
}

/* Return the virtual address of the PDP entry mapping this virtual address.
* The entry is assumed to be mapped
*/
static inline pgentry_t *get_pdpe(const void *va) {
pdpe_t *l3t = get_l3_table(va);
pdpe_t *l3e = l3_table_entry(l3t, va);
return &(l3e->entry);
}

static inline void set_pgentry(pgentry_t *e, mfn_t mfn, unsigned long flags) {
*e = pgentry_from_mfn(mfn, flags);
barrier();
Expand Down

0 comments on commit 0575b4f

Please sign in to comment.