Buddy allocator
This commit is contained in:
parent
21d55031d9
commit
90c63ab41e
3 changed files with 162 additions and 0 deletions
22
kern/libkern/buddy.h
Normal file
22
kern/libkern/buddy.h
Normal 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
|
||||
Loading…
Add table
Add a link
Reference in a new issue