-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathibs-vtpmo.h
68 lines (45 loc) · 1.53 KB
/
ibs-vtpmo.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
#ifndef __IBS_VTPMO__
#define __IBS_VTPMO__
#define ADDRESS_MASK 0xfffffffffffff000
#define PAGE_TABLE_ADDRESS phys_to_virt(__read_cr3() & ADDRESS_MASK)
#define PT_ADDRESS_MASK 0x7ffffffffffff000
#define VALID 0x1
#define LH_MAPPING 0x80
#define PML4(addr) (((long long)(addr) >> 39) & 0x1ff)
#define PDP(addr) (((long long)(addr) >> 30) & 0x1ff)
#define PDE(addr) (((long long)(addr) >> 21) & 0x1ff)
#define PTE(addr) (((long long)(addr) >> 12) & 0x1ff)
const int NO_MAP = -1;
static int sys_vtpmo(unsigned long vaddr)
{
void* target_address;
pud_t* pdp;
pmd_t* pde;
pte_t* pte;
pgd_t *pml4;
int frame_number;
unsigned long frame_addr;
target_address = (void*)vaddr;
pml4 = PAGE_TABLE_ADDRESS;
if(!(((ulong)(pml4[PML4(target_address)].pgd)) & VALID))
return NO_MAP;
pdp = __va((ulong)(pml4[PML4(target_address)].pgd) & PT_ADDRESS_MASK);
if(!((ulong)(pdp[PDP(target_address)].pud) & VALID))
return NO_MAP;
pde = __va((ulong)(pdp[PDP(target_address)].pud) & PT_ADDRESS_MASK);
if(!((ulong)(pde[PDE(target_address)].pmd) & VALID))
return NO_MAP;
if((ulong)pde[PDE(target_address)].pmd & LH_MAPPING)
{
frame_addr = (ulong)(pde[PDE(target_address)].pmd) & PT_ADDRESS_MASK;
frame_number = frame_addr >> 12;
return frame_number;
}
pte = __va((ulong)(pde[PDE(target_address)].pmd) & PT_ADDRESS_MASK);
if(!((ulong)(pte[PTE(target_address)].pte) & VALID))
return NO_MAP;
frame_addr = (ulong)(pte[PTE(target_address)].pte) & PT_ADDRESS_MASK;
frame_number = frame_addr >> 12;
return frame_number;
}
#endif