Skip to content

Commit a418658

Browse files
committed
arch,pt: add dump_pagetable_va() functions
These functionality dumps the current state of page tables for specified CR3 only for a given virtual address. Signed-off-by: Pawel Wieczorkiewicz <[email protected]>
1 parent 4442666 commit a418658

File tree

2 files changed

+62
-0
lines changed

2 files changed

+62
-0
lines changed

arch/x86/pagetables.c

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -133,6 +133,66 @@ void dump_pagetables(cr3_t *cr3_ptr) {
133133
spin_unlock(&vmap_lock);
134134
}
135135

136+
static void dump_pagetable_va(cr3_t *cr3_ptr, void *va) {
137+
paddr_t tab_paddr;
138+
pgentry_t *tab;
139+
#if defined(__x86_64__)
140+
int level = 4;
141+
#else
142+
int level = 3;
143+
#endif
144+
145+
ASSERT(cr3_ptr);
146+
if (mfn_invalid(cr3_ptr->mfn)) {
147+
/* FIXME: Use warning */
148+
printk("CR3: 0x%lx is invalid", cr3.paddr);
149+
return;
150+
}
151+
152+
spin_lock(&vmap_lock);
153+
154+
tab = tmp_map_mfn(cr3_ptr->mfn);
155+
#if defined(__x86_64__)
156+
pml4_t *l4e = l4_table_entry((pml4_t *) tab, va);
157+
dump_pte(l4e, cr3_ptr->mfn, level--, l4_table_index(va));
158+
159+
if (mfn_invalid(l4e->mfn))
160+
goto unlock;
161+
162+
tab_paddr = mfn_to_paddr(l4e->mfn);
163+
tab = tmp_map_mfn(l4e->mfn);
164+
#endif
165+
pdpe_t *l3e = l3_table_entry((pdpe_t *) tab, va);
166+
dump_pte(l3e, tab_paddr, level--, l3_table_index(va));
167+
168+
if (mfn_invalid(l3e->mfn) || l3e->PS)
169+
goto unlock;
170+
171+
tab_paddr = mfn_to_paddr(l3e->mfn);
172+
tab = tmp_map_mfn(l3e->mfn);
173+
pde_t *l2e = l2_table_entry((pde_t *) tab, va);
174+
dump_pte(l2e, tab_paddr, level--, l2_table_index(va));
175+
176+
if (mfn_invalid(l2e->mfn) || l2e->PS)
177+
goto unlock;
178+
179+
tab_paddr = mfn_to_paddr(l2e->mfn);
180+
tab = tmp_map_mfn(l2e->mfn);
181+
pte_t *l1e = l1_table_entry((pte_t *) tab, va);
182+
dump_pte(l1e, tab_paddr, level--, l1_table_index(va));
183+
184+
unlock:
185+
spin_unlock(&vmap_lock);
186+
}
187+
188+
void dump_kern_pagetable_va(void *va) {
189+
dump_pagetable_va(&cr3, va);
190+
}
191+
192+
void dump_user_pagetable_va(void *va) {
193+
dump_pagetable_va(&user_cr3, va);
194+
}
195+
136196
static mfn_t get_cr3_mfn(cr3_t *cr3_entry) {
137197
void *cr3_mapped = NULL;
138198

include/arch/x86/pagetable.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -288,6 +288,8 @@ extern pml4_t l4_pt_entries[L4_PT_ENTRIES];
288288

289289
extern void init_pagetables(void);
290290
extern void dump_pagetables(cr3_t *cr3_ptr);
291+
extern void dump_kern_pagetable_va(void *va);
292+
extern void dump_user_pagetable_va(void *va);
291293

292294
#endif /* __ASSEMBLY__ */
293295

0 commit comments

Comments
 (0)