fix treeallocator bug and reenable
This commit is contained in:
@ -17,9 +17,9 @@ Keyboard kb; // Tastatur
|
||||
IntDispatcher intdis; // Unterbrechungsverteilung
|
||||
PIC pic; // Interrupt-Controller
|
||||
unsigned int total_mem; // RAM total
|
||||
BumpAllocator allocator;
|
||||
// BumpAllocator allocator;
|
||||
// LinkedListAllocator allocator;
|
||||
// TreeAllocator allocator;
|
||||
TreeAllocator allocator;
|
||||
Scheduler scheduler;
|
||||
BIOS bios; // Schnittstelle zum 16-Bit BIOS
|
||||
VESA vesa; // VESA-Treiber
|
||||
|
||||
@ -30,9 +30,9 @@ extern Keyboard kb; // Tastatur
|
||||
extern IntDispatcher intdis; // Unterbrechungsverteilung
|
||||
extern PIC pic; // Interrupt-Controller
|
||||
extern unsigned int total_mem; // RAM total
|
||||
extern BumpAllocator allocator;
|
||||
// extern BumpAllocator allocator;
|
||||
// extern LinkedListAllocator allocator;
|
||||
// extern TreeAllocator allocator;
|
||||
extern TreeAllocator allocator;
|
||||
extern Scheduler scheduler;
|
||||
extern BIOS bios; // Schnittstelle zum 16-Bit BIOS
|
||||
extern VESA vesa; // VESA-Treiber
|
||||
|
||||
@ -10,6 +10,7 @@ void TreeAllocator::init() {
|
||||
this->free_start->left = NULL;
|
||||
this->free_start->right = NULL;
|
||||
this->free_start->parent = NULL;
|
||||
this->free_start->red = false; // The root is always black
|
||||
this->free_start->next = (list_block_t*)this->free_start;
|
||||
this->free_start->previous = (list_block_t*)this->free_start;
|
||||
|
||||
@ -59,9 +60,6 @@ void* TreeAllocator::alloc(unsigned int req_size) {
|
||||
unsigned int size = this->get_size(best_fit);
|
||||
if constexpr (DEBUG) { kout << " - Found best-fit: " << hex << (unsigned int)best_fit << endl; }
|
||||
|
||||
// Remove the block first so we can insert correctly when cutting
|
||||
// kout << " - Removing block from freelist" << endl;
|
||||
this->rbt_remove(best_fit);
|
||||
if (size > HEAP_MIN_FREE_BLOCK_SIZE + rreq_size + sizeof(list_block_t)) {
|
||||
// Block can be cut
|
||||
if constexpr (DEBUG) { kout << " - Allocating " << dec << rreq_size << " Bytes with cutting" << endl; }
|
||||
@ -77,6 +75,11 @@ void* TreeAllocator::alloc(unsigned int req_size) {
|
||||
// need to remove it from the freelist, which is done for both cases
|
||||
if constexpr (DEBUG) { kout << " - Allocating " << dec << rreq_size << " Bytes without cutting" << endl; }
|
||||
}
|
||||
// Remove the old block from the freelist
|
||||
// BUG: If the first allocation allocates the whole heap, this removal will crash the paging
|
||||
// as the freelist will no longer contain any notes, gives NullPointerException as it's not handled
|
||||
// kout << " - Removing block from freelist" << endl;
|
||||
this->rbt_remove(best_fit);
|
||||
|
||||
if constexpr (DEBUG) { kout << " - Returned address " << hex << (unsigned int)((char*)best_fit + sizeof(list_block_t)) << endl; }
|
||||
return (void*)((char*)best_fit + sizeof(list_block_t));
|
||||
|
||||
Reference in New Issue
Block a user