Buddy allocator

This commit is contained in:
Imbus 2025-09-06 02:37:09 +02:00
parent 21d55031d9
commit 90c63ab41e
3 changed files with 162 additions and 0 deletions

22
kern/libkern/buddy.h Normal file
View file

@ -0,0 +1,22 @@
#ifndef BUDDY_H
#define BUDDY_H
#include <stddef.h>
#include <stdint.h>
extern uintptr_t heap_start;
extern uintptr_t heap_end;
extern char __heap_start;
extern char __heap_end;
void buddy_init(uintptr_t start, uintptr_t end);
void *buddy_alloc(size_t size);
int buddy_free(void *ptr);
/* Returns total heap memory managed by buddy allocator in bytes */
static inline size_t buddy_total_bytes(void) {
return (uintptr_t)&__heap_end - (uintptr_t)&__heap_start;
}
#endif // BUDDY_H