diff --git a/code/lkm.c b/code/lkm.c index b6282d406..760a75cb1 100644 --- a/code/lkm.c +++ b/code/lkm.c @@ -1,9 +1,11 @@ +#include #include #include #include #include #include #include +#include #define DEVICE_NAME "lkm" #define CLASS_NAME "lkmclass" @@ -25,6 +27,48 @@ static struct file_operations lkm_fops = { .unlocked_ioctl = lkm_ioctl, }; +void +is2mb(size_t addr) +{ + unsigned long above = ((long)addr) >> __VIRTUAL_MASK_SHIFT; + pgd_t *pgd; + p4d_t *p4d; + pud_t *pud; + pmd_t *pmd; + pte_t *pte; + + if (above != 0 && above != -1UL) + return 0; + + pgd = pgd_offset_pgd(_init_top_pgt, addr); + if (pgd_none(*pgd)) + return 0; + + p4d = p4d_offset(pgd, addr); + if (!p4d_present(*p4d)) + return 0; + + pud = pud_offset(p4d, addr); + if (!pud_present(*pud)) + return 0; + + if (pud_large(*pud)) + return 0; + + pmd = pmd_offset(pud, addr); + if (!pmd_present(*pmd)) + return 0; + + if (pmd_large(*pmd)) + return 1; + + pte = pte_offset_kernel(pmd, addr); + if (pte_none(*pte)) + return 0; + + return 0; +} + static int lkm_init(void) {