forked from PoliEcho-holding-org/kern
handle non-canonical addresses in vmm
This commit is contained in:
@@ -51,27 +51,6 @@ __noreturn void _start(void) {
|
||||
printk("%d: %lu\n", i, get_random_number());
|
||||
}
|
||||
|
||||
// test VMM
|
||||
{
|
||||
void* vaddr;
|
||||
int ret = vmm_alloc(&vaddr, 2, 0);
|
||||
if (ret != SUCCESS) {
|
||||
panic(NULL, "vmm_alloc returned %d", ret);
|
||||
}
|
||||
{
|
||||
uint64_t* pml4 = pag_get_pml4();
|
||||
uint64_t* pte = pag_get_pte(pml4, vaddr);
|
||||
if (!IS_ERR(pte) && (*pte & PTE_FLAG_PRESENT)) {
|
||||
printk("page allocated\n");
|
||||
} else {
|
||||
printk("page not allocated\n");
|
||||
}
|
||||
}
|
||||
memset(vaddr, 69, 2 * PAGE_SIZE);
|
||||
*(char*)((vaddr + (2 * PAGE_SIZE)) - 1) = 0;
|
||||
printk("read back:\n%s\n", (char*)vaddr);
|
||||
}
|
||||
|
||||
// The most important function in the world.
|
||||
splash();
|
||||
|
||||
|
||||
@@ -31,6 +31,18 @@ int vmm_alloc(void** vaddr, uint64_t count, uint64_t flags) {
|
||||
*vaddr = (void*)((uint64_t)(*vaddr) |
|
||||
CANONICAL_MASK_KERNEL);
|
||||
}
|
||||
} else {
|
||||
if (flags & PTE_FLAG_USER) {
|
||||
if ((void*)((uint64_t)(*vaddr) &
|
||||
CANONICAL_MASK_KERNEL)) {
|
||||
return -EINVAL;
|
||||
}
|
||||
} else {
|
||||
if (!((void*)((uint64_t)(*vaddr) &
|
||||
CANONICAL_MASK_KERNEL))) {
|
||||
return -EINVAL;
|
||||
}
|
||||
}
|
||||
}
|
||||
for (uint64_t i = 0; i < count; i++) {
|
||||
uint64_t* pte =
|
||||
|
||||
Reference in New Issue
Block a user