Compare commits

..

3 Commits

Author SHA1 Message Date
0c280d971b clean: simplify code 2024-11-20 16:26:33 +01:00
94b2fa340c fix: check if zone is not null before explore it 2024-11-20 16:26:01 +01:00
ec3a038a36 fix: free frame use right addr 2024-11-20 16:25:31 +01:00
3 changed files with 8 additions and 11 deletions

View File

@ -13,7 +13,7 @@ void *alloc_frame(void)
struct frame_zone *it = head;
while (it && !it->remaining_frames)
it = it->next;
if (it->remaining_frames == 0) {
if (!it || it->remaining_frames == 0) {
kprintf(KERN_CRIT "No memory zone available (ratio)\n");
return NULL;
}

View File

@ -68,12 +68,11 @@ static void add_frame_node(multiboot_memory_map_t *mmmt)
// KERNEL code partially on the block
if (HEAP_START >= zone) {
const uint32_t len = mmmt->len -
((uint64_t)&_kernel_end - HEAP_END) -
(uint64_t)zone;
const uint32_t start_space =
CEIL(HEAP_START, PAGE_SIZE) * PAGE_SIZE;
const uint32_t len = mmmt->len - (start_space - (uint32_t)zone);
mmmt->len = CEIL(len, PAGE_SIZE) * PAGE_SIZE;
zone =
(void *)((uint32_t)CEIL(HEAP_START, PAGE_SIZE) * PAGE_SIZE);
zone = (void *)start_space;
}
init_page_table(frame_zones_page_table, 0);
@ -90,9 +89,9 @@ static void add_frame_node(multiboot_memory_map_t *mmmt)
/** 8 is cause we are using uint8_t
nb_frame = size / (PAGE_SIZE + 1 / 8)
cause we are using non decimal number
nb_frame = ((size * 8) / (PAGE_SIZE * 8 + 1)) / 8
nb_frame = ((size * 8) / (PAGE_SIZE * 8 + 1))
*/
const uint32_t nb_frame = ((mmmt->len * 8) / (PAGE_SIZE * 8 + 1)) - 1;
const uint32_t nb_frame = ((mmmt->len * 8) / (PAGE_SIZE * 8 + 1));
current->first_free_frame = 0;
current->next = NULL;

View File

@ -7,8 +7,6 @@
#include "memory.h"
#include "utils.h"
#define MAX_TLB_ENTRIES 32
static int16_t find_next_block(size_t nb_pages, uint16_t *pd_index_ptr,
uint32_t **page_table_ptr)
{
@ -49,7 +47,7 @@ void *alloc_pages(size_t size)
void *frame = alloc_frame();
if (!frame) {
for (size_t j = index; j < i; j++)
free_frame((void *)(page_table[j] >> 12));
free_frame((void *)(page_table[j] & PAGE_MASK));
return NULL;
}
page_table[i] = ((uint32_t)frame & PAGE_MASK) | INIT_FLAGS;