feature: memory limit with multiboot (wip, still crashing)
This commit is contained in:
@ -8,6 +8,7 @@
|
||||
#include "utils.h"
|
||||
|
||||
#define MAX_FRAMES (HEAP_END / PAGE_SIZE)
|
||||
#define NB_FRAMES (mem_size / PAGE_SIZE)
|
||||
|
||||
enum {
|
||||
FREE,
|
||||
@ -19,7 +20,7 @@ static uint8_t frame_table[MAX_FRAMES];
|
||||
static int32_t find_next_block(size_t nb_frames)
|
||||
{
|
||||
for (uint32_t i = CEIL(HEAP_START, PAGE_SIZE);
|
||||
i + nb_frames < MAX_FRAMES; i++) {
|
||||
i + nb_frames < NB_FRAMES; i++) {
|
||||
uint32_t j;
|
||||
for (j = 0; frame_table[i + j] == FREE && j < nb_frames; j++)
|
||||
;
|
||||
@ -39,7 +40,7 @@ void *alloc_frames(size_t size)
|
||||
return NULL;
|
||||
}
|
||||
for (size_t j = 0; j < nb_frames; j++) {
|
||||
assert(j + i < MAX_FRAMES);
|
||||
assert(j + i < NB_FRAMES);
|
||||
frame_table[j + i] = USED;
|
||||
}
|
||||
return (void *)(i * PAGE_SIZE);
|
||||
@ -50,13 +51,13 @@ int free_frames(void *frame_ptr, size_t size)
|
||||
const uint32_t nb_frames = CEIL(size, PAGE_SIZE);
|
||||
const uint32_t start = (uint32_t)frame_ptr / PAGE_SIZE;
|
||||
|
||||
if (start > MAX_FRAMES) {
|
||||
if (start > NB_FRAMES) {
|
||||
kprintf(KERN_WARNING "Address out of range\n");
|
||||
return -1;
|
||||
} else if ((uint32_t)frame_ptr % PAGE_SIZE) {
|
||||
kprintf(KERN_WARNING "Invalid address\n");
|
||||
return -1;
|
||||
} else if (start + nb_frames > MAX_FRAMES) {
|
||||
} else if (start + nb_frames > NB_FRAMES) {
|
||||
kprintf(KERN_WARNING "Invalid number of frames\n");
|
||||
return -1;
|
||||
}
|
||||
|
@ -6,6 +6,7 @@
|
||||
|
||||
uint32_t *page_directory = &boot_page_directory;
|
||||
uint32_t page_table_default[1024] __attribute__((aligned(4096)));
|
||||
uint32_t mem_size;
|
||||
|
||||
void init_memory(void)
|
||||
{
|
||||
|
Reference in New Issue
Block a user