Skip to content

Commit 0575b4f

Browse files
committed
mem: get page table entries for vaddr
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 >
1 parent 5d29781 commit 0575b4f

File tree

1 file changed

+27
-0
lines changed

1 file changed

+27
-0
lines changed

include/arch/x86/pagetable.h

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -237,6 +237,33 @@ static inline pte_t *get_l1_table(const void *va) {
237237
return INVALID_PGENTRY(l1e) ? NULL : mfn_to_virt_kern(l1e->mfn);
238238
}
239239

240+
/* Return the virtual address of the PT entry mapping this virtual address.
241+
* The entry is assumed to be mapped
242+
*/
243+
static inline pgentry_t *get_pte(const void *va) {
244+
pte_t *l1t = get_l1_table(va);
245+
pte_t *l1e = l1_table_entry(l1t, va);
246+
return &(l1e->entry);
247+
}
248+
249+
/* Return the virtual address of the PD entry mapping this virtual address.
250+
* The entry is assumed to be mapped
251+
*/
252+
static inline pgentry_t *get_pde(const void *va) {
253+
pde_t *l2t = get_l2_table(va);
254+
pde_t *l2e = l2_table_entry(l2t, va);
255+
return &(l2e->entry);
256+
}
257+
258+
/* Return the virtual address of the PDP entry mapping this virtual address.
259+
* The entry is assumed to be mapped
260+
*/
261+
static inline pgentry_t *get_pdpe(const void *va) {
262+
pdpe_t *l3t = get_l3_table(va);
263+
pdpe_t *l3e = l3_table_entry(l3t, va);
264+
return &(l3e->entry);
265+
}
266+
240267
static inline void set_pgentry(pgentry_t *e, mfn_t mfn, unsigned long flags) {
241268
*e = pgentry_from_mfn(mfn, flags);
242269
barrier();

0 commit comments

Comments
 (0)