fix: virtual memory manager
This commit is contained in:
@@ -131,6 +131,11 @@ private:
|
||||
static constexpr u64 INIT_END = 0xFFFFA00000000000ULL;
|
||||
private:
|
||||
struct node {
|
||||
enum color_e {
|
||||
RED = 0,
|
||||
BLACK = 1,
|
||||
};
|
||||
|
||||
// NOTE: The parent node is used for the last free node for first free node.
|
||||
node* parent = nullptr;
|
||||
node* left = nullptr;
|
||||
@@ -141,10 +146,12 @@ private:
|
||||
u64 size = 0;
|
||||
u64 maxSize = 0;
|
||||
|
||||
bool is_red() const { return (base & (1ULL << 63)) != 0; }
|
||||
color_e color = BLACK;
|
||||
|
||||
void make_red() { base |= (1ULL << 63); }
|
||||
void make_black() { base &= ~(1ULL << 63); }
|
||||
bool is_red() const { return color == RED; }
|
||||
|
||||
void make_red() { color = RED; }
|
||||
void make_black() { color = BLACK; }
|
||||
|
||||
static u64 max_size(node* node) { return (node != nullptr) ? node->maxSize : 0; }
|
||||
|
||||
@@ -171,7 +178,7 @@ private:
|
||||
|
||||
node* max() {
|
||||
node* node = this;
|
||||
while (node != nullptr && node->left != nullptr)
|
||||
while (node != nullptr && node->right != nullptr)
|
||||
node = node->right;
|
||||
return node;
|
||||
}
|
||||
|
||||
@@ -351,7 +351,7 @@ void vm::remove_fixup(node* first, node* second) {
|
||||
|
||||
node* sibling = second->left;
|
||||
|
||||
if (sibling->is_red()) {
|
||||
if (sibling != nullptr && sibling->is_red()) {
|
||||
sibling->make_black();
|
||||
second->make_red();
|
||||
|
||||
@@ -489,8 +489,9 @@ void vm::rotate_right(node* node) {
|
||||
|
||||
vm::node* vm::allocate_node() {
|
||||
if (m_firstFree != nullptr) {
|
||||
node* node = m_firstFree;
|
||||
m_firstFree = m_firstFree->right;
|
||||
node* node = m_firstFree;
|
||||
m_firstFree = m_firstFree->right;
|
||||
m_firstFree->parent = node->parent;
|
||||
return node;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user