feat(pfa, kcp): Add kcp::NoMallocVector and realloc in PFA
This commit is contained in:
@@ -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));
|
||||
}
|
||||
}
|
||||
};
|
||||
@@ -21,7 +21,9 @@ public:
|
||||
PageFrameAllocator(LargestSection section);
|
||||
|
||||
void* Allocate();
|
||||
void* ReallocConsecutive(void* ptr, int n);
|
||||
void Free(void* ptr);
|
||||
void Free(void* ptr, int n);
|
||||
};
|
||||
|
||||
extern PageFrameAllocator* g_pfa;
|
||||
|
||||
Reference in New Issue
Block a user