feat(pfa, kcp): Add kcp::NoMallocVector and realloc in PFA

This commit is contained in:
Daniel Hammer
2025-03-12 17:18:31 +01:00
parent 53739b0059
commit bd8a1fdbca
4 changed files with 72 additions and 4 deletions
+24
View File
@@ -7,6 +7,9 @@
#include "PageFrameAllocator.hpp"
#include "HHDM.hpp"
#include <Libraries/Memory.hpp>
#include <Terminal/Terminal.hpp>
namespace Memory {
PageFrameAllocator::PageFrameAllocator(LargestSection section) {
/* we need the virtual address rather than the physical address, so we call the helper */
@@ -48,6 +51,21 @@ namespace Memory {
return nullptr;
}
void* PageFrameAllocator::ReallocConsecutive(void* ptr, int n) {
auto first = Allocate();
for (int i = 0; i < n - 1; i++) {
Allocate();
}
if (ptr != nullptr) {
memcpy(first, ptr, n);
Free(ptr);
}
return first;
}
void PageFrameAllocator::Free(void* ptr) {
auto prev_next = head.next;
head.next = (Page*)ptr;
@@ -55,4 +73,10 @@ namespace Memory {
head.next->next = prev_next;
head.next->size = 0x1000;
}
void PageFrameAllocator::Free(void* ptr, int n) {
for (int i = 0; i < n; i++) {
Free((void*)(uint64_t)ptr + (0x1000 * n));
}
}
};