void*********************

This commit is contained in:
2026-09-24 17:34:14 +02:00
parent 8ab7e5a33d
commit 675ff8519a
2 changed files with 63 additions and 35 deletions
+29 -2
View File
@@ -1,5 +1,7 @@
#include "kernel.h"
#include "types.h"
#include <kmalloc.h>
#include <limits.h>
#include <string.h>
// this file contains SLUB inspired HEAP allocator
@@ -46,7 +48,32 @@ void* kmalloc(size_t size) {
: "eax", "edx");
// freelists_all_cpus[core_id];
// TODO enable when we actualy know how many CPUs we have
if () {
// TODO disable when we actualy know how many CPUs we have
core_id = 0;
size_t alloc_index;
{
uint8_t leading_zeros = __builtin_clzll(size);
if (__builtin_popcountll(size) == 1) {
alloc_index = leading_zeros;
} else {
alloc_index = sizeof(size) * CHAR_BIT - leading_zeros;
}
if (alloc_index > KMALLOC_MAX_SIZE) {
// NOT IMPLEMENTED
printk("Cannot allocate [%lu] bytes: \e[1MNOT "
"IMPLEMENTED!\e[8M\n",
size);
return NULL;
}
alloc_index -= LOWEST_POWER;
}
void** selected_freelist =
freelists_all_cpus[core_id].freelists[alloc_index];
if (selected_freelist != NULL) {
// fast path
void** second_item_in_list = *selected_freelist;
} else {
// slower path
}
}