mirror of
https://github.com/wichtounet/thor-os.git
synced 2025-09-13 14:36:37 -04:00
Implement k_free
This commit is contained in:
parent
72ae92dfae
commit
4f74c84ef2
@ -17,5 +17,6 @@ const char* str_e820_type(std::size_t type);
|
|||||||
|
|
||||||
void init_memory_manager();
|
void init_memory_manager();
|
||||||
std::size_t* k_malloc(std::size_t bytes);
|
std::size_t* k_malloc(std::size_t bytes);
|
||||||
|
void k_free(std::size_t* block);
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
@ -128,7 +128,7 @@ void init_memory_manager(){
|
|||||||
}
|
}
|
||||||
|
|
||||||
std::size_t* k_malloc(std::size_t bytes){
|
std::size_t* k_malloc(std::size_t bytes){
|
||||||
malloc_header_chunk* current = malloc_head->next;
|
auto current = malloc_head->next;
|
||||||
|
|
||||||
while(true){
|
while(true){
|
||||||
if(current == malloc_head){
|
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(){
|
void load_memory_map(){
|
||||||
mmap_query(0, &e820_failed);
|
mmap_query(0, &e820_failed);
|
||||||
mmap_query(1, &entry_count);
|
mmap_query(1, &entry_count);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user