handle non-canonical addresses in vmm

This commit is contained in:
2026-09-27 17:04:41 +02:00
parent 6c609e9840
commit ffa23b1dba
2 changed files with 12 additions and 21 deletions
-21
View File
@@ -51,27 +51,6 @@ __noreturn void _start(void) {
printk("%d: %lu\n", i, get_random_number()); 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. // The most important function in the world.
splash(); splash();
+12
View File
@@ -31,6 +31,18 @@ int vmm_alloc(void** vaddr, uint64_t count, uint64_t flags) {
*vaddr = (void*)((uint64_t)(*vaddr) | *vaddr = (void*)((uint64_t)(*vaddr) |
CANONICAL_MASK_KERNEL); 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++) { for (uint64_t i = 0; i < count; i++) {
uint64_t* pte = uint64_t* pte =