Initial commit

This commit is contained in:
ssimnb 2026-01-22 08:05:43 +01:00
parent 3ba3e98f6b
commit 1dd7b8b07f
3 changed files with 103 additions and 1 deletions

64
slaballoc.c Normal file
View file

@ -0,0 +1,64 @@
#include <stddef.h>
#include <stdint.h>
#include "slaballoc.h"
char memory[4096 * 10];
int cnt = 0;
struct ma_kcache *head = NULL; // create standard sizes
uint64_t *alloc_contigious_pages(int num){
uint64_t *ret = (uint64_t*)(memory + cnt*4096);
cnt+=num;
return ret;
}
struct ma_slab *_ma_alloc_initial_slab(struct ma_kcache *kcache){
uint64_t *p = alloc_contigious_pages(1);
int bufnum = (4096 - sizeof(struct ma_slab)) / kcache->objsize; // Calculate the number of buffers in this slab
for(int i = 0; i < bufnum; i++){
(uint64_t*)((uint64_t)p + i * kcache->objsize)
}
}
struct ma_kcache *ma_cache_create(char *name, size_t size, uint32_t flags, void (*constructor)(void *, size_t), void (*destructor)(void *, size_t)){
struct ma_kcache *kcache = (struct ma_kcache*)alloc_contigious_pages(1);
head->next = kcache;
kcache->prev = head;
head = kcache;
int bufnum = (4096 - sizeof(struct ma_slab)) / size; // Calculate the number of buffers in this slab
struct ma_slab *slab_structure = (struct ma_slab*)((uint64_t)kcache - sizeof(struct ma_slab));
kcache->slabs_free = slab_structure;
return kcache;
}
void *ma_cache_alloc(struct ma_kcache *cache, uint64_t flags){
if(cache->slabs_free == NULL){
if(cache->slabs_partial == NULL){
}
}
common:
}
int main(){
}