From 256a32438f736cd8ee08e24c9cc8468e911be6da Mon Sep 17 00:00:00 2001 From: Pawel Wieczorkiewicz Date: Thu, 2 Nov 2023 11:57:56 +0100 Subject: [PATCH] arch,pt: add frame finder for virtual address functionality Signed-off-by: Pawel Wieczorkiewicz --- arch/x86/pagetables.c | 21 +++++++++++++++++++++ include/arch/x86/pagetable.h | 3 +++ 2 files changed, 24 insertions(+) diff --git a/arch/x86/pagetables.c b/arch/x86/pagetables.c index 3d733f43..ff2a6a39 100644 --- a/arch/x86/pagetables.c +++ b/arch/x86/pagetables.c @@ -422,6 +422,27 @@ int get_user_va_mfn_order(void *va, mfn_t *mfn, unsigned int *order) { return err; } +static frame_t *get_va_frame(const cr3_t *cr3_ptr, const void *va) { + frame_t *frame = NULL; + unsigned int order; + mfn_t mfn; + + spin_lock(&vmap_lock); + if (get_va_mfn_order(cr3_ptr, va, &mfn, &order) == 0) + frame = find_mfn_frame(mfn, order); + spin_unlock(&vmap_lock); + + return frame; +} + +frame_t *get_kern_va_frame(const void *va) { + return get_va_frame(&cr3, va); +} + +frame_t *get_user_va_frame(const void *va) { + return get_va_frame(&user_cr3, va); +} + void init_pagetables(void) { init_tmp_mapping(); diff --git a/include/arch/x86/pagetable.h b/include/arch/x86/pagetable.h index fb95e444..30f68680 100644 --- a/include/arch/x86/pagetable.h +++ b/include/arch/x86/pagetable.h @@ -304,6 +304,9 @@ extern void dump_user_pagetable_va(void *va); extern int get_kern_va_mfn_order(void *va, mfn_t *mfn, unsigned int *order); extern int get_user_va_mfn_order(void *va, mfn_t *mfn, unsigned int *order); +extern frame_t *get_kern_va_frame(const void *va); +extern frame_t *get_user_va_frame(const void *va); + #endif /* __ASSEMBLY__ */ #endif /* KTF_PAGETABLE_H */