Implement k_free

This commit is contained in:
Baptiste Wicht 2013-11-01 18:17:30 +01:00
parent 72ae92dfae
commit 4f74c84ef2
2 changed files with 14 additions and 1 deletions

View File

@ -17,5 +17,6 @@ const char* str_e820_type(std::size_t type);
void init_memory_manager();
std::size_t* k_malloc(std::size_t bytes);
void k_free(std::size_t* block);
#endif

View File

@ -128,7 +128,7 @@ void init_memory_manager(){
}
std::size_t* k_malloc(std::size_t bytes){
malloc_header_chunk* current = malloc_head->next;
auto current = malloc_head->next;
while(true){
if(current == malloc_head){
@ -199,6 +199,18 @@ std::size_t* k_malloc(std::size_t bytes){
}
}
void k_free(std::size_t* block){
auto free_header = reinterpret_cast<malloc_header_chunk*>(block);
auto header = malloc_head;
free_header->prev = header;
free_header->next = header->next;
header->next->prev = free_header;
header->next = free_header;
}
void load_memory_map(){
mmap_query(0, &e820_failed);
mmap_query(1, &entry_count);