fix: various kernel bug fixes

This commit is contained in:
2026-04-10 23:16:02 +02:00
parent 0433274244
commit fd7fcbbbc8
12 changed files with 282 additions and 163 deletions
+7 -2
View File
@@ -24,10 +24,15 @@ void operator delete(void* block)
void operator delete[](void* block)
{
delete block;
Memory::g_heap->Free(block);
}
void operator delete(void* block, long unsigned int)
{
Memory::g_heap->Free(block);
}
}
void operator delete[](void* block, long unsigned int)
{
Memory::g_heap->Free(block);
}
+18 -22
View File
@@ -20,21 +20,14 @@ namespace kcp
template<typename T>
class vector {
protected:
T* array;
std::size_t sz;
std::size_t capacity;
T* array = nullptr;
std::size_t sz = 0;
std::size_t capacity = 0;
public:
vector()
{
sz = 0;
array = nullptr;
}
vector() = default;
vector(std::initializer_list<T> initList) {
sz = 0;
array = nullptr;
for (auto itr = initList.begin(); itr != initList.end(); itr++) {
T item = *itr;
push_back(item);
@@ -43,15 +36,12 @@ namespace kcp
T& operator[](std::size_t position)
{
if (position > (capacity - 1)) {
kerr << "Vector out of bounds caught!" << Kt::newline;
return at(0);
}
else
{
return array[position];
if (position >= sz || array == nullptr) {
Panic("Vector out of bounds caught!", nullptr);
__builtin_unreachable();
}
return array[position];
}
T& at(std::int64_t position) {
@@ -62,8 +52,14 @@ namespace kcp
size_t _sz = sz;
if (capacity < sz + 1) {
array = (T *)Memory::g_heap->Realloc(array, sizeof(T) * (sz + 1));
capacity++;
size_t newCapacity = (capacity == 0) ? 4 : (capacity * 2);
T* newArray = (T*)Memory::g_heap->Realloc(array, sizeof(T) * newCapacity);
if (newArray == nullptr) {
Panic("Vector allocation failed!", nullptr);
__builtin_unreachable();
}
array = newArray;
capacity = newCapacity;
}
array[sz++] = value;
@@ -81,4 +77,4 @@ namespace kcp
}
};
};
};