diff options
author | Marvin Borner | 2020-05-15 20:28:44 +0200 |
---|---|---|
committer | Marvin Borner | 2020-05-15 20:28:44 +0200 |
commit | 916c21af52dc2230d689e1075457c4c29b4b262c (patch) | |
tree | 761fb7eb888d1d3fd33405e4a601014ab1776484 /src/kernel/memory | |
parent | 89b9cad0607d8fb81489143e312c1983e3e8a552 (diff) |
Added test-case for malloc
Diffstat (limited to 'src/kernel/memory')
-rw-r--r-- | src/kernel/memory/alloc.c | 17 | ||||
-rw-r--r-- | src/kernel/memory/paging.c | 16 | ||||
-rw-r--r-- | src/kernel/memory/paging.h | 4 |
3 files changed, 24 insertions, 13 deletions
diff --git a/src/kernel/memory/alloc.c b/src/kernel/memory/alloc.c index 0751011..a4fb60a 100644 --- a/src/kernel/memory/alloc.c +++ b/src/kernel/memory/alloc.c @@ -162,7 +162,10 @@ static struct liballoc_major *allocate_new_page(u32 size) void *malloc(u32 req_size) { - int startedBet = 0; + if (!paging_enabled) + warn("Mallocing while paging is disabled!"); + + int started_bet = 0; u64 best_size = 0; void *p = NULL; u32 diff; @@ -192,14 +195,14 @@ void *malloc(u32 req_size) } maj = l_mem_root; - startedBet = 0; + started_bet = 0; if (l_best_bet != NULL) { best_size = l_best_bet->size - l_best_bet->usage; if (best_size > (size + sizeof(struct liballoc_minor))) { maj = l_best_bet; - startedBet = 1; + started_bet = 1; } } @@ -217,9 +220,9 @@ void *malloc(u32 req_size) continue; } - if (startedBet == 1) { + if (started_bet == 1) { maj = l_mem_root; - startedBet = 0; + started_bet = 0; continue; } @@ -339,9 +342,9 @@ void *malloc(u32 req_size) #ifdef USE_CASE5 if (maj->next == NULL) { - if (startedBet == 1) { + if (started_bet == 1) { maj = l_mem_root; - startedBet = 0; + started_bet = 0; continue; } maj->next = allocate_new_page(size); diff --git a/src/kernel/memory/paging.c b/src/kernel/memory/paging.c index edaa82e..516f0f1 100644 --- a/src/kernel/memory/paging.c +++ b/src/kernel/memory/paging.c @@ -7,9 +7,9 @@ int paging_enabled = 0; u32 tmp[1024][1024] __attribute__((aligned(4096))); -struct page_directory *paging_kernel_directory = (struct page_directory *)tmp; - -struct page_directory *paging_directory; // Current +struct page_directory *paging_kernel_directory __attribute__((aligned(4096))) = + (struct page_directory *)tmp; +struct page_directory *paging_directory __attribute__((aligned(4096))); // Current void paging_init(struct page_directory *dir, int user) { @@ -47,6 +47,14 @@ void paging_install(u32 multiboot_address) log("Enabling"); paging_enable(); log("Installed paging"); + + u32 a = (u32)malloc(4096); + u32 b = (u32)malloc(4096); + free((void *)b); + free((void *)a); + u32 c = (u32)malloc(2048); + assert(a == c); + info("kmalloc test succeeded!"); } void paging_disable() @@ -189,4 +197,4 @@ u32 paging_get_used_pages() } } return n; -} +}
\ No newline at end of file diff --git a/src/kernel/memory/paging.h b/src/kernel/memory/paging.h index f0b50b4..bf82cf5 100644 --- a/src/kernel/memory/paging.h +++ b/src/kernel/memory/paging.h @@ -31,7 +31,7 @@ struct page_directory { struct page_table *tables[1024] __attribute__((aligned(4096))); }; -struct page_directory *paging_kernel_directory; +struct page_directory *paging_kernel_directory __attribute__((aligned(4096))); int paging_enabled; void paging_install(u32 multiboot_address); @@ -58,4 +58,4 @@ void paging_set_user(u32 virt, u32 count); u32 paging_find_pages(u32 count); u32 paging_alloc_pages(u32 count); -#endif +#endif
\ No newline at end of file |