Skip to content

Commit

Permalink
Use current vmm_info when vmm is allocating memory
Browse files Browse the repository at this point in the history
  • Loading branch information
dreamos82 committed Nov 13, 2023
1 parent 7f957cc commit d7fae9a
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 9 deletions.
4 changes: 2 additions & 2 deletions src/kernel/arch/x86_64/mem/vmm_mapping.c
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ void *map_phys_to_virt_addr_hh(void* physical_address, void* address, size_t fla
pd_root = (uint64_t *) hhdm_get_variable((uintptr_t) pdpr_root[pdpr_e] & VM_PAGE_TABLE_BASE_ADDRESS_MASK);
}

if( !(pd_root[pd_e] & 0b01) ) {
if( !(pd_root[pd_e] & 0b1) ) {
#if SMALL_PAGES == 1
uint64_t *new_table = pmm_alloc_frame();
pd_root[pd_e] = (uint64_t) new_table | user_mode_status | WRITE_BIT | PRESENT_BIT;
Expand All @@ -67,7 +67,7 @@ void *map_phys_to_virt_addr_hh(void* physical_address, void* address, size_t fla
pt_root = new_table_hhdm;
#elif SMALL_PAGES == 0
pd_root[pd_e] = (uint64_t) (physical_address) | HUGEPAGE_BIT | flags | user_mode_status;
// loglinef(Verbose, "(%s): PD Flags: 0x%x entry value: 0x%x", __FUNCTION__, flags, pd_table[pd_e]);
loglinef(Verbose, "(%s): PD Flags: 0x%x entry value: 0x%x", __FUNCTION__, flags, pd_root[pd_e]);
#endif
}

Expand Down
8 changes: 3 additions & 5 deletions src/kernel/mem/vmm.c
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ void *vmm_alloc(size_t size, size_t flags, VmmInfo *vmm_info) {
// 1.a We need to get the virtual address for the new structure
new_container = (VmmContainer*)align_value_to_page((uint64_t)vmm_info->status.vmm_cur_container + sizeof(VmmContainer) + PAGE_SIZE_IN_BYTES);
loglinef(Verbose, "(%s): new address 0x%x is aligned: %d", __FUNCTION__, new_container, is_address_aligned((uintptr_t)new_container, PAGE_SIZE_IN_BYTES));
map_phys_to_virt_addr_hh(new_container_phys_address, new_container, VMM_FLAGS_PRESENT | VMM_FLAGS_WRITE_ENABLE, NULL);
map_phys_to_virt_addr_hh(new_container_phys_address, new_container, VMM_FLAGS_PRESENT | VMM_FLAGS_WRITE_ENABLE, (uint64_t *) vmm_info->root_table_hhdm);
// Step 2: Reset vmm_cur_index
vmm_info->status.vmm_cur_index = 0;
// Step 2.a: Set next as null for new_container;
Expand Down Expand Up @@ -145,13 +145,11 @@ void *vmm_alloc(size_t size, size_t flags, VmmInfo *vmm_info) {
size_t arch_flags = vm_parse_flags(flags);
loglinef(Verbose, "(%s): Testing vm_parse_flags: 0x%x required pages: %d - address to ret: 0x%x - arch_flags: 0x%x", __FUNCTION__, arch_flags, required_pages, address_to_return, arch_flags);
loglinef(Verbose, "(%s): address: 0x%x", __FUNCTION__, vmm_info->root_table_hhdm);
if (vmm_info->root_table_hhdm != NULL) {
loglinef(Verbose, "(%s): vmm_info->root_table_hhdm[510]: 0x%x ", __FUNCTION__, ((uint64_t *)vmm_info->root_table_hhdm)[510]);
}

for ( size_t i = 0; i < required_pages; i++ ) {
void *frame = pmm_alloc_frame();
loglinef(Verbose, "(%s): address to map: 0x%x - phys frame: 0x%x", __FUNCTION__, frame, address_to_return);
map_phys_to_virt_addr_hh((void*) frame, (void *)address_to_return + (i * PAGE_SIZE_IN_BYTES), arch_flags | VMM_FLAGS_PRESENT | VMM_FLAGS_WRITE_ENABLE, NULL);
map_phys_to_virt_addr_hh((void*) frame, (void *)address_to_return + (i * PAGE_SIZE_IN_BYTES), arch_flags | VMM_FLAGS_PRESENT | VMM_FLAGS_WRITE_ENABLE, (uint64_t *) vmm_info->root_table_hhdm);
}
}

Expand Down
4 changes: 2 additions & 2 deletions src/kernel/scheduling/thread.c
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,8 @@ thread_t* create_thread(char* thread_name, void (*_entry_point)(void *), void* a
while(1);
}
// We need to allocate a new stack for each thread
//void* stack_pointer = kmalloc(THREAD_DEFAULT_STACK_SIZE);
void* stack_pointer = vmm_alloc(THREAD_DEFAULT_STACK_SIZE, VMM_FLAGS_PRESENT | VMM_FLAGS_WRITE_ENABLE, &(parent_task->vmm_data));
void* stack_pointer = kmalloc(THREAD_DEFAULT_STACK_SIZE);
//void* stack_pointer = vmm_alloc(THREAD_DEFAULT_STACK_SIZE, VMM_FLAGS_PRESENT | VMM_FLAGS_WRITE_ENABLE, &(parent_task->vmm_data));
if (stack_pointer == NULL) {
loglinef(Fatal, "(create_thread): rsp is null - PANIC!");
while(1);
Expand Down

0 comments on commit d7fae9a

Please sign in to comment.