我试图在内核模块中读取通过kmalloc分配的虚拟内存地址的内存属性。
使用arch / arm64 / include / asm / pgtable.h中提供的api进行手动页面表行走。
以下是代码。
{
unsigned int attr;
pud_t *pud;
pmd_t *pmd;
pte_t *pte;
pgd_t *pgd, *swapper_pgd;
struct page *pg = phys_to_page(read_sysreg(ttbr1_el1));
swapper_pgd = (pgd_t*) kmap(pg);
pgd = pgd_offset_raw(swapper_pgd, (uint64_t)buf);
pgd_ptr = (pgd_t *)kmap(pgd_page(*pgd));
if(!pgd)
return 0;
kunmap(pg);
pg = phys_to_page(pud_offset_phys(pgd, (uint64_t)buf));
pud = (pud_t *)kmap(pg);
if(!pud)
return 0;
kunmap(pg);
pg = phys_to_page(pmd_offset_phys(pud, (uint64_t)buf));
pmd = (pmd_t *)kmap(pg);
if(!pmd)
return 0;
kunmap(pg);
pg = phys_to_page(pte_offset_phys(pmd, (uint64_t)buf));
pte = (pte_t *)kmap(pg);
if(!pte)
return 0;
attr = PTE_ATTRINDX_MASK & pte_val(*pte);
kunmap(pg);
return attr;
}
我可以依赖从此代码中获取的内存属性值吗?