lkm: add is2mb, no usage yet
This commit is contained in:
parent
0d4b45391a
commit
182c517c5a
1 changed files with 44 additions and 0 deletions
44
code/lkm.c
44
code/lkm.c
|
@ -1,9 +1,11 @@
|
||||||
|
#include <asm/pgtable_64.h>
|
||||||
#include <linux/device.h>
|
#include <linux/device.h>
|
||||||
#include <linux/fs.h>
|
#include <linux/fs.h>
|
||||||
#include <linux/init.h>
|
#include <linux/init.h>
|
||||||
#include <linux/module.h>
|
#include <linux/module.h>
|
||||||
#include <linux/proc_fs.h>
|
#include <linux/proc_fs.h>
|
||||||
#include <linux/uaccess.h>
|
#include <linux/uaccess.h>
|
||||||
|
#include <stddef.h>
|
||||||
|
|
||||||
#define DEVICE_NAME "lkm"
|
#define DEVICE_NAME "lkm"
|
||||||
#define CLASS_NAME "lkmclass"
|
#define CLASS_NAME "lkmclass"
|
||||||
|
@ -25,6 +27,48 @@ static struct file_operations lkm_fops = {
|
||||||
.unlocked_ioctl = lkm_ioctl,
|
.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
|
static int
|
||||||
lkm_init(void)
|
lkm_init(void)
|
||||||
{
|
{
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue